LineInformation

Emacs 21.4 and XEmacs 21.4 both have point-at-bol and point-at-eol, so you can use those for line position information nowadays.

In Emacs they’re aliases for line-beginning-position and line-end-position which are documented in the EmacsLispReference. If you’re writing just for Emacs then you can use those names.

At the time of the EmacsSchism people used the following to get the end of the line position:

  (save-excursion (end-of-line) (point))

To support old emacsen you can make a helper function or alias with either this or point-at-eol or line-end-position, and ditto beginning of line.


Here’s a workaround used in ibuffer.el (see IbufferMode for more):

(if (fboundp 'line-beginning-position)
    (defalias 'ibuffer-line-beginning-position 'line-beginning-position)
  (defun ibuffer-line-beginning-position ()
    (save-excursion
      (beginning-of-line)
      (point))))

(if (fboundp 'line-end-position)
    (defalias 'ibuffer-line-end-position 'line-end-position)
  (defun ibuffer-line-end-position ()
    (save-excursion
      (end-of-line)
      (point))))

Here is some example code from sql.el for comint specific stuff:

(if (not (fboundp 'comint-line-beginning-position))
    ;; comint-line-beginning-position is defined in Emacs 21
    (defun comint-line-beginning-position ()
      "Returns the buffer position of the beginning of the line, after any prompt.
The prompt is assumed to be any text at the beginning of the line matching
the regular expression `comint-prompt-regexp', a buffer local variable."
      (save-excursion (comint-bol nil) (point))))

In matlab.el you can find some code that looks like the following which takes into account the point-at-eol/bol functions that exist in XEmacs:

 (cond ((fboundp 'point-at-bol)
        (defalias 'this-mode-point-at-bol 'point-at-bol)
        (defalias 'this-mode-point-at-eol 'point-at-eol))
      ((fboundp 'line-beginning-position)
       (defalias 'this-mode-point-at-bol 'line-beginning-position)
       (defalias 'this-mode-point-at-eol 'line-end-position))
      (t
       (defmacro this-mode-point-at-bol ()
          (save-excursion (beginning-of-line) (point)))
       (defmacro this-mode-point-at-eol ()
     (save-excursion (end-of-line) (point)))))

CategoryCode ComparativeEmacsology