unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 44294@debbugs.gnu.org
Subject: bug#44294: No widen by xref-find-definitions
Date: Thu, 29 Oct 2020 23:18:16 +0200	[thread overview]
Message-ID: <87r1pgivdz.fsf@mail.linkov.net> (raw)
In-Reply-To: <5cfcbbf0-beef-3c0a-9641-a010925dbda4@yandex.ru> (Dmitry Gutov's message of "Thu, 29 Oct 2020 13:31:28 +0200")

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

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:


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

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).

  reply	other threads:[~2020-10-29 21:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 20:01 bug#44294: No widen by xref-find-definitions Juri Linkov
2020-10-28 21:37 ` Dmitry Gutov
2020-10-29  8:30   ` Philipp Stephani
2020-10-29  9:11     ` Juri Linkov
2020-10-29  9:09   ` Juri Linkov
2020-10-29 21:20     ` Juri Linkov
2020-10-29 11:31 ` Dmitry Gutov
2020-10-29 21:18   ` Juri Linkov [this message]
2020-10-29 21:33     ` Dmitry Gutov
2020-10-30  7:38       ` Juri Linkov
2020-10-30 16:54         ` Dmitry Gutov
2020-10-31 19:41           ` Juri Linkov
2020-10-31 23:14             ` Dmitry Gutov

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=87r1pgivdz.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=44294@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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).