unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Fix two bugs in removing bookmark fringe marks (bug#70019)
@ 2024-04-19  5:19 Karl Fogel
  2024-04-19  8:01 ` Dani Moncayo
  0 siblings, 1 reply; 8+ messages in thread
From: Karl Fogel @ 2024-04-19  5:19 UTC (permalink / raw)
  To: Emacs Developers; +Cc: 70019, Dani Moncayo

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

I'd appreciate some review on this patch.  I've no prior 
experience with fringe mark code (someone else added fringe mark 
support to bookmark.el).

This should fix bug#70019 and a separate-but-sort-of-related bug.

I'll wait at least a few days for comments/review before 
committing.

Best regards,
-Karl


[-- Attachment #2: Fix two bugs in removing bookmark fringe marks (bug#70019) --]
[-- Type: text/plain, Size: 2768 bytes --]

From a7c9618efdd423134990c22d62513eac50ab98e3 Mon Sep 17 00:00:00 2001
From: Karl Fogel <kfogel@red-bean.com>
Date: Thu, 18 Apr 2024 23:49:29 -0500
Subject: [PATCH] Fix two bugs in removing bookmark fringe marks

This fixes bug#70019 and a separate fringe-mark removal bug that
affected bookmarks in Info "dir" nodes.

* lisp/bookmark.el (bookmark--remove-fringe-mark): Fix bug#70019 by
temporarily widening in order to ensure we fetch the right overlays.
Also, don't tamper with the filename as received from the bookmark
object, since we will compare the received filename against one
generated dynamically by the same means (`bookmark-buffer-file-name')
to determine whether or not we're in the right buffer.
---
 lisp/bookmark.el | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index bf2357207d8..5d01fe24991 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -515,15 +515,30 @@ bookmark--remove-fringe-mark
         (non-essential t)
         overlays found temp)
     (when (and pos filename)
-      (setq filename (abbreviate-file-name (expand-file-name filename)))
       (dolist (buf (buffer-list))
         (with-current-buffer buf
           (when (equal filename
                        (ignore-errors (bookmark-buffer-file-name)))
             (setq overlays
                   (save-excursion
-                    (goto-char pos)
-                    (overlays-in (pos-bol) (1+ (pos-bol)))))
+                    (save-restriction
+                      ;; Suppose bookmark "foo" was earlier set at
+                      ;; location X in a file, but now the file is
+                      ;; narrowed such that X is outside the restriction.
+                      ;; Then the `goto-char' below would go to the
+                      ;; wrong place and thus the wrong overlays would
+                      ;; be fetched.  This is why we temporarily `widen'
+                      ;; before fetching.
+                      ;;
+                      ;; (This circumstance can easily arise when a
+                      ;; bookmark was set on Info node X but now the
+                      ;; "*info*" buffer is showing some other node Y,
+                      ;; with X and Y physically located in the same
+                      ;; file, as is often the case with Info nodes.
+                      ;; See bug #70019, for example.)
+                      (widen)
+                      (goto-char pos)
+                      (overlays-in (pos-bol) (1+ (pos-bol))))))
             (while (and (not found) (setq temp (pop overlays)))
               (when (eq 'bookmark (overlay-get temp 'category))
                 (delete-overlay (setq found temp))))))))))
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-04-22 22:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19  5:19 [PATCH] Fix two bugs in removing bookmark fringe marks (bug#70019) Karl Fogel
2024-04-19  8:01 ` Dani Moncayo
2024-04-20  0:54   ` Karl Fogel
2024-04-20  6:50     ` Dani Moncayo
2024-04-22  3:51       ` Karl Fogel
2024-04-22  6:26         ` Dani Moncayo
2024-04-22  7:40           ` bug#70019: " Eli Zaretskii
2024-04-22 22:21             ` Karl Fogel

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