comparison lisp/bookmark.el @ 107125:063e00f61d0f

(bookmark-handle-bookmark): Catch the right error. (bookmark-default-handler): Accept new bookmark field `buffer'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 10 Feb 2010 15:02:54 -0500
parents 203a882ff4c0
children 3c9f81253d07
comparison
equal deleted inserted replaced
107124:5db482a31869 107125:063e00f61d0f
1066 that file no longer exists, then offer interactively to relocate BOOKMARK." 1066 that file no longer exists, then offer interactively to relocate BOOKMARK."
1067 (condition-case err 1067 (condition-case err
1068 (funcall (or (bookmark-get-handler bookmark) 1068 (funcall (or (bookmark-get-handler bookmark)
1069 'bookmark-default-handler) 1069 'bookmark-default-handler)
1070 (bookmark-get-bookmark bookmark)) 1070 (bookmark-get-bookmark bookmark))
1071 (file-error 1071 (bookmark-error-no-filename ;file-error
1072 ;; We were unable to find the marked file, so ask if user wants to 1072 ;; We were unable to find the marked file, so ask if user wants to
1073 ;; relocate the bookmark, else remind them to consider deletion. 1073 ;; relocate the bookmark, else remind them to consider deletion.
1074 (when (stringp bookmark) 1074 (when (stringp bookmark)
1075 ;; `bookmark' can be either a bookmark name (from `bookmark-alist') 1075 ;; `bookmark' can be either a bookmark name (from `bookmark-alist')
1076 ;; or a bookmark object. If it's an object, we assume it's a 1076 ;; or a bookmark object. If it's an object, we assume it's a
1114 (defun bookmark-default-handler (bmk-record) 1114 (defun bookmark-default-handler (bmk-record)
1115 "Default handler to jump to a particular bookmark location. 1115 "Default handler to jump to a particular bookmark location.
1116 BMK-RECORD is a bookmark record, not a bookmark name (i.e., not a string). 1116 BMK-RECORD is a bookmark record, not a bookmark name (i.e., not a string).
1117 Changes current buffer and point and returns nil, or signals a `file-error'." 1117 Changes current buffer and point and returns nil, or signals a `file-error'."
1118 (let ((file (bookmark-get-filename bmk-record)) 1118 (let ((file (bookmark-get-filename bmk-record))
1119 (buf (bookmark-prop-get bmk-record 'buffer))
1119 (forward-str (bookmark-get-front-context-string bmk-record)) 1120 (forward-str (bookmark-get-front-context-string bmk-record))
1120 (behind-str (bookmark-get-rear-context-string bmk-record)) 1121 (behind-str (bookmark-get-rear-context-string bmk-record))
1121 (place (bookmark-get-position bmk-record))) 1122 (place (bookmark-get-position bmk-record)))
1122 (if (not file) 1123 (set-buffer
1123 (signal 'bookmark-error-no-filename (list 'stringp file)) 1124 (cond
1124 (set-buffer (find-file-noselect file)) 1125 ((and file (file-readable-p file) (not (buffer-live-p buf)))
1125 (if place (goto-char place)) 1126 (find-file-noselect file))
1126 ;; Go searching forward first. Then, if forward-str exists and 1127 ;; No file found. See if buffer BUF have been created.
1127 ;; was found in the file, we can search backward for behind-str. 1128 ((and buf (get-buffer buf)))
1128 ;; Rationale is that if text was inserted between the two in the 1129 (t ;; If not, raise error.
1129 ;; file, it's better to be put before it so you can read it, 1130 (signal 'bookmark-error-no-filename (list 'stringp file)))))
1130 ;; rather than after and remain perhaps unaware of the changes. 1131 (if place (goto-char place))
1131 (if forward-str 1132 ;; Go searching forward first. Then, if forward-str exists and
1132 (if (search-forward forward-str (point-max) t) 1133 ;; was found in the file, we can search backward for behind-str.
1133 (goto-char (match-beginning 0)))) 1134 ;; Rationale is that if text was inserted between the two in the
1134 (if behind-str 1135 ;; file, it's better to be put before it so you can read it,
1135 (if (search-backward behind-str (point-min) t) 1136 ;; rather than after and remain perhaps unaware of the changes.
1136 (goto-char (match-end 0))))) 1137 (when (and forward-str (search-forward forward-str (point-max) t))
1138 (goto-char (match-beginning 0)))
1139 (when (and behind-str (search-backward behind-str (point-min) t))
1140 (goto-char (match-end 0)))
1137 nil)) 1141 nil))
1138 1142
1139 ;;;###autoload 1143 ;;;###autoload
1140 (defun bookmark-relocate (bookmark) 1144 (defun bookmark-relocate (bookmark)
1141 "Relocate BOOKMARK to another file (reading file name with minibuffer). 1145 "Relocate BOOKMARK to another file (reading file name with minibuffer).