Subject: bug#5550: 23.1.92; bookmark stops relocating

From: Thierry Volpiatto <[email-masked]>
Date: Tue, 09 Feb 2010 09:09:07 +0100

Find here the patch that fix bug#5476 and bug#5550.
(patch sent to Stefan also)

Leo <[email-masked]> writes:

> It seems this is the third bug report from me regarding bookmark. I
> wonder what has happened to it.
>
> Previously if I 'C-x r b' and choose a bookmark whose target no longer
> exists, for example, a directory, I am offered to relocate the target.
>
> Now emacs just opens a blank buffer. I recently upgraded to snow leopard
> and so I ran into lots of such cases.
>
>
> In GNU Emacs 23.1.92.2 (x86_64-apple-darwin10.2.0, Carbon Version 1.6.0 AppKit 1038.25)
>  of 2010-02-03 on Victoria.local
> Windowing system distributor `Apple Inc.', version 10.6.2
> configured using `configure  '--prefix=/usr/local/unix/emacs' '--with-mac''
>
> Important settings:
>   value of $LC_ALL: nil
>   value of $LC_COLLATE: nil
>   value of $LC_CTYPE: nil
>   value of $LC_MESSAGES: nil
>   value of $LC_MONETARY: nil
>   value of $LC_NUMERIC: nil
>   value of $LC_TIME: nil
>   value of $LANG: nil
>   value of $XMODIFIERS: nil
>   locale-coding-system: iso-latin-1-unix
>   default enable-multibyte-characters: t
>
> Major mode: Bookmark Menu
>
>
>
>
>
>

-- 
Thierry Volpiatto
##Merge of all patches applied from revision 107108
## Initial-patch: bookmark.el (bookmark-default-handler): bugfix 5476:Use buffer entry of bookmark if some instead of filename.
## patch-r107110: bookmark.el (bookmark-handle-bookmark):Fix bug 5550 fail to relocate non--existent bookmark.
## 
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1068,7 +1068,7 @@
       (funcall (or (bookmark-get-handler bookmark)
                    'bookmark-default-handler)
                (bookmark-get-bookmark bookmark))
-    (file-error
+    ('bookmark-error-no-filename ;file-error
      ;; We were unable to find the marked file, so ask if user wants to
      ;; relocate the bookmark, else remind them to consider deletion.
      (when (stringp bookmark)
@@ -1116,24 +1116,26 @@
 BMK-RECORD is a bookmark record, not a bookmark name (i.e., not a string).
 Changes current buffer and point and returns nil, or signals a `file-error'."
   (let ((file          (bookmark-get-filename bmk-record))
+	(buf           (bookmark-prop-get bmk-record 'buffer))
         (forward-str   (bookmark-get-front-context-string bmk-record))
         (behind-str    (bookmark-get-rear-context-string bmk-record))
         (place         (bookmark-get-position bmk-record)))
-    (if (not file)
-        (signal 'bookmark-error-no-filename (list 'stringp file))
-      (set-buffer (find-file-noselect file))
-      (if place (goto-char place))
-      ;; Go searching forward first.  Then, if forward-str exists and
-      ;; was found in the file, we can search backward for behind-str.
-      ;; Rationale is that if text was inserted between the two in the
-      ;; file, it's better to be put before it so you can read it,
-      ;; rather than after and remain perhaps unaware of the changes.
-      (if forward-str
-          (if (search-forward forward-str (point-max) t)
-              (goto-char (match-beginning 0))))
-      (if behind-str
-          (if (search-backward behind-str (point-min) t)
-              (goto-char (match-end 0)))))
+    (if (and file (file-readable-p file) (not (buffer-live-p buf)))
+        (with-current-buffer (find-file-noselect file) (setq buf (buffer-name)))
+        ;; No file found. See if buffer BUF have been created. If not, raise error.
+        (unless (and buf (get-buffer buf))
+          (signal 'bookmark-error-no-filename (list 'stringp file))))
+    (set-buffer buf)
+    (if place (goto-char place))
+    ;; Go searching forward first.  Then, if forward-str exists and
+    ;; was found in the file, we can search backward for behind-str.
+    ;; Rationale is that if text was inserted between the two in the
+    ;; file, it's better to be put before it so you can read it,
+    ;; rather than after and remain perhaps unaware of the changes.
+    (when (and forward-str (search-forward forward-str (point-max) t))
+      (goto-char (match-beginning 0)))
+    (when (and behind-str (search-backward behind-str (point-min) t))
+      (goto-char (match-end 0)))
     nil))
 
 ;;;###autoload
diff --git a/lisp/info.el b/lisp/info.el
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -4797,7 +4797,7 @@
     ;; Use bookmark-default-handler to move to the appropriate location
     ;; within the node.
     (bookmark-default-handler
-     (list* "" `(buffer . ,buf) (bookmark-get-bookmark-record bmk)))))
+     `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bookmark)))))
 
 (provide 'info)