diff options
| author | Karl Fogel | 2009-10-05 04:19:04 +0000 |
|---|---|---|
| committer | Karl Fogel | 2009-10-05 04:19:04 +0000 |
| commit | 5feb1ba7e5c222ffbc9060e7efa0b00f36638d6e (patch) | |
| tree | 1dcc8dd731f385fa59829b9f264022d7f1463983 | |
| parent | 1bd49952d72256c015b1d097727762276399cc27 (diff) | |
| download | emacs-5feb1ba7e5c222ffbc9060e7efa0b00f36638d6e.tar.gz emacs-5feb1ba7e5c222ffbc9060e7efa0b00f36638d6e.zip | |
* bookmark.el (bookmark-handle-bookmark): If bookmark has no file,
don't do anything related to relocating, just return nil.
(bookmark-error-no-filename): New error.
(bookmark-default-handler): Signal `bookmark-error-no-filename' if
bookmark has no file. Don't even attempt to handle things that
are not files; the whole point of custom handlers is to keep that
knowledge elsewhere anyway. Tighten some comments.
(bookmark-file-or-variation-thereof): Remove now-unused function.
(bookmark-location): Doc string fix.
(Bug#4250)
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/bookmark.el | 108 |
2 files changed, 59 insertions, 62 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 846c66595a5..6622082e5bf 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2009-10-05 Karl Fogel <kfogel@red-bean.com> | ||
| 2 | |||
| 3 | * bookmark.el (bookmark-handle-bookmark): If bookmark has no file, | ||
| 4 | don't do anything related to relocating, just return nil. | ||
| 5 | (bookmark-error-no-filename): New error. | ||
| 6 | (bookmark-default-handler): Signal `bookmark-error-no-filename' if | ||
| 7 | bookmark has no file. Don't even attempt to handle things that | ||
| 8 | are not files; the whole point of custom handlers is to keep that | ||
| 9 | knowledge elsewhere anyway. Tighten some comments. | ||
| 10 | (bookmark-file-or-variation-thereof): Remove now-unused function. | ||
| 11 | (bookmark-location): Doc string fix. | ||
| 12 | (Bug#4250) | ||
| 13 | |||
| 1 | 2009-10-04 Karl Fogel <kfogel@red-bean.com> | 14 | 2009-10-04 Karl Fogel <kfogel@red-bean.com> |
| 2 | 15 | ||
| 3 | * bookmark.el (bookmark-handle-bookmark): When relocating a bookmark, | 16 | * bookmark.el (bookmark-handle-bookmark): When relocating a bookmark, |
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index eef888288ce..b59a06970bc 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -1025,26 +1025,6 @@ the latter is usually only used by programmatic callers." | |||
| 1025 | (bookmark--jump-via bookmark 'switch-to-buffer-other-window))) | 1025 | (bookmark--jump-via bookmark 'switch-to-buffer-other-window))) |
| 1026 | 1026 | ||
| 1027 | 1027 | ||
| 1028 | (defun bookmark-file-or-variation-thereof (file) | ||
| 1029 | "Return FILE (a string) if it exists, or return a reasonable | ||
| 1030 | variation of FILE if that exists. Reasonable variations are checked | ||
| 1031 | by appending suffixes defined in `Info-suffix-list'. If cannot find FILE | ||
| 1032 | nor a reasonable variation thereof, then still return FILE if it can | ||
| 1033 | be retrieved from a VC backend, else return nil." | ||
| 1034 | (if (file-exists-p file) | ||
| 1035 | file | ||
| 1036 | (or | ||
| 1037 | (progn (require 'info) ; ensure Info-suffix-list is bound | ||
| 1038 | (catch 'found | ||
| 1039 | (mapc (lambda (elt) | ||
| 1040 | (let ((suffixed-file (concat file (car elt)))) | ||
| 1041 | (if (file-exists-p suffixed-file) | ||
| 1042 | (throw 'found suffixed-file)))) | ||
| 1043 | Info-suffix-list) | ||
| 1044 | nil)) | ||
| 1045 | ;; Last possibility: try VC | ||
| 1046 | (if (vc-backend file) file)))) | ||
| 1047 | |||
| 1048 | (defun bookmark-jump-noselect (bookmark) | 1028 | (defun bookmark-jump-noselect (bookmark) |
| 1049 | "Return the location pointed to by the bookmark BOOKMARK. | 1029 | "Return the location pointed to by the bookmark BOOKMARK. |
| 1050 | The return value has the form (BUFFER . POINT). | 1030 | The return value has the form (BUFFER . POINT). |
| @@ -1061,9 +1041,13 @@ compatibility only." | |||
| 1061 | 1041 | ||
| 1062 | (defun bookmark-handle-bookmark (bookmark) | 1042 | (defun bookmark-handle-bookmark (bookmark) |
| 1063 | "Call BOOKMARK's handler or `bookmark-default-handler' if it has none. | 1043 | "Call BOOKMARK's handler or `bookmark-default-handler' if it has none. |
| 1044 | BOOKMARK may be a bookmark name (a string) or a bookmark record. | ||
| 1045 | |||
| 1064 | Changes current buffer and point and returns nil, or signals a `file-error'. | 1046 | Changes current buffer and point and returns nil, or signals a `file-error'. |
| 1065 | 1047 | ||
| 1066 | BOOKMARK may be a bookmark name (a string) or a bookmark record." | 1048 | If BOOKMARK has no file, this is a no-op. If BOOKMARK has a file, but |
| 1049 | that file no longer exists, then offer interactively to relocate BOOKMARK. | ||
| 1050 | " | ||
| 1067 | (condition-case err | 1051 | (condition-case err |
| 1068 | (funcall (or (bookmark-get-handler bookmark) | 1052 | (funcall (or (bookmark-get-handler bookmark) |
| 1069 | 'bookmark-default-handler) | 1053 | 'bookmark-default-handler) |
| @@ -1072,57 +1056,57 @@ BOOKMARK may be a bookmark name (a string) or a bookmark record." | |||
| 1072 | ;; We were unable to find the marked file, so ask if user wants to | 1056 | ;; We were unable to find the marked file, so ask if user wants to |
| 1073 | ;; relocate the bookmark, else remind them to consider deletion. | 1057 | ;; relocate the bookmark, else remind them to consider deletion. |
| 1074 | (when (stringp bookmark) | 1058 | (when (stringp bookmark) |
| 1075 | ;; `bookmark' can either be a bookmark name (found in | 1059 | ;; `bookmark' can be either a bookmark name (from `bookmark-alist') |
| 1076 | ;; `bookmark-alist') or a bookmark object. If it's an object, we | 1060 | ;; or a bookmark object. If it's an object, we assume it's a |
| 1077 | ;; assume it's a bookmark used internally by some other package. | 1061 | ;; bookmark used internally by some other package. |
| 1078 | (let* ((file (bookmark-get-filename bookmark)) | 1062 | (let ((file (bookmark-get-filename bookmark))) |
| 1079 | ;; If file is not a directory, this should be a no-op. | ||
| 1080 | (display-name (directory-file-name file))) | ||
| 1081 | (when file ;Don't know how to relocate if there's no `file'. | 1063 | (when file ;Don't know how to relocate if there's no `file'. |
| 1082 | (ding) | 1064 | ;; If file is not a dir, directory-file-name just returns file. |
| 1083 | ;; Dialog boxes can accept a file target, but usually don't | 1065 | (let ((display-name (directory-file-name file))) |
| 1084 | ;; know how to accept a directory target (at least, this | 1066 | (ding) |
| 1085 | ;; was true in Gnome on GNU/Linux, and Bug#4230 says it's | 1067 | ;; Dialog boxes can accept a file target, but usually don't |
| 1086 | ;; true on Windows as well). Thus, suppress file dialogs | 1068 | ;; know how to accept a directory target (at least, this |
| 1087 | ;; when relocating. | 1069 | ;; is true in Gnome on GNU/Linux, and Bug#4230 says it's |
| 1088 | (let ((use-dialog-box nil) | 1070 | ;; true on Windows as well). So we suppress file dialogs |
| 1089 | (use-file-dialog nil)) | 1071 | ;; when relocating. |
| 1090 | (if (y-or-n-p (concat display-name " nonexistent. Relocate \"" | 1072 | (let ((use-dialog-box nil) |
| 1091 | bookmark "\"? ")) | 1073 | (use-file-dialog nil)) |
| 1092 | (progn | 1074 | (if (y-or-n-p (concat display-name " nonexistent. Relocate \"" |
| 1093 | (bookmark-relocate bookmark) | 1075 | bookmark "\"? ")) |
| 1094 | ;; Try again. | 1076 | (progn |
| 1095 | (funcall (or (bookmark-get-handler bookmark) | 1077 | (bookmark-relocate bookmark) |
| 1096 | 'bookmark-default-handler) | 1078 | ;; Try again. |
| 1097 | (bookmark-get-bookmark bookmark))) | 1079 | (funcall (or (bookmark-get-handler bookmark) |
| 1098 | (message | 1080 | 'bookmark-default-handler) |
| 1099 | "Bookmark not relocated; consider removing it \(%s\)." bookmark) | 1081 | (bookmark-get-bookmark bookmark))) |
| 1100 | (signal (car err) (cdr err))))))))) | 1082 | (message |
| 1083 | "Bookmark not relocated; consider removing it \(%s\)." | ||
| 1084 | bookmark) | ||
| 1085 | (signal (car err) (cdr err)))))))))) | ||
| 1101 | ;; Added by db. | 1086 | ;; Added by db. |
| 1102 | (when (stringp bookmark) | 1087 | (when (stringp bookmark) |
| 1103 | (setq bookmark-current-bookmark bookmark)) | 1088 | (setq bookmark-current-bookmark bookmark)) |
| 1104 | nil) | 1089 | nil) |
| 1105 | 1090 | ||
| 1091 | (put 'bookmark-error-no-filename | ||
| 1092 | 'error-conditions | ||
| 1093 | '(error bookmark-errors bookmark-error-no-filename)) | ||
| 1094 | (put 'bookmark-error-no-filename | ||
| 1095 | 'error-message | ||
| 1096 | "Bookmark has no associated file (or directory)") | ||
| 1097 | |||
| 1106 | (defun bookmark-default-handler (bmk-record) | 1098 | (defun bookmark-default-handler (bmk-record) |
| 1107 | "Default handler to jump to a particular bookmark location. | 1099 | "Default handler to jump to a particular bookmark location. |
| 1108 | BMK-RECORD is a bookmark record, not a bookmark name (i.e., not a string). | 1100 | BMK-RECORD is a bookmark record, not a bookmark name (i.e., not a string). |
| 1109 | Changes current buffer and point and returns nil, or signals a `file-error'." | 1101 | Changes current buffer and point and returns nil, or signals a `file-error'." |
| 1110 | (let* ((file (bookmark-get-filename bmk-record)) | 1102 | (let ((file (bookmark-get-filename bmk-record)) |
| 1111 | (buf (bookmark-prop-get bmk-record 'buffer)) | 1103 | (forward-str (bookmark-get-front-context-string bmk-record)) |
| 1112 | (forward-str (bookmark-get-front-context-string bmk-record)) | 1104 | (behind-str (bookmark-get-rear-context-string bmk-record)) |
| 1113 | (behind-str (bookmark-get-rear-context-string bmk-record)) | 1105 | (place (bookmark-get-position bmk-record))) |
| 1114 | (place (bookmark-get-position bmk-record))) | 1106 | (if (not file) |
| 1115 | ;; FIXME: bookmark-file-or-variation-thereof was needed for Info files, | 1107 | (signal 'bookmark-error-no-filename (list 'stringp file)) |
| 1116 | ;; but now that Info bookmarks are handled elsewhere it seems that we | 1108 | (set-buffer (find-file-noselect file)) |
| 1117 | ;; should be able to get rid of it. --Stef | ||
| 1118 | (if (not (if buf (buffer-live-p buf) | ||
| 1119 | (setq file (bookmark-file-or-variation-thereof file)))) | ||
| 1120 | (signal 'file-error | ||
| 1121 | `("Jumping to bookmark" "No such file or directory" | ||
| 1122 | (bookmark-get-filename bmk-record))) | ||
| 1123 | (set-buffer (or buf (find-file-noselect file))) | ||
| 1124 | (if place (goto-char place)) | 1109 | (if place (goto-char place)) |
| 1125 | |||
| 1126 | ;; Go searching forward first. Then, if forward-str exists and | 1110 | ;; Go searching forward first. Then, if forward-str exists and |
| 1127 | ;; was found in the file, we can search backward for behind-str. | 1111 | ;; was found in the file, we can search backward for behind-str. |
| 1128 | ;; Rationale is that if text was inserted between the two in the | 1112 | ;; Rationale is that if text was inserted between the two in the |
| @@ -1186,7 +1170,7 @@ minibuffer history list `bookmark-history'." | |||
| 1186 | (defalias 'bookmark-locate 'bookmark-insert-location) | 1170 | (defalias 'bookmark-locate 'bookmark-insert-location) |
| 1187 | 1171 | ||
| 1188 | (defun bookmark-location (bookmark) | 1172 | (defun bookmark-location (bookmark) |
| 1189 | "Return the name of the file associated with BOOKMARK. | 1173 | "Return the name of the file associated with BOOKMARK, or nil if none. |
| 1190 | BOOKMARK may be a bookmark name (a string) or a bookmark record." | 1174 | BOOKMARK may be a bookmark name (a string) or a bookmark record." |
| 1191 | (bookmark-maybe-load-default-file) | 1175 | (bookmark-maybe-load-default-file) |
| 1192 | (bookmark-get-filename bookmark)) | 1176 | (bookmark-get-filename bookmark)) |