From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: point-at-final-line Date: Fri, 26 Jan 2018 17:52:43 -0800 Message-ID: References: <868tckgl1y.fsf@zoho.com> <87vafom6af.fsf@bsb.me.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1517017906 21139 195.159.176.226 (27 Jan 2018 01:51:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 27 Jan 2018 01:51:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 27 02:51:42 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efFeZ-0004oD-1T for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Jan 2018 02:51:35 +0100 Original-Received: from localhost ([::1]:42903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFgZ-0002vx-OU for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Jan 2018 20:53:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1efFg2-0002vK-H4 for help-gnu-emacs@gnu.org; Fri, 26 Jan 2018 20:53:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1efFg1-0008Q4-FO for help-gnu-emacs@gnu.org; Fri, 26 Jan 2018 20:53:06 -0500 Original-Received: from mail-qt0-x229.google.com ([2607:f8b0:400d:c0d::229]:40384) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1efFg1-0008Pl-9i for help-gnu-emacs@gnu.org; Fri, 26 Jan 2018 20:53:05 -0500 Original-Received: by mail-qt0-x229.google.com with SMTP id s39so5903136qth.7 for ; Fri, 26 Jan 2018 17:53:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=+gKu0ocF/sf/RpCtK6SggPNfoyFo/lBWRxL5hv++tQc=; b=IC6pW1mk8kFXZGQmebjR3ER5jdJC//WsaQxoaSQOwia/KQIZ0OhPmZvhTah2OtuKCe mPs5Z2/8zydoZLZ48oT+lqi1swMbx5kG5FWPXiyQqD4YniYE1vlktXVbTB+++vHkNIdN E+CfGxx0tYVPFuCl4ZQDi7PjMvihiCmro74AqZMT9rklC5iLJ1PTae7H2vwZVDoAAtoV VRxr8DVlzVBzwsREoJilLsuWZ5KetHHAYA47V1Fyoqdzi4AlTu/MbU+JgGF2z7hyGd4B MwcOMri7gphjn3MG1sEBlVe4eCjX4wm9R6HfU/mKKf7l/X8nboRc6N8H685xVyIom3z5 tV4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=+gKu0ocF/sf/RpCtK6SggPNfoyFo/lBWRxL5hv++tQc=; b=Tvi8t7CYIv701q2Ea2scHz6rocwD1L1ZcqfV9v4vbZpCj/pNGFFtozQJoS5JoRWU8J 3L7m57V0UxEQtLJev9SF+BZP3AYwrOanlKzkC9gY7nUkaIbUq7n0QyVSrgez5Qq5rJxH Z7Zh6BzJhnRLip09d5PGKxMcRl/G0dTtCSmjrKVHeqKn/GaCtd1EF5/PbM4M0nv26dM+ u00c8E3TCzF6Bk/DhX8xP8Ep8gmjKXb5No5dcvPU7iZK912haA8xdR6sKAXvC+SsBX9u Sq5ibPi+kMelDEBOG1J3mpuIssPkVae4pglUnx1vuGU/j0l/TjV9QkPcnvN/CW/h7ZH4 HiCw== X-Gm-Message-State: AKwxytfI5Lnp82VsU0V9Vh5msq0lmKZbzHZJRLJiyBfoJdMCB9hSXBIQ CGQMR4vJJ+E8mlLn2n5R41JR7uexkG9AUweqkYlfxON7 X-Google-Smtp-Source: AH8x225+r5NWCSnY87b/RWpGUhl/157znowQbBmJ6Ty2cnYLe612fuDiXcbOEoNBNwwFQDeqGK+/e6xW3W3nuw19FrA= X-Received: by 10.200.3.41 with SMTP id q41mr26039740qtg.173.1517017984212; Fri, 26 Jan 2018 17:53:04 -0800 (PST) Original-Received: by 10.200.55.166 with HTTP; Fri, 26 Jan 2018 17:52:43 -0800 (PST) In-Reply-To: <87vafom6af.fsf@bsb.me.uk> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::229 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115859 Archived-At: Ben Bacarisse wrote: > Emanuel Berg 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