]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix finding anchor references after 'Info-on-current-buffer'
authorEli Zaretskii <eliz@gnu.org>
Fri, 2 Aug 2024 06:24:55 +0000 (09:24 +0300)
committerEshel Yaron <me@eshelyaron.com>
Fri, 2 Aug 2024 10:08:01 +0000 (12:08 +0200)
* lisp/info.el (Info--record-tag-table): New function, extracted
from 'Info-find-node-2'.
(Info-find-node-2, Info-on-current-buffer): Use
'Info--record-tag-table'.  (Bug#72391)

(cherry picked from commit 4fa540f86587d4458cf33da352176f57e20723d4)

lisp/info.el

index cd70f4bfbb0eb5974e4ad9bd8c0f040762c64e92..4b02c9db263037a67b3227206627a34d679f69c3 100644 (file)
@@ -1037,6 +1037,67 @@ If NOERROR, inhibit error messages when we can't find the node."
              Info-history))
   (Info-find-node-2 filename nodename no-going-back strict-case))
 
+(defun Info--record-tag-table (nodename)
+  "If the current Info file has a tag table, record its location for NODENAME.
+
+This creates a tag-table buffer, sets `Info-tag-table-buffer' to
+name that buffer, and records the buffer and the tag table in
+the marker `Info-tag-table-buffer'.  If the Info file has no
+tag table, or if NODENAME is \"*\", the function sets the marker
+to nil to indicate the tag table is not available/relevant.
+
+The function assumes that the Info buffer is widened, and does
+not preserve point."
+  (goto-char (point-max))
+  (forward-line -8)
+  ;; Use string-equal, not equal, to ignore text props.
+  (if (not (or (string-equal nodename "*")
+              (not
+               (search-forward "\^_\nEnd tag table\n" nil t))))
+      (let (pos)
+       ;; We have a tag table.  Find its beginning.
+       ;; Is this an indirect file?
+       (search-backward "\nTag table:\n")
+       (setq pos (point))
+       (if (save-excursion
+             (forward-line 2)
+             (looking-at "(Indirect)\n"))
+           ;; It is indirect.  Copy it to another buffer
+           ;; and record that the tag table is in that buffer.
+           (let ((buf (current-buffer))
+                 (tagbuf
+                  (or Info-tag-table-buffer
+                      (generate-new-buffer " *info tag table*"))))
+             (setq Info-tag-table-buffer tagbuf)
+             (with-current-buffer tagbuf
+               (buffer-disable-undo (current-buffer))
+               (setq case-fold-search t)
+               (erase-buffer)
+               (insert-buffer-substring buf))
+             (set-marker Info-tag-table-marker
+                         (match-end 0) tagbuf))
+         (set-marker Info-tag-table-marker pos)))
+    (set-marker Info-tag-table-marker nil)))
+
+;;;###autoload
+(defun Info-on-current-buffer (&optional nodename)
+  "Use Info mode to browse the current Info buffer.
+With a prefix arg, this queries for the node name to visit first;
+otherwise, that defaults to `Top'."
+  (interactive
+   (list (if current-prefix-arg
+            (completing-read "Node name: " (Info-build-node-completions)
+                             nil t "Top"))))
+  (unless nodename (setq nodename "Top"))
+  (info-initialize)
+  (Info-mode)
+  (setq Info-current-file
+        (or buffer-file-name
+            ;; If called on a non-file buffer, make a fake file name.
+            (concat default-directory (buffer-name))))
+  (Info--record-tag-table nodename)
+  (Info-find-node-2 nil nodename))
+
 (defun Info-revert-find-node (filename nodename)
   "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
 When *info* is already displaying FILENAME and NODENAME, the window position
@@ -1197,36 +1258,7 @@ is non-nil)."
                 (Info-file-supports-index-cookies filename))
 
            ;; See whether file has a tag table.  Record the location if yes.
-           (goto-char (point-max))
-           (forward-line -8)
-           ;; Use string-equal, not equal, to ignore text props.
-           (if (not (or (string-equal nodename "*")
-                        (not
-                         (search-forward "\^_\nEnd tag table\n" nil t))))
-               (let (pos)
-                 ;; We have a tag table.  Find its beginning.
-                 ;; Is this an indirect file?
-                 (search-backward "\nTag table:\n")
-                 (setq pos (point))
-                 (if (save-excursion
-                       (forward-line 2)
-                       (looking-at "(Indirect)\n"))
-                     ;; It is indirect.  Copy it to another buffer
-                     ;; and record that the tag table is in that buffer.
-                     (let ((buf (current-buffer))
-                           (tagbuf
-                            (or Info-tag-table-buffer
-                                (generate-new-buffer " *info tag table*"))))
-                       (setq Info-tag-table-buffer tagbuf)
-                       (with-current-buffer tagbuf
-                         (buffer-disable-undo (current-buffer))
-                         (setq case-fold-search t)
-                         (erase-buffer)
-                         (insert-buffer-substring buf))
-                       (set-marker Info-tag-table-marker
-                                   (match-end 0) tagbuf))
-                   (set-marker Info-tag-table-marker pos)))
-             (set-marker Info-tag-table-marker nil))
+            (Info--record-tag-table nodename)
            (setq Info-current-file filename)
            )))