From 97a45a3fc4765b3b36d8df3df2c5d43505cbece9 Mon Sep 17 00:00:00 2001 From: Stefan Kangas 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