From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.devel Subject: line-number-mode at EOB (was: Native display of line numbers, improved) Date: Tue, 18 Jul 2017 00:20:10 +0200 Message-ID: <87k236vh7p.fsf_-_@rosalinde> References: <83tw35thxw.fsf@gnu.org> <87tw35cc70.fsf@rosalinde> <83injktb9p.fsf@gnu.org> <87k240xhk6.fsf@rosalinde> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1500330040 4213 195.159.176.226 (17 Jul 2017 22:20:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Jul 2017 22:20:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 18 00:20:31 2017 Return-path: Envelope-to: ged-emacs-devel@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 1dXENM-00005l-FF for ged-emacs-devel@m.gmane.org; Tue, 18 Jul 2017 00:20:24 +0200 Original-Received: from localhost ([::1]:52819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXENN-0002tP-El for ged-emacs-devel@m.gmane.org; Mon, 17 Jul 2017 18:20:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXENG-0002t6-CV for emacs-devel@gnu.org; Mon, 17 Jul 2017 18:20:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXENB-0006DZ-DQ for emacs-devel@gnu.org; Mon, 17 Jul 2017 18:20:18 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:59161) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dXENB-0006Bs-2M; Mon, 17 Jul 2017 18:20:13 -0400 Original-Received: from rosalinde ([83.135.12.56]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MEbYb-1dQIUM078j-00FkBt; Tue, 18 Jul 2017 00:20:11 +0200 In-Reply-To: <87k240xhk6.fsf@rosalinde> (Stephen Berman's message of "Sun, 25 Jun 2017 16:34:01 +0200") X-Provags-ID: V03:K0:QjOsKtCYYH/h1FrPFT6DjVetSHsSvKiud98g9SK7lCJI+xTS5oF tIDUY1hGZbbfEXPH7mo4Oc06B7vvPF5cGpouHBxapgOT7oKhA5JcnhugynIXVrTQ3pR8QJ2 vPfwspUgl1BZogy5Mf72dD7Rjuay0NaQ3jlpR1teljkGMydaUMaH3tdKhwFzhnyw0lbZVPl RjXPQG4VhDoIWf9ol1BAQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:nIJyMsFvBpM=:NLCcQUi01npkfxNwE02zIQ xWekN8GPWu4VbRgzs+4nYQi1iMjHL+8wwMs9AEWlEhBefiD/GJvYLU9ly//MMuKSbAgCINjHf GtB92jJayGe5zDINavOjYmr2Fr4yTUJQxbRgS9DvaTDZI3oqJcVZAbfyrqjOMJFTrCITdQn3l dljdwzKWfBgx3t5FLA+QJcQ6hQ9QmVRjKjwbLaeb13xOONlEVks3aJDgqUXnvhim94Q0YYIt2 Fww0m4A4jpkSmbFmn5QzKZW2GbeJCmkl12RqHl54NdJuCWWeALObtzvQ5EN5gPV6D0sxaOvej gH4pVuxSsPbDpPd+4MPrAGaXe3tk959hBTtipBcbhCJxDOhPAaBRb8pMUEb4YOYZVPQy/xM9I JkC8isFkwp7oQ0GxAfu4FmOnLSTwGL/8VeupJsezIzcDwlXvB2cKW8UMa75w8t0TbMAgtovTb JcwdU5VHiDFnVouJQbjylx/SX1UQN0ejiFZJKrozI8aYzwinW++ek3c7K2SPv7HVA7sICj1/2 CcBxRJwzm9yZpzWP9PrzgLNrNBnV40nAkVQOzf4mSxwTYrhZoyYDDwzWomreWDyP+GXpT8EYl JElCiNWXPb7uTOIiNkz0Za9MZzD7Z2KGWcLH8yHsTpbk+91UwJM02IG+1clt1UVyOar41ZvRm sgfvRULuUoFT3rL8xRGQ6hYVvCWmI3lmxuGpLptLqdlfniJpo2/1DmTZgUQhqTmWuxcVshcLl rvT6Kc33PIQ/epPo649e7hztG2Wt4b/hbRNiGu2xOGf4ptuMELsKQorQERfJ7icTq4nyOnkY X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.20 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216808 Archived-At: --=-=-= Content-Type: text/plain On Sun, 25 Jun 2017 16:34:01 +0200 Stephen Berman wrote: > On Sun, 25 Jun 2017 17:03:30 +0300 Eli Zaretskii wrote: > >>> From: Stephen Berman >>> 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Description: line-number-mode at EOB patch 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; --=-=-=--