unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: line-number-mode at EOB (was: Native display of line numbers, improved)
Date: Tue, 18 Jul 2017 00:20:10 +0200	[thread overview]
Message-ID: <87k236vh7p.fsf_-_@rosalinde> (raw)
In-Reply-To: <87k240xhk6.fsf@rosalinde> (Stephen Berman's message of "Sun, 25 Jun 2017 16:34:01 +0200")

[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]

On Sun, 25 Jun 2017 16:34:01 +0200 Stephen Berman <stephen.berman@gmx.net> wrote:

> On Sun, 25 Jun 2017 17:03:30 +0300 Eli Zaretskii <eliz@gnu.org> wrote:
>
>>> From: Stephen Berman <stephen.berman@gmx.net>
>>> Cc: emacs-devel@gnu.org
>>> Date: Sat, 24 Jun 2017 23:23:15 +0200
>>> 
>>> When the buffer ends with a newline and point is on it, no line number
>>> is displayed on the left, though with line-number-mode enabled the mode
>>> line does display the line number.
>>
>> By "point is on it", I guess you mean point is at EOB, i.e. beyond the
>> last character position?  Because otherwise, I don't think I see what
>> you describe.
>
> Yes, I meant at EOB.
>
>> If this is about point at EOB, then this is the intended behavior: the
>> "line" where we position cursor in that case doesn't exist, so it
>> would be IMO incorrect to count it.  
>
> By that reasoning, line-number-mode (the %l construct) should be changed
> so as not to display a number when point is at EOB.  Perhaps it should
> display "EOB" or "END" instead.

I attempted to implement this change in the mode line display (see
attached patch) and the result, while admittedly only "minor aesthetic
sugar", seems to me not too bad: it makes line-number-mode consistent
not only with vertically displayed line numbers but also with
`count-words-region' (and hence with `count-lines').  What do others
think?

If this change is accepted, then the command `what-line' should probably
also be changed to return "EOB" at EOB.  (Such a change makes sense even
if line-number-mode is not changed, since it seems odd that e.g. in the
standard *scratch* buffer `C-x h M-=' reports "Region has 3 lines..."
while calling `what-line' at EOB reports "Line 4".)

Steve Berman



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: line-number-mode at EOB patch --]
[-- Type: text/x-patch, Size: 2106 bytes --]

diff --git a/lisp/bindings.el b/lisp/bindings.el
index be44b45136..4d4411e55d 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -415,8 +415,8 @@ mode-line-position
               'mouse-face 'mode-line-highlight
               'help-echo "Line number and Column number\n\
 mouse-1: Display Line and Column Mode Menu")))
-       (6 ,(propertize
-	    " L%l"
+       (6 (:propertize
+	    (:eval (if (eobp) " %l" " L%l"))
 	    'local-map mode-line-column-line-number-mode-map
 	    'mouse-face 'mode-line-highlight
 	    'help-echo "Line Number\n\
diff --git a/src/xdisp.c b/src/xdisp.c
index 2aceb89c00..600fad0100 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -11579,14 +11579,19 @@ window_buffer_changed (struct window *w)
   return (BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) != w->last_had_star;
 }
 
-/* True if W has %c or %C in its mode line and mode line should be updated.  */
+/* True if W has %c or %C in its mode line and mode line should be
+   updated. or if W has %l in its mode line and point has moved either
+   to or away from EOB.  */
 
 static bool
 mode_line_update_needed (struct window *w)
 {
-  return (w->column_number_displayed != -1
-	  && !(PT == w->last_point && !window_outdated (w))
-	  && (w->column_number_displayed != current_column ()));
+  return ((w->column_number_displayed != -1
+	   && !(PT == w->last_point && !window_outdated (w))
+	   && (w->column_number_displayed != current_column ()))
+	  || (line_number_displayed
+	      && ((ZV == w->last_point && PT != ZV)
+		  || (ZV != w->last_point && PT == ZV))));
 }
 
 /* True if window start of W is frozen and may not be changed during
@@ -24395,8 +24400,13 @@ decode_mode_spec (struct window *w, register int c, int field_width,
 	line_number_displayed = true;
 
 	/* Make the string to show.  */
-	pint2str (decode_mode_spec_buf, width, topline + nlines);
-	return decode_mode_spec_buf;
+	if (PT == BUF_ZV (b))
+	  return "EOB";
+	else
+	  {
+	    pint2str (decode_mode_spec_buf, width, topline + nlines);
+	    return decode_mode_spec_buf;
+	  }
     no_value:
         {
 	  char *p = decode_mode_spec_buf;

  parent reply	other threads:[~2017-07-17 22:20 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-24 17:27 Native display of line numbers, improved Eli Zaretskii
2017-06-24 18:40 ` Clément Pit-Claudel
2017-06-24 18:51   ` Eli Zaretskii
2017-06-24 20:53 ` Stephen Berman
2017-06-25 14:07   ` Eli Zaretskii
2017-06-25 14:34     ` Stephen Berman
2017-06-25 15:10       ` Eli Zaretskii
2017-06-25 15:41         ` Stephen Berman
2017-06-25 16:02           ` Eli Zaretskii
2017-06-25 19:00             ` Stephen Berman
2017-06-24 21:23 ` Stephen Berman
2017-06-25 14:03   ` Eli Zaretskii
2017-06-25 14:34     ` Stephen Berman
2017-06-25 14:57       ` Eli Zaretskii
2017-07-17 22:20       ` Stephen Berman [this message]
2017-07-18  4:16         ` line-number-mode at EOB Stefan Monnier
2017-07-18 14:04           ` Stephen Berman
2017-07-18 14:30             ` Stefan Monnier
2017-07-18 14:51               ` Eli Zaretskii
2017-07-18 15:04                 ` Stefan Monnier
2017-07-20 20:25                   ` Paul Eggert
2017-07-20 20:43                     ` Stephen Berman
2017-07-20 21:19                       ` Paul Eggert
2017-07-20 21:35                         ` Stephen Berman
2017-07-18 14:55         ` line-number-mode at EOB (was: Native display of line numbers, improved) Eli Zaretskii
2017-07-18 16:33           ` line-number-mode at EOB Stephen Berman
2017-07-18 19:03             ` Eli Zaretskii
2017-07-18 20:38               ` Stephen Berman
2017-06-25  9:59 ` Native display of line numbers, improved martin rudalics
2017-06-25 13:54   ` Eli Zaretskii
2017-06-25 15:58     ` martin rudalics
2017-06-25 20:30 ` Alex
2017-06-26  2:39   ` Eli Zaretskii
2017-06-26  3:43     ` Alex
2017-06-26  3:50       ` Alex
2017-06-26 14:58         ` Eli Zaretskii
2017-06-26 19:41           ` Alex
2017-06-27 14:25             ` Eli Zaretskii
2017-06-29 20:25               ` Native line numbers column disappears at times Kaushal Modi
2017-06-30  6:00                 ` Eli Zaretskii
2017-07-10 18:53                   ` Kaushal Modi
2017-07-10 19:31                     ` Eli Zaretskii
2017-07-10 20:56                       ` Kaushal Modi
2017-06-26 14:54       ` Native display of line numbers, improved Eli Zaretskii
2017-06-26 15:28         ` Stefan Monnier
2017-06-26 15:56           ` Eli Zaretskii
2017-06-26 16:12             ` Stefan Monnier
2017-06-26 16:26               ` Eli Zaretskii
2017-06-26 19:36             ` Alex

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87k236vh7p.fsf_-_@rosalinde \
    --to=stephen.berman@gmx.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).