Skip to main content

31.3 Functions that Create Markers

When you create a new marker, you can make it point nowhere, or point to the present position of point, or to the beginning or end of the accessible portion of the buffer, or to the same place as another given marker.

The next four functions all return markers with insertion type nil. See Marker Insertion Types.

function make-marker​

This function returns a newly created marker that does not point anywhere.

(make-marker)
β‡’ #<marker in no buffer>

function point-marker​

This function returns a new marker that points to the present position of point in the current buffer. See Point. For an example, see copy-marker, below.

function point-min-marker​

This function returns a new marker that points to the beginning of the accessible portion of the buffer. This will be the beginning of the buffer unless narrowing is in effect. See Narrowing.

function point-max-marker​

This function returns a new marker that points to the end of the accessible portion of the buffer. This will be the end of the buffer unless narrowing is in effect. See Narrowing.

Here are examples of this function and point-min-marker, shown in a buffer containing a version of the source file for the text of this chapter.

(point-min-marker)
β‡’ #<marker at 1 in markers.texi>
(point-max-marker)
β‡’ #<marker at 24080 in markers.texi>
(narrow-to-region 100 200)
β‡’ nil
(point-min-marker)
β‡’ #<marker at 100 in markers.texi>
(point-max-marker)
β‡’ #<marker at 200 in markers.texi>

function copy-marker \&optional marker-or-integer insertion-type​

If passed a marker as its argument, copy-marker returns a new marker that points to the same place and the same buffer as does marker-or-integer. If passed an integer as its argument, copy-marker returns a new marker that points to position marker-or-integer in the current buffer.

The new marker’s insertion type is specified by the argument insertion-type. See Marker Insertion Types.

(copy-marker 0)
β‡’ #<marker at 1 in markers.texi>
(copy-marker 90000)
β‡’ #<marker at 24080 in markers.texi>

An error is signaled if marker is neither a marker nor an integer.

Two distinct markers are considered equal (even though not eq) to each other if they have the same position and buffer, or if they both point nowhere.

(setq p (point-marker))
β‡’ #<marker at 2139 in markers.texi>
(setq q (copy-marker p))
β‡’ #<marker at 2139 in markers.texi>
(eq p q)
β‡’ nil
(equal p q)
β‡’ t