bug#81467: [PATCH] Make bookmark-jump work with other-window/frame/tab-prefix

Juri Linkov <[email protected]>
Newsgroups gmane.emacs.bugs
Organization LINKOV.NET
Message-ID <[email protected]>
> What if 'display-buffer' to show another unrelated buffer
> is called in 'bookmark-handle-bookmark'?

It's possible to check the buffer.  Also using the same trick
as in 'display-buffer-override-next-command' that temporarily
changes 'display-buffer-overriding-action', here is the patch
that does the same, but uses the added action as a way to detect
if 'display-buffer' was already called with the same buffer:
bookmark-was-called.patch (text/x-diff, 1.6 KB)
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 77136308573..7832a63c14d 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1265,12 +1265,25 @@ bookmark--jump-via
 After calling DISPLAY-FUNCTION, set window point to the point specified
 by BOOKMARK-NAME-OR-RECORD, if necessary, run `bookmark-after-jump-hook',
 and then show any annotations for this bookmark."
-  (let (buf point)
-    (save-window-excursion
-      (bookmark-handle-bookmark bookmark-name-or-record)
-      (setq buf (current-buffer)
-            point (point)))
-    (funcall display-function buf)
+  (let* (buf point was-called
+         (action (lambda (buffer _alist)
+                   (setq was-called buffer)
+                   nil)))
+    ;; Prepare special action to detect display-buffer call.
+    (unless (listp (car display-buffer-overriding-action))
+      (setcar display-buffer-overriding-action
+              (list (car display-buffer-overriding-action))))
+    (push action (car display-buffer-overriding-action))
+    (bookmark-handle-bookmark bookmark-name-or-record)
+    ;; Clear special action after a possible display-buffer call.
+    (setcar display-buffer-overriding-action
+            (delq action (car display-buffer-overriding-action)))
+    (setq buf (current-buffer)
+          point (point))
+    ;; Display the buffer only unless it was already displayed
+    ;; by the handler above.
+    (unless (and was-called (eq was-called buf))
+      (funcall display-function buf))
     (when-let* ((win (get-buffer-window buf 0)))
       (set-window-point win point))
     (when bookmark-fringe-mark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.