unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: 42839@debbugs.gnu.org
Subject: bug#42839: [PATCH] Support displaying line numbers in goto-line
Date: Wed, 12 Aug 2020 23:30:42 -0700	[thread overview]
Message-ID: <CADwFkmkCryuZ6B0cgHEzX_V8mmad0gzBMQRR6dYU9958jVu9zg@mail.gmail.com> (raw)

[-- 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


             reply	other threads:[~2020-08-13  6:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-13  6:30 Stefan Kangas [this message]
2020-08-13  8:30 ` bug#42839: [PATCH] Support displaying line numbers in goto-line 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

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=CADwFkmkCryuZ6B0cgHEzX_V8mmad0gzBMQRR6dYU9958jVu9zg@mail.gmail.com \
    --to=stefan@marxist.se \
    --cc=42839@debbugs.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).