all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: dmoncayo@gmail.com, 9917@debbugs.gnu.org,
	monnier@iro.umontreal.ca, 5042@debbugs.gnu.org
Subject: bug#5042: bug#9917: 24.0.90; Make `goto-line' consistent with the line number from the minibuffer
Date: Tue, 22 Sep 2020 21:08:10 +0300	[thread overview]
Message-ID: <871ritbs6t.fsf@mail.linkov.net> (raw)
In-Reply-To: <878sd1j2rv.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 22 Sep 2020 16:37:40 +0200")

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

>>> So a new command and keystroke seems warranted.  How about...
>>> `M-g M-v'?   (The mnemonic is "goto visual line".)
>>
>>   C-x n g         go to narrowed line
>
> Perhaps both?  The keystroke makes sense in both contexts -- as a
> variation on `M-g M-g', and in the group of narrowing keystroke.

Yep, having both is a win-win situation.

Here is the patch that:

1. leaves the existing 'goto-line' completely backward-compatible
   (actually a small difference is that in a narrowed buffer it displays
    now the prompt "Goto absolute line:" instead of just "Goto line:")
2. adds two optional args RELATIVE and WIDEN to 'goto-line';
3. adds two new commands 'goto-line-absolute' and 'goto-line-relative':
3.1. 'goto-line-absolute' widens the buffer and doesn't narrow it back;
3.2. 'goto-line-relative' is bound in Info mode to `M-g M-g'.

If this is ok, then 'goto-line-relative' could be bound to
`M-g M-v' and `C-x n g'.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: goto-line-relative.patch --]
[-- Type: text/x-diff, Size: 5295 bytes --]

diff --git a/lisp/info.el b/lisp/info.el
index e4f75b481f..20633fd059 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -4053,6 +4053,7 @@ Info-mode-map
     (define-key map "^" 'Info-up)
     (define-key map "," 'Info-index-next)
     (define-key map "\177" 'Info-scroll-down)
+    (define-key map [remap goto-line] 'goto-line-relative)
     (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
     (define-key map [follow-link] 'mouse-face)
     (define-key map [XF86Back] 'Info-history-back)
diff --git a/lisp/simple.el b/lisp/simple.el
index 050c81a410..724d2d96aa 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1231,7 +1231,38 @@ goto-line-history
   "History of values entered with `goto-line'.")
 (make-variable-buffer-local 'goto-line-history)
 
-(defun goto-line (line &optional buffer)
+(defun goto-line-read-args (&optional relative)
+  "Read arguments for `goto-line' related commands."
+  (if (and current-prefix-arg (not (consp current-prefix-arg)))
+      (list (prefix-numeric-value current-prefix-arg))
+    ;; Look for a default, a number in the buffer at point.
+    (let* ((default
+	     (save-excursion
+	       (skip-chars-backward "0-9")
+	       (if (looking-at "[0-9]")
+		   (string-to-number
+		    (buffer-substring-no-properties
+		     (point)
+		     (progn (skip-chars-forward "0-9")
+			    (point)))))))
+	   ;; Decide if we're switching buffers.
+	   (buffer
+	    (if (consp current-prefix-arg)
+		(other-buffer (current-buffer) t)))
+	   (buffer-prompt
+	    (if buffer
+		(concat " in " (buffer-name buffer))
+	      "")))
+      ;; Read the argument, offering that number (if any) as default.
+      (list (read-number (format "Goto%s line%s: "
+                                 (if (= (point-min) 1) ""
+                                   (if relative " relative" " absolute"))
+                                 buffer-prompt)
+                         (list default (line-number-at-pos))
+                         'goto-line-history)
+	    buffer))))
+
+(defun goto-line (line &optional buffer relative widen)
   "Go to LINE, counting from line 1 at beginning of buffer.
 If called interactively, a numeric prefix argument specifies
 LINE; without a numeric prefix argument, read LINE from the
@@ -1241,6 +1272,12 @@ goto-line
 move to line LINE there.  If called interactively with \\[universal-argument]
 as argument, BUFFER is the most recently selected other buffer.
 
+If optional argument RELATIVE is non-nil, counting is relative
+from the beginning of the narrowed buffer.
+
+If optional argument WIDEN is non-nil, cancel narrowing
+and leave all lines accessible.
+
 Prior to moving point, this function sets the mark (without
 activating it), unless Transient Mark mode is enabled and the
 mark is already active.
@@ -1252,32 +1289,7 @@ goto-line
 If at all possible, an even better solution is to use char counts
 rather than line counts."
   (declare (interactive-only forward-line))
-  (interactive
-   (if (and current-prefix-arg (not (consp current-prefix-arg)))
-       (list (prefix-numeric-value current-prefix-arg))
-     ;; Look for a default, a number in the buffer at point.
-     (let* ((default
-	      (save-excursion
-		(skip-chars-backward "0-9")
-		(if (looking-at "[0-9]")
-		    (string-to-number
-		     (buffer-substring-no-properties
-		      (point)
-		      (progn (skip-chars-forward "0-9")
-			     (point)))))))
-	    ;; Decide if we're switching buffers.
-	    (buffer
-	     (if (consp current-prefix-arg)
-		 (other-buffer (current-buffer) t)))
-	    (buffer-prompt
-	     (if buffer
-		 (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))))
+  (interactive (goto-line-read-args))
   ;; Switch to the desired buffer, one way or another.
   (if buffer
       (let ((window (get-buffer-window buffer)))
@@ -1286,12 +1298,28 @@ goto-line
   ;; Leave mark at previous position
   (or (region-active-p) (push-mark))
   ;; Move to the specified line number in that buffer.
-  (save-restriction
-    (widen)
-    (goto-char (point-min))
-    (if (eq selective-display t)
-	(re-search-forward "[\n\C-m]" nil 'end (1- line))
-      (forward-line (1- line)))))
+  (if (and (not relative) (not widen))
+      ;; Useless case because it just moves point to the edge of visible portion.
+      (save-restriction
+        (widen)
+        (goto-char (point-min))
+        (if (eq selective-display t)
+	    (re-search-forward "[\n\C-m]" nil 'end (1- line))
+          (forward-line (1- line))))
+    (progn
+      (unless relative (widen))
+      (goto-char (point-min))
+      (if (eq selective-display t)
+	  (re-search-forward "[\n\C-m]" nil 'end (1- line))
+        (forward-line (1- line))))))
+
+(defun goto-line-absolute (line &optional buffer)
+  (interactive (goto-line-read-args))
+  (goto-line line buffer nil t))
+
+(defun goto-line-relative (line &optional buffer)
+  (interactive (goto-line-read-args t))
+  (goto-line line buffer t t))
 
 (defun count-words-region (start end &optional arg)
   "Count the number of words in the region.

  reply	other threads:[~2020-09-22 18:08 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-31 14:31 bug#9917: 24.0.90; Make `goto-line' consistent with the line number from the minibuffer Dani Moncayo
2011-11-01  9:35 ` Juri Linkov
2011-11-01 17:56   ` Stefan Monnier
2011-11-01 22:35     ` Juri Linkov
2011-11-01 23:22       ` Drew Adams
2011-11-02  9:48         ` Juri Linkov
2011-11-02 12:59           ` Drew Adams
2011-11-02  9:46     ` Juri Linkov
2020-09-19 17:42 ` bug#5042: " Lars Ingebrigtsen
2020-09-19 18:01   ` Stefan Monnier
2020-09-19 19:27     ` bug#9917: bug#5042: " Drew Adams
2020-09-19 19:56       ` Eli Zaretskii
2020-09-19 18:33   ` Eli Zaretskii
2020-09-20  9:28     ` Lars Ingebrigtsen
2020-09-21 19:03       ` Juri Linkov
2020-09-22 14:37         ` Lars Ingebrigtsen
2020-09-22 18:08           ` Juri Linkov [this message]
2020-09-22 20:10             ` Drew Adams
2020-09-23 14:14               ` bug#5042: bug#9917: " Eli Zaretskii
2020-09-23 13:18             ` Lars Ingebrigtsen
2020-09-23 17:58               ` Drew Adams
2020-09-24  7:39                 ` Robert Pluim
2020-09-24 17:31                   ` bug#9917: " Drew Adams
2020-10-29  9:19           ` Juri Linkov
2020-10-29 14:31             ` Eli Zaretskii
2020-10-30  7:27               ` Juri Linkov
2020-10-30  8:19                 ` Eli Zaretskii
2020-10-29 16:44             ` bug#5042: " Drew Adams
2020-10-30  9:49             ` Lars Ingebrigtsen
2020-10-31 19:28               ` Juri Linkov
2020-10-31 20:00                 ` bug#5042: " Eli Zaretskii
2020-10-27 20:52         ` Juri Linkov
2020-10-28  9:48           ` bug#5042: " Lars Ingebrigtsen
2020-10-28 11:58             ` Dmitry Gutov
2020-10-30  9:44               ` Lars Ingebrigtsen
     [not found] <<CAH8Pv0jBbJoyJfW+Xh-m3kqGQnVc0eO2+kM40SJ23JOKiBrx-A@mail.gmail.com>
     [not found] ` <<877dspmzo3.fsf@gnus.org>
     [not found]   ` <<jwv4kntbqep.fsf-monnier+emacs@gnu.org>
     [not found]     ` <<28534d1c-6652-4cfe-acb4-f0a30624f878@default>
     [not found]       ` <<83tuvt1qwq.fsf@gnu.org>
2020-09-19 20:22         ` Drew Adams
2020-09-19 20:27           ` bug#9917: " Eli Zaretskii
     [not found]   ` <<83zh5l1uqw.fsf@gnu.org>
     [not found]     ` <<87wo0osspd.fsf@gnus.org>
     [not found]       ` <<87lfh3dtoj.fsf@mail.linkov.net>
     [not found]         ` <<878sd1j2rv.fsf@gnus.org>
     [not found]           ` <<871ritbs6t.fsf@mail.linkov.net>
     [not found]             ` <<cd8f2969-6705-46c8-b090-03e284b0ba0c@default>
     [not found]               ` <<83zh5gvauy.fsf@gnu.org>
2020-09-23 18:09                 ` bug#5042: " Drew Adams
2020-09-23 19:40                   ` Juri Linkov
     [not found] <<<CAH8Pv0jBbJoyJfW+Xh-m3kqGQnVc0eO2+kM40SJ23JOKiBrx-A@mail.gmail.com>
     [not found] ` <<<877dspmzo3.fsf@gnus.org>
     [not found]   ` <<<jwv4kntbqep.fsf-monnier+emacs@gnu.org>
     [not found]     ` <<<28534d1c-6652-4cfe-acb4-f0a30624f878@default>
     [not found]       ` <<<83tuvt1qwq.fsf@gnu.org>
     [not found]         ` <<1cfba469-3adf-4287-a1fa-647e4e5e83e2@default>
     [not found]           ` <<83pn6h1pie.fsf@gnu.org>
2020-09-19 21:10             ` Drew Adams

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871ritbs6t.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=5042@debbugs.gnu.org \
    --cc=9917@debbugs.gnu.org \
    --cc=dmoncayo@gmail.com \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.