[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: point-at-final-line

From: John Mastro
Subject: Re: point-at-final-line
Date: Fri, 26 Jan 2018 17:52:43 -0800

Ben Bacarisse <address@hidden> wrote:
> Emanuel Berg <address@hidden> writes:
> > Did anyone do
> >
> > (defun point-at-final-line ()
> >   (let ((line (line-number-at-pos)))
> >     (save-excursion
> >       (forward-line 1)
> >       (= line (line-number-at-pos)) )))
> >
> > ?
> Maybe something like
>   (= (line-number-at-pos) (line-number-at-pos (point-max)))
> though the details depend on how you interpret the final line.

This should do it too, without needing line-number-at-pos:

(defun point-at-final-line ()
    (= (forward-line 1) 1)))

Since forward-line returns "the count of lines left to move".

The end-of-line call is because of this bit, from the docstring:

    Exception: With positive N, a non-empty line at the end of the
    buffer, or of its accessible portion, counts as one line
    successfully moved (for the return value). This means that the
    function will move point to the end of such a line and will count it
    as a line moved across, even though there is no next line to go to
    its beginning.

It seems ambiguous to me whether (based on that description) moving to
the end of the line should get us the result we're looking for, but it
seems to in practice. You could use (or (eobp) (= (forward-line 1) 1))
to be safe.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]