unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#42839: [PATCH] Support displaying line numbers in goto-line
@ 2020-08-13  6:30 Stefan Kangas
  2020-08-13  8:30 ` Robert Pluim
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Stefan Kangas @ 2020-08-13  6:30 UTC (permalink / raw)
  To: 42839

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

Here's an interesting idea I picked up from Reddit: make goto-line
enable display-line-numbers-mode temporarily when prompting.  Please see
the attached patch.

Comments or thoughts welcome, as always.

Best regards,
Stefan Kangas

PS. I added a new defcustom to enable this behaviour, by default set to
    nil.  But if it seems useful, it would be nifty if we could enable
    it by default.  (I have no idea if display-line-numbers-mode is
    stable enough in all scenarios, however.)

[-- Attachment #2: 0001-Support-displaying-line-numbers-in-goto-line.patch --]
[-- Type: text/x-diff, Size: 1982 bytes --]

From 97a45a3fc4765b3b36d8df3df2c5d43505cbece9 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Thu, 13 Aug 2020 08:19:42 +0200
Subject: [PATCH] Support displaying line numbers in goto-line

* lisp/simple.el (goto-line): Support temporarily enabling
display-line-numbers-mode when prompting.
(goto-line-display-line-numbers): New defcustom to enable this new
behaviour.
---
 lisp/simple.el | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 6f72c3b81b..8766a194e1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1227,6 +1227,12 @@ mark-whole-buffer
 
 ;; Counting lines, one way or another.
 
+(defcustom goto-line-display-line-numbers nil
+  "If non-nil, `goto-line' temporarily displays line numbers."
+  :type 'boolean
+  :version "28.1"
+  :group 'editing-basics)
+
 (defvar goto-line-history nil
   "History of values entered with `goto-line'.")
 (make-variable-buffer-local 'goto-line-history)
@@ -1274,10 +1280,17 @@ goto-line
 		 (concat " in " (buffer-name buffer))
 	       "")))
        ;; Read the argument, offering that number (if any) as default.
-       (list (read-number (format "Goto line%s: " buffer-prompt)
-                          (list default (line-number-at-pos))
-                          'goto-line-history)
-	     buffer))))
+       (let ((showing display-line-numbers))
+         (unwind-protect
+             (progn
+               (when (not showing)
+                 (display-line-numbers-mode 1))
+               (list (read-number (format "Goto line%s: " buffer-prompt)
+                                  (list default (line-number-at-pos))
+                                  'goto-line-history)
+	             buffer))
+           (when (not showing)
+             (display-line-numbers-mode -1)))))))
   ;; Switch to the desired buffer, one way or another.
   (if buffer
       (let ((window (get-buffer-window buffer)))
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13  6:30 bug#42839: [PATCH] Support displaying line numbers in goto-line Stefan Kangas
@ 2020-08-13  8:30 ` Robert Pluim
  2020-08-13  8:58   ` Stefan Kangas
  2020-08-13 13:17   ` Eli Zaretskii
  2020-08-13 13:10 ` Eli Zaretskii
  2020-10-09 21:22 ` Stefan Kangas
  2 siblings, 2 replies; 9+ messages in thread
From: Robert Pluim @ 2020-08-13  8:30 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 42839

>>>>> On Wed, 12 Aug 2020 23:30:42 -0700, Stefan Kangas <stefan@marxist.se> said:

    Stefan> Here's an interesting idea I picked up from Reddit: make goto-line
    Stefan> enable display-line-numbers-mode temporarily when prompting.  Please see
    Stefan> the attached patch.

    Stefan> Comments or thoughts welcome, as always.

Hmm, if the line youʼre going to is visible, why would
you need goto-line to show line numbers? For that matter, why not just
move to the line using other motion commands?

And if itʼs not visible, what does showing line numbers for the lines
that are visible get you?

You'd have to add some interactive 'scroll window to show target line'
functionality, I think.

Robert





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13  8:30 ` Robert Pluim
@ 2020-08-13  8:58   ` Stefan Kangas
  2020-08-13  9:16     ` Robert Pluim
  2020-08-13 13:17   ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Kangas @ 2020-08-13  8:58 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 42839

Robert Pluim <rpluim@gmail.com> writes:

>>>>>> On Wed, 12 Aug 2020 23:30:42 -0700, Stefan Kangas <stefan@marxist.se> said:
>
>     Stefan> Here's an interesting idea I picked up from Reddit: make goto-line
>     Stefan> enable display-line-numbers-mode temporarily when prompting.  Please see
>     Stefan> the attached patch.
>
>     Stefan> Comments or thoughts welcome, as always.
>
> Hmm, if the line youʼre going to is visible, why would
> you need goto-line to show line numbers?

Well, I don't always know the line number of every line in my window.

> For that matter, why not just move to the line using other motion
> commands?

I personally use `goto-line' only when I have a specific line number
that I want to go to.  It is true that there are other movement
commands that are often better to use.

> And if itʼs not visible, what does showing line numbers for the lines
> that are visible get you?

It serves as a reminder of where you're at before you leave.

> You'd have to add some interactive 'scroll window to show target line'
> functionality, I think.

Good idea, thanks.  Maybe I should look into that.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13  8:58   ` Stefan Kangas
@ 2020-08-13  9:16     ` Robert Pluim
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Pluim @ 2020-08-13  9:16 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 42839

>>>>> On Thu, 13 Aug 2020 01:58:41 -0700, Stefan Kangas <stefan@marxist.se> said:

    Stefan> Well, I don't always know the line number of every line in my window.

Neither do I, but if Iʼm going to a specific number that doesnʼt
matter.

    >> For that matter, why not just move to the line using other motion
    >> commands?

    Stefan> I personally use `goto-line' only when I have a specific line number
    Stefan> that I want to go to.  It is true that there are other movement
    Stefan> commands that are often better to use.

    >> And if itʼs not visible, what does showing line numbers for the lines
    >> that are visible get you?

    Stefan> It serves as a reminder of where you're at before you leave.

`goto-line' sets the mark, so thatʼs only a 'C-u C-SPC' away.

Robert





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13  6:30 bug#42839: [PATCH] Support displaying line numbers in goto-line Stefan Kangas
  2020-08-13  8:30 ` Robert Pluim
@ 2020-08-13 13:10 ` Eli Zaretskii
  2020-08-13 14:30   ` Stefan Kangas
  2020-10-09 21:22 ` Stefan Kangas
  2 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-08-13 13:10 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 42839

> From: Stefan Kangas <stefan@marxist.se>
> Date: Wed, 12 Aug 2020 23:30:42 -0700
> 
> +       (let ((showing display-line-numbers))
> +         (unwind-protect
> +             (progn
> +               (when (not showing)
> +                 (display-line-numbers-mode 1))
> +               (list (read-number (format "Goto line%s: " buffer-prompt)
> +                                  (list default (line-number-at-pos))
> +                                  'goto-line-history)
> +	             buffer))
> +           (when (not showing)
> +             (display-line-numbers-mode -1)))))))

The variable display-line-numbers is not a simple boolean, it can have
several values.  I think you intended to show absolute line numbers in
this case, so just testing whether display-line-numbers is non-nil is
not enough.  Similarly, restoring the original setting needs more than
just a call to display-line-numbers-mode.

And this needs a NEWS entry.

Other than that, if someone wants this optional feature, why not?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13  8:30 ` Robert Pluim
  2020-08-13  8:58   ` Stefan Kangas
@ 2020-08-13 13:17   ` Eli Zaretskii
  2020-08-13 13:24     ` Robert Pluim
  1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-08-13 13:17 UTC (permalink / raw)
  To: Robert Pluim; +Cc: 42839, stefan

> From: Robert Pluim <rpluim@gmail.com>
> Date: Thu, 13 Aug 2020 10:30:01 +0200
> Cc: 42839@debbugs.gnu.org
> 
> And if itʼs not visible, what does showing line numbers for the lines
> that are visible get you?

You can make it visible with the likes of "C-M-v".





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13 13:17   ` Eli Zaretskii
@ 2020-08-13 13:24     ` Robert Pluim
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Pluim @ 2020-08-13 13:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 42839, stefan

>>>>> On Thu, 13 Aug 2020 16:17:57 +0300, Eli Zaretskii <eliz@gnu.org> said:

    >> From: Robert Pluim <rpluim@gmail.com>
    >> Date: Thu, 13 Aug 2020 10:30:01 +0200
    >> Cc: 42839@debbugs.gnu.org
    >> 
    >> And if itʼs not visible, what does showing line numbers for the lines
    >> that are visible get you?

    Eli> You can make it visible with the likes of "C-M-v".

Yes, if itʼs not too far away, in which case that would be tedious
(and entering the line number as an arg to C-M-v means typing it
twice).

Robert





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13 13:10 ` Eli Zaretskii
@ 2020-08-13 14:30   ` Stefan Kangas
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Kangas @ 2020-08-13 14:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 42839

Eli Zaretskii <eliz@gnu.org> writes:

> The variable display-line-numbers is not a simple boolean, it can have
> several values.  I think you intended to show absolute line numbers in
> this case, so just testing whether display-line-numbers is non-nil is
> not enough.  Similarly, restoring the original setting needs more than
> just a call to display-line-numbers-mode.

Right, you are completely correct of course.  I suppose we would also
have to consider that the user might have nlinum, linum, and possibly
other conflicting modes activated.

I should have been more clear that this was more a proof of concept to
see if the idea would fly.

> And this needs a NEWS entry.

Yup.

> Other than that, if someone wants this optional feature, why not?

Thanks.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#42839: [PATCH] Support displaying line numbers in goto-line
  2020-08-13  6:30 bug#42839: [PATCH] Support displaying line numbers in goto-line Stefan Kangas
  2020-08-13  8:30 ` Robert Pluim
  2020-08-13 13:10 ` Eli Zaretskii
@ 2020-10-09 21:22 ` Stefan Kangas
  2 siblings, 0 replies; 9+ messages in thread
From: Stefan Kangas @ 2020-10-09 21:22 UTC (permalink / raw)
  To: 42839-done

Stefan Kangas <stefan@marxist.se> writes:

> Here's an interesting idea I picked up from Reddit: make goto-line
> enable display-line-numbers-mode temporarily when prompting.  Please see
> the attached patch.
>
> Comments or thoughts welcome, as always.

There were no massive enthusiasm for this idea, and I sort of lost
interest.  It would need some more work, and there are obviously many
other areas where time could be usefully spent.  So I'm closing this bug
for now.

Thanks to Robert and Eli who contributed their thoughts.  Hopefully we
will be able to dig up this thread if we ever return to this idea in the
future.

PS. If anyone wants to pick up the ball, they should feel free to do so.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-10-09 21:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13  6:30 bug#42839: [PATCH] Support displaying line numbers in goto-line Stefan Kangas
2020-08-13  8:30 ` Robert Pluim
2020-08-13  8:58   ` Stefan Kangas
2020-08-13  9:16     ` Robert Pluim
2020-08-13 13:17   ` Eli Zaretskii
2020-08-13 13:24     ` Robert Pluim
2020-08-13 13:10 ` Eli Zaretskii
2020-08-13 14:30   ` Stefan Kangas
2020-10-09 21:22 ` Stefan Kangas

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).