;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later
-;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2003 Free Software Foundation
+;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003,
+;; 2004, 2005 Free Software Foundation, Inc.
;; Author: Karl Fogel <kfogel@red-bean.com>
;; Maintainer: Karl Fogel <kfogel@red-bean.com>
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(defcustom bookmark-automatically-show-annotations t
- "*nil means don't show annotations when jumping to a bookmark."
+ "*Non-nil means show annotations when jumping to a bookmark."
:type 'boolean
:group 'bookmark)
(defvar bookmark-yank-point 0)
(defvar bookmark-current-buffer nil)
-
+(defvar Info-current-node)
+(defvar Info-suffix-list)
\f
;; Helper functions.
(defun bookmark-get-bookmark (bookmark)
- "Return the full entry for BOOKMARK in bookmark-alist.
+ "Return the full entry for BOOKMARK in `bookmark-alist'.
If BOOKMARK is not a string, return nil."
(when (stringp bookmark)
- (apply (if bookmark-completion-ignore-case
- #'assoc-ignore-case
- #'assoc)
- (list bookmark bookmark-alist))))
+ (assoc-string bookmark bookmark-alist bookmark-completion-ignore-case)))
(defun bookmark-get-bookmark-record (bookmark)
- "Return the guts of the entry for BOOKMARK in bookmark-alist.
+ "Return the guts of the entry for BOOKMARK in `bookmark-alist'.
That is, all information but the name."
(car (cdr (bookmark-get-bookmark bookmark))))
(if cell
(setcdr cell filename)
(nconc (bookmark-get-bookmark-record bookmark)
- (list (cons 'filename filename))))))
+ (list (cons 'filename filename))))
+ (setq bookmark-alist-modification-count
+ (1+ bookmark-alist-modification-count))
+ (if (bookmark-time-to-save-p)
+ (bookmark-save))))
(defun bookmark-get-position (bookmark)
(list (cons 'info-node node)))))
(message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark)))
- (sit-for 4)
- )
+ (sit-for 4))
(defvar bookmark-history nil
(defun bookmark-alist-from-buffer ()
- "Return a bookmark-alist (in any format) from the current buffer.
+ "Return a `bookmark-alist' (in any format) from the current buffer.
The buffer must of course contain bookmark format information.
Does not care from where in the buffer it is called, and does not
affect point."
(defun bookmark-upgrade-file-format-from-0 ()
"Upgrade a bookmark file of format 0 (the original format) to format 1.
-This expects to be called from point-min in a bookmark file."
+This expects to be called from `point-min' in a bookmark file."
(message "Upgrading bookmark format from 0 to %d..."
bookmark-file-format-version)
(let* ((old-list (bookmark-alist-from-buffer))
(defun bookmark-grok-file-format-version ()
"Return an integer which is the file-format version of this bookmark file.
-This expects to be called from point-min in a bookmark file."
+This expects to be called from `point-min' in a bookmark file."
(if (looking-at "^;;;;")
(save-excursion
(save-match-data
(defun bookmark-maybe-upgrade-file-format ()
"Check the file-format version of this bookmark file.
If the version is not up-to-date, upgrade it automatically.
-This expects to be called from point-min in a bookmark file."
+This expects to be called from `point-min' in a bookmark file."
(let ((version (bookmark-grok-file-format-version)))
(cond
((= version bookmark-file-format-version)
(defun bookmark-kill-line (&optional newline-too)
"Kill from point to end of line.
If optional arg NEWLINE-TOO is non-nil, delete the newline too.
-Does not affect the kill-ring."
+Does not affect the kill ring."
(let ((eol (save-excursion (end-of-line) (point))))
(delete-region (point) eol)
(if (and newline-too (looking-at "\n"))
(defvar bookmark-read-annotation-text-func 'bookmark-default-annotation-text
"Function to return default text to use for a bookmark annotation.
-It takes the name of the bookmark, as a string, as an arg.")
+It takes one argument, the name of the bookmark, as a string.")
(defun bookmark-read-annotation-mode (buf point parg bookmark)
"Mode for composing annotations for a bookmark.
-Wants BUF POINT PARG and BOOKMARK.
+Wants BUF, POINT, PARG, and BOOKMARK.
When you have finished composing, type \\[bookmark-send-annotation] to send
the annotation.
(use-local-map bookmark-read-annotation-mode-map)
(setq major-mode 'bookmark-read-annotation-mode)
(insert (funcall bookmark-read-annotation-text-func bookmark))
- (run-hooks 'text-mode-hook))
+ (run-mode-hooks 'text-mode-hook))
(defun bookmark-read-annotation (parg bookmark)
(make-local-variable 'bookmark-annotation-name)
(setq bookmark-annotation-name bookmark)
(use-local-map bookmark-edit-annotation-mode-map)
- (setq major-mode 'bookmark-edit-annotation-mode)
+ (setq major-mode 'bookmark-edit-annotation-mode
+ mode-name "Edit Bookmark Annotation")
(insert (funcall bookmark-read-annotation-text-func bookmark))
(let ((annotation (bookmark-get-annotation bookmark)))
(if (and annotation (not (string-equal annotation "")))
(insert annotation)))
- (run-hooks 'text-mode-hook))
+ (run-mode-hooks 'text-mode-hook))
(defun bookmark-send-edited-annotation ()
- "Use buffer contents (minus beginning with `#' as annotation for a bookmark."
+ "Use buffer contents as annotation for a bookmark.
+Lines beginning with `#' are ignored."
(interactive)
(if (not (eq major-mode 'bookmark-edit-annotation-mode))
(error "Not in bookmark-edit-annotation-mode"))
(defun bookmark-insert-current-bookmark ()
- "Insert this buffer's value of bookmark-current-bookmark.
+ "Insert this buffer's value of `bookmark-current-bookmark'.
Default to file name if it's nil."
(interactive)
(let ((str
(insert string)))
+(defvar Info-current-file)
+
(defun bookmark-buffer-file-name ()
"Return the current buffer's file in a way useful for bookmarks.
For example, if this is a Info buffer, return the Info file's name."
(lambda (x y) (string-lessp (car x) (car y))))))))
+(defvar bookmark-after-jump-hook nil
+ "Hook run after `bookmark-jump' jumps to a bookmark.
+Useful for example to unhide text in `outline-mode'.")
+
;;;###autoload
(defun bookmark-jump (bookmark)
"Jump to bookmark BOOKMARK (a point in some file).
this.
If the file pointed to by BOOKMARK no longer exists, you will be asked
-if you wish to give the bookmark a new location, and bookmark-jump
+if you wish to give the bookmark a new location, and `bookmark-jump'
will then jump to the new location, as well as recording it in place
of the old one in the permanent bookmark record."
(interactive
(list (bookmark-completing-read "Jump to bookmark"
bookmark-current-bookmark)))
+ (unless bookmark
+ (error "No bookmark specified"))
(bookmark-maybe-historicize-string bookmark)
(let ((cell (bookmark-jump-noselect bookmark)))
(and cell
(switch-to-buffer (car cell))
(goto-char (cdr cell))
+ (progn (run-hooks 'bookmark-after-jump-hook) t)
(if bookmark-automatically-show-annotations
;; if there is an annotation for this bookmark,
;; show it in a buffer.
;; Info nodes must be visited with care.
(progn
(require 'info)
- (Info-find-node file info-node))
+ (with-no-warnings
+ (Info-find-node file info-node)))
;; Else no Info. Can do an ordinary find-file:
(set-buffer (find-file-noselect file))
(goto-char place))
`bookmark-default-file'. With a prefix arg, save it in file FILE
\(second argument\).
-If you are calling this from Lisp, the two arguments are PREFIX-ARG
-and FILE, and if you just want it to write to the default file, then
+If you are calling this from Lisp, the two arguments are PARG and
+FILE, and if you just want it to write to the default file, then
pass no arguments. Or pass in nil and FILE, and it will save in FILE
instead. If you pass in one argument, and it is non-nil, then the
user will be interactively queried for a file to save in.
((eq 'nospecial bookmark-version-control) version-control)
(t
t))))
- (write-file file)
+ (condition-case nil
+ (write-file file)
+ (file-error (message "Can't write %s" file)))
(kill-buffer (current-buffer))
(if (>= baud-rate 9600)
(message "Saving bookmarks to file %s...done" file)))))))
(define-key bookmark-bmenu-mode-map "m" 'bookmark-bmenu-mark)
(define-key bookmark-bmenu-mode-map "l" 'bookmark-bmenu-load)
(define-key bookmark-bmenu-mode-map "r" 'bookmark-bmenu-rename)
+ (define-key bookmark-bmenu-mode-map "R" 'bookmark-bmenu-relocate)
(define-key bookmark-bmenu-mode-map "t" 'bookmark-bmenu-toggle-filenames)
(define-key bookmark-bmenu-mode-map "a" 'bookmark-bmenu-show-annotation)
(define-key bookmark-bmenu-mode-map "A" 'bookmark-bmenu-show-all-annotations)
so the bookmark menu bookmark remains visible in its window.
\\[bookmark-bmenu-switch-other-window] -- switch the other window to this bookmark.
\\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).
+\\[bookmark-bmenu-relocate] -- relocate this bookmark's file \(prompts for new file\).
\\[bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
\\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
\\[bookmark-bmenu-execute-deletions] -- delete bookmarks marked with `\\[bookmark-bmenu-delete]'.
(setq buffer-read-only t)
(setq major-mode 'bookmark-bmenu-mode)
(setq mode-name "Bookmark Menu")
- (run-hooks 'bookmark-bmenu-mode-hook))
+ (run-mode-hooks 'bookmark-bmenu-mode-hook))
(defun bookmark-bmenu-toggle-filenames (&optional show)
(setq tem (bookmark-bmenu-bookmark))
(let ((inhibit-read-only t))
(delete-char -1)
- (insert ?\ ))
+ (insert ?\s))
(or (string-equal tem bmrk)
(member tem others)
(setq others (cons tem others))))
(let ((bmrk (bookmark-bmenu-bookmark)))
(message (bookmark-location bmrk)))))
+(defun bookmark-bmenu-relocate ()
+ "Change the file path of the bookmark on the current line,
+ prompting with completion for the new path."
+ (interactive)
+ (if (bookmark-bmenu-check-position)
+ (let ((bmrk (bookmark-bmenu-bookmark))
+ (thispoint (point)))
+ (bookmark-relocate bmrk)
+ (goto-char thispoint))))
\f
;;; Menu bar stuff. Prefix is "bookmark-menu".
(format "-*- %s (%d) -*-" name iter)
(nreverse lst))
pane-list)))
-
+
;; Popup the menu and return the string.
(x-popup-menu event (cons (concat "-*- " name " -*-")
(nreverse pane-list)))))
(define-key map [write] '("Save Bookmarks As..." . bookmark-write))
(define-key map [save] '("Save Bookmarks" . bookmark-save))
(define-key map [edit] '("Edit Bookmark List" . bookmark-bmenu-list))
- (define-key map [delete] '("Delete Bookmark" . bookmark-delete))
- (define-key map [rename] '("Rename Bookmark" . bookmark-rename))
- (define-key map [locate] '("Insert Location" . bookmark-locate))
- (define-key map [insert] '("Insert Contents" . bookmark-insert))
- (define-key map [set] '("Set Bookmark" . bookmark-set))
- (define-key map [jump] '("Jump to Bookmark" . bookmark-jump))
+ (define-key map [delete] '("Delete Bookmark..." . bookmark-delete))
+ (define-key map [rename] '("Rename Bookmark..." . bookmark-rename))
+ (define-key map [locate] '("Insert Location..." . bookmark-locate))
+ (define-key map [insert] '("Insert Contents..." . bookmark-insert))
+ (define-key map [set] '("Set Bookmark..." . bookmark-set))
+ (define-key map [jump] '("Jump to Bookmark..." . bookmark-jump))
map))
;;;###autoload
;;; Exit Hook, called from kill-emacs-hook
(defvar bookmark-exit-hook nil
- "Hook run when emacs exits.")
+ "Hook run when Emacs exits.")
+
+(define-obsolete-variable-alias 'bookmark-exit-hooks 'bookmark-exit-hook "22.1")
(defun bookmark-exit-hook-internal ()
"Save bookmark state, if necessary, at Emacs exit time.
-This also runs `bookmark-exit-hooks'."
- (run-hooks 'bookmark-exit-hooks)
+This also runs `bookmark-exit-hook'."
+ (run-hooks 'bookmark-exit-hook)
(and bookmark-alist
(bookmark-time-to-save-p t)
(bookmark-save)))
(provide 'bookmark)
+;;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6
;;; bookmark.el ends here