bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#44294: No widen by xref-find-definitions


From: Juri Linkov
Subject: bug#44294: No widen by xref-find-definitions
Date: Thu, 29 Oct 2020 23:18:16 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

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:

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 via email to

[Prev in Thread] Current Thread [Next in Thread]