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#44294: No widen by xref-find-definitions Date: Thu, 29 Oct 2020 23:18:16 +0200 Organization: LINKOV.NET Message-ID: <87r1pgivdz.fsf@mail.linkov.net> References: <87mu06p1aw.fsf_-_@mail.linkov.net> <5cfcbbf0-beef-3c0a-9641-a010925dbda4@yandex.ru> 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="31767"; 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: 44294@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 29 22:26:19 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 1kYFR4-0008CG-T2 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Oct 2020 22:26:18 +0100 Original-Received: from localhost ([::1]:58376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYFR3-0000E8-Vf for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Oct 2020 17:26:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYFPx-00086a-7c for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2020 17:25:09 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYFPq-0001hl-Gk for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2020 17:25:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kYFPq-0001ri-DQ for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2020 17:25: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: Thu, 29 Oct 2020 21:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44294 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed patch Original-Received: via spool by 44294-submit@debbugs.gnu.org id=B44294.16040066617093 (code B ref 44294); Thu, 29 Oct 2020 21:25:02 +0000 Original-Received: (at 44294) by debbugs.gnu.org; 29 Oct 2020 21:24:21 +0000 Original-Received: from localhost ([127.0.0.1]:55115 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kYFPB-0001qK-67 for submit@debbugs.gnu.org; Thu, 29 Oct 2020 17:24:21 -0400 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:56131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kYFOw-0001p7-3c; Thu, 29 Oct 2020 17:24:19 -0400 X-Originating-IP: 91.129.102.160 Original-Received: from mail.gandi.net (m91-129-102-160.cust.tele2.ee [91.129.102.160]) (Authenticated sender: juri@linkov.net) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 8A0A220005; Thu, 29 Oct 2020 21:23:57 +0000 (UTC) In-Reply-To: <5cfcbbf0-beef-3c0a-9641-a010925dbda4@yandex.ru> (Dmitry Gutov's message of "Thu, 29 Oct 2020 13:31:28 +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:192003 Archived-At: --=-=-= Content-Type: text/plain reopen 44294 stop >> - (user-error "Rerun etags: `%s' not found in %s" >> - pat buffer-file-name))) >> + (if (or (= (point-min) 1) (not widen-automatically)) >> + (user-error "Rerun etags: `%s' not found in %s" >> + pat buffer-file-name) >> + ;; Rerun after removing narrowing >> + (widen) >> + (etags-goto-tag-location tag-info)))) > > By the way... have you tried to use the same method here as in elisp-mode? > Meaning, widen unconditionally inside 'save-restriction'. > > There should be no reason for backends to do it differently. And this way, > you don't have to always search twice for a missing tag when inside > a narrowing. It should not widen unnecessarily when the found position is within the narrowed region. In this regard, xref--goto-char does the right thing: (defun xref--goto-char (pos) (cond ((and (<= (point-min) pos) (<= pos (point-max)))) (widen-automatically (widen)) (t (user-error "Position is outside accessible part of buffer"))) (goto-char pos)) It widens only when position is outside accessible part of buffer (and widen-automatically is non-nil). Now I fixed goto-line to use the same condition as in xref--goto-char (and (<= (point-min) p) (<= p (point-max))) to widen only when the found position is outside accessible part of buffer: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=goto-line-widen-only-accessible.patch diff --git a/lisp/simple.el b/lisp/simple.el index 2e40e3261c..0cd1739c4d 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1340,18 +1340,19 @@ goto-line ;; Leave mark at previous position (or (region-active-p) (push-mark)) ;; Move to the specified line number in that buffer. - (if (and (not relative) (not widen-automatically)) - (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)))) - (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))))) + (let ((p (save-restriction + (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))) + (point)))) + (when (and (not relative) + (buffer-narrowed-p) + widen-automatically + (not (and (<= (point-min) p) (<= p (point-max))))) + (widen)) + (goto-char p))) (defun goto-line-relative (line &optional buffer) "Go to LINE, counting from line at (point-min). --=-=-=--