all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: point-at-final-line
Date: Fri, 26 Jan 2018 17:52:43 -0800	[thread overview]
Message-ID: <CAOj2CQQaE+=RfybwbbLU8otvpXg0PdfcYZUR+thVm+==07B15A@mail.gmail.com> (raw)
In-Reply-To: <87vafom6af.fsf@bsb.me.uk>

Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Emanuel Berg <moasen@zoho.com> 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 ()
  (save-excursion
    (end-of-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.

        John



  reply	other threads:[~2018-01-27  1:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-27  1:14 point-at-final-line Emanuel Berg
2018-01-27  1:36 ` point-at-final-line Ben Bacarisse
2018-01-27  1:52   ` John Mastro [this message]
2018-01-27  2:50   ` point-at-final-line Emanuel Berg
     [not found]   ` <mailman.8058.1517017989.27995.help-gnu-emacs@gnu.org>
2018-01-27  2:56     ` point-at-final-line Emanuel Berg
2018-01-27  3:02     ` point-at-final-line Emanuel Berg
2018-01-27  6:11       ` point-at-final-line Marcin Borkowski
     [not found]       ` <mailman.8063.1517033499.27995.help-gnu-emacs@gnu.org>
2018-01-27  7:05         ` point-at-final-line Emanuel Berg
2018-01-28 16:06       ` point-at-final-line Stefan Monnier
     [not found]       ` <mailman.8116.1517155644.27995.help-gnu-emacs@gnu.org>
2018-01-28 18:59         ` point-at-final-line Emanuel Berg
2018-01-28 20:36           ` point-at-final-line Eli Zaretskii
     [not found]           ` <mailman.8132.1517171769.27995.help-gnu-emacs@gnu.org>
2018-01-29 15:03             ` point-at-final-line Emanuel Berg
2018-01-29 16:04               ` point-at-final-line Eli Zaretskii
     [not found]               ` <mailman.8177.1517241890.27995.help-gnu-emacs@gnu.org>
2018-01-29 16:40                 ` point-at-final-line Emanuel Berg
2018-01-29 17:51                   ` point-at-final-line Eli Zaretskii
     [not found]                   ` <mailman.8185.1517248285.27995.help-gnu-emacs@gnu.org>
2018-01-30  2:18                     ` point-at-final-line Emanuel Berg
2018-01-30  3:32                       ` point-at-final-line Eli Zaretskii
2018-01-30  3:50       ` point-at-final-line Stefan Monnier
     [not found]       ` <mailman.8212.1517284260.27995.help-gnu-emacs@gnu.org>
2018-01-30 14:52         ` point-at-final-line Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOj2CQQaE+=RfybwbbLU8otvpXg0PdfcYZUR+thVm+==07B15A@mail.gmail.com' \
    --to=john.b.mastro@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.