diff options
Diffstat (limited to 'lisp/bookmark.el')
-rw-r--r-- | lisp/bookmark.el | 139 |
1 files changed, 81 insertions, 58 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 9515837fc28..11883febb07 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -1,7 +1,8 @@ ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later -;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003, -;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003, 2004, +;; 2005, 2006, 2007, 2008, 2009, 2010 +;; Free Software Foundation, Inc. ;; Author: Karl Fogel <kfogel@red-bean.com> ;; Maintainer: Karl Fogel <kfogel@red-bean.com> @@ -92,7 +93,7 @@ To specify the file in which to save them, modify the variable (if bookmark-file ;; In case user set `bookmark-file' in her .emacs: bookmark-file - (convert-standard-filename "~/.emacs.bmk")) + (locate-user-emacs-file "bookmarks" ".emacs.bmk")) "File in which to save bookmarks by default." :type 'file :group 'bookmark) @@ -528,26 +529,36 @@ old one." (setq bookmark-current-bookmark stripped-name) (bookmark-bmenu-surreptitiously-rebuild-list))) -(defun bookmark-make-record-default (&optional point-only) +(defun bookmark-make-record-default (&optional no-file no-context posn) "Return the record describing the location of a new bookmark. -Must be at the correct position in the buffer in which the bookmark is -being set. -If POINT-ONLY is non-nil, then only return the subset of the -record that pertains to the location within the buffer." - `(,@(unless point-only `((filename . ,(bookmark-buffer-file-name)))) - (front-context-string - . ,(if (>= (- (point-max) (point)) bookmark-search-size) - (buffer-substring-no-properties - (point) - (+ (point) bookmark-search-size)) - nil)) - (rear-context-string - . ,(if (>= (- (point) (point-min)) bookmark-search-size) - (buffer-substring-no-properties - (point) - (- (point) bookmark-search-size)) - nil)) - (position . ,(point)))) +Point should be at the buffer in which the bookmark is being set, +and normally should be at the position where the bookmark is desired, +but see the optional arguments for other possibilities. + +If NO-FILE is non-nil, then only return the subset of the +record that pertains to the location within the buffer, leaving off +the part that records the filename. + +If NO-CONTEXT is non-nil, do not include the front- and rear-context +strings in the record -- the position is enough. + +If POSN is non-nil, record POSN as the point instead of `(point)'." + `(,@(unless no-file `((filename . ,(bookmark-buffer-file-name)))) + ,@(unless no-context `((front-context-string + . ,(if (>= (- (point-max) (point)) + bookmark-search-size) + (buffer-substring-no-properties + (point) + (+ (point) bookmark-search-size)) + nil)))) + ,@(unless no-context `((rear-context-string + . ,(if (>= (- (point) (point-min)) + bookmark-search-size) + (buffer-substring-no-properties + (point) + (- (point) bookmark-search-size)) + nil)))) + (position . ,(or posn (point))))) ;;; File format stuff @@ -773,33 +784,40 @@ Use \\[bookmark-delete] to remove bookmarks (you give it a name and it removes only the first instance of a bookmark with that name from the list of bookmarks.)" (interactive (list nil current-prefix-arg)) - (let* ((record (bookmark-make-record)) - (default (car record))) + (unwind-protect + (let* ((record (bookmark-make-record)) + (default (car record))) + + (bookmark-maybe-load-default-file) + ;; Don't set `bookmark-yank-point' and `bookmark-current-buffer' + ;; if they have been already set in another buffer. (e.g gnus-art). + (unless (and bookmark-yank-point + bookmark-current-buffer) + (setq bookmark-yank-point (point)) + (setq bookmark-current-buffer (current-buffer))) + + (let ((str + (or name + (read-from-minibuffer + (format "Set bookmark (%s): " default) + nil + bookmark-minibuffer-read-name-map + nil nil default)))) + (and (string-equal str "") (setq str default)) + (bookmark-store str (cdr record) no-overwrite) + + ;; Ask for an annotation buffer for this bookmark + (when bookmark-use-annotations + (bookmark-edit-annotation str)))) + (setq bookmark-yank-point nil) + (setq bookmark-current-buffer nil))) - (bookmark-maybe-load-default-file) - - (setq bookmark-yank-point (point)) - (setq bookmark-current-buffer (current-buffer)) - - (let ((str - (or name - (read-from-minibuffer - (format "Set bookmark (%s): " default) - nil - bookmark-minibuffer-read-name-map - nil nil default)))) - (and (string-equal str "") (setq str default)) - (bookmark-store str (cdr record) no-overwrite) - - ;; Ask for an annotation buffer for this bookmark - (when bookmark-use-annotations - (bookmark-edit-annotation str))))) (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." - (let ((eol (save-excursion (end-of-line) (point)))) + (let ((eol (line-end-position))) (delete-region (point) eol) (if (and newline-too (looking-at "\n")) (delete-char 1)))) @@ -1176,7 +1194,7 @@ minibuffer history list `bookmark-history'." (or no-history (bookmark-maybe-historicize-string bookmark)) (let ((start (point))) (prog1 - (insert (bookmark-location bookmark)) ; *Return this line* + (insert (bookmark-location bookmark)) (if (display-mouse-p) (add-text-properties start @@ -1191,10 +1209,16 @@ minibuffer history list `bookmark-history'." (defalias 'bookmark-locate 'bookmark-insert-location) (defun bookmark-location (bookmark) - "Return the name of the file associated with BOOKMARK, or nil if none. + "Return a description of the location of BOOKMARK. BOOKMARK may be a bookmark name (a string) or a bookmark record." (bookmark-maybe-load-default-file) - (bookmark-get-filename bookmark)) + ;; We could call the `handler' and ask for it to construct a description + ;; dynamically: it would open up several new possibilities, but it + ;; would have the major disadvantage of forcing to load each and + ;; every handler when the user calls bookmark-menu. + (or (bookmark-prop-get bookmark 'location) + (bookmark-get-filename bookmark) + "-- Unknown location --")) ;;;###autoload @@ -1661,7 +1685,7 @@ mainly for debugging, and should not be necessary in normal use." (while (< (point) (point-max)) (let ((bmrk (bookmark-bmenu-bookmark))) (push bmrk bookmark-bmenu-hidden-bookmarks) - (let ((start (save-excursion (end-of-line) (point)))) + (let ((start (line-end-position))) (move-to-column bookmark-bmenu-file-column t) ;; Strip off `mouse-face' from the white spaces region. (if (display-mouse-p) @@ -1727,15 +1751,15 @@ last full line, move to the last full line. The return value is undefined." "Display the annotation for bookmark named BOOKMARK in a buffer, if an annotation exists." (let ((annotation (bookmark-get-annotation bookmark))) - (if (and annotation (not (string-equal annotation ""))) - (save-excursion - (let ((old-buf (current-buffer))) - (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t) - (delete-region (point-min) (point-max)) - ;; (insert (concat "Annotation for bookmark '" bookmark "':\n\n")) - (insert annotation) - (goto-char (point-min)) - (pop-to-buffer old-buf)))))) + (when (and annotation (not (string-equal annotation ""))) + (save-excursion + (let ((old-buf (current-buffer))) + (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t) + (delete-region (point-min) (point-max)) + ;; (insert (concat "Annotation for bookmark '" bookmark "':\n\n")) + (insert annotation) + (goto-char (point-min)) + (switch-to-buffer-other-window old-buf)))))) (defun bookmark-show-all-annotations () @@ -2173,7 +2197,7 @@ strings returned are not." ;; Load Hook (defvar bookmark-load-hook nil - "Hook run at the end of loading bookmark.") + "Hook run at the end of loading library `bookmark.el'.") ;; Exit Hook, called from kill-emacs-hook (defvar bookmark-exit-hook nil @@ -2202,5 +2226,4 @@ This also runs `bookmark-exit-hook'." (provide 'bookmark) -;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6 ;;; bookmark.el ends here |