From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs 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 Organization: LINKOV.NET Message-ID: <871ritbs6t.fsf@mail.linkov.net> References: <877dspmzo3.fsf@gnus.org> <83zh5l1uqw.fsf@gnu.org> <87wo0osspd.fsf@gnus.org> <87lfh3dtoj.fsf@mail.linkov.net> <878sd1j2rv.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19006"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: dmoncayo@gmail.com, 9917@debbugs.gnu.org, monnier@iro.umontreal.ca, 5042@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 22 20:20:18 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kKmtm-0004qd-BH for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Sep 2020 20:20:18 +0200 Original-Received: from localhost ([::1]:41650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKmtl-0005ks-BF for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Sep 2020 14:20:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKmtX-0005bp-4c for bug-gnu-emacs@gnu.org; Tue, 22 Sep 2020 14:20:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kKmtW-0008W6-Qw for bug-gnu-emacs@gnu.org; Tue, 22 Sep 2020 14:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kKmtW-0001oi-MR for bug-gnu-emacs@gnu.org; Tue, 22 Sep 2020 14:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Sep 2020 18:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5042 X-GNU-PR-Package: emacs Original-Received: via spool by 5042-submit@debbugs.gnu.org id=B5042.16007987686921 (code B ref 5042); Tue, 22 Sep 2020 18:20:02 +0000 Original-Received: (at 5042) by debbugs.gnu.org; 22 Sep 2020 18:19:28 +0000 Original-Received: from localhost ([127.0.0.1]:33318 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kKmsx-0001nY-Pa for submit@debbugs.gnu.org; Tue, 22 Sep 2020 14:19:28 -0400 Original-Received: from relay10.mail.gandi.net ([217.70.178.230]:43177) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kKmsr-0001mu-5I; Tue, 22 Sep 2020 14:19:22 -0400 Original-Received: from mail.gandi.net (m91-129-108-13.cust.tele2.ee [91.129.108.13]) (Authenticated sender: juri@linkov.net) by relay10.mail.gandi.net (Postfix) with ESMTPSA id B5936240007; Tue, 22 Sep 2020 18:19:12 +0000 (UTC) In-Reply-To: <878sd1j2rv.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 22 Sep 2020 16:37:40 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:188735 Archived-At: --=-=-= Content-Type: text/plain >>> 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'. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=goto-line-relative.patch 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. --=-=-=--