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

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