unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Karl Fogel <kfogel@red-bean.com>
To: Emacs Developers <emacs-devel@gnu.org>
Cc: 70019@debbugs.gnu.org, Dani Moncayo <dmoncayo@gmail.com>
Subject: [PATCH] Fix two bugs in removing bookmark fringe marks (bug#70019)
Date: Fri, 19 Apr 2024 00:19:45 -0500	[thread overview]
Message-ID: <87r0f26ia6.fsf@red-bean.com> (raw)

[-- 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


             reply	other threads:[~2024-04-19  5:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19  5:19 Karl Fogel [this message]
2024-04-19  8:01 ` [PATCH] Fix two bugs in removing bookmark fringe marks (bug#70019) 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

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=87r0f26ia6.fsf@red-bean.com \
    --to=kfogel@red-bean.com \
    --cc=70019@debbugs.gnu.org \
    --cc=dmoncayo@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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).