aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKarl Fogel2015-11-08 14:16:43 -0500
committerKarl Fogel2015-11-08 14:18:53 -0500
commit3812e17978547bd659b92da817f9ddd557bd511c (patch)
tree2efcc02f6276fb01de8fcbf027a3ea544541ca48 /lisp
parent2ce0c0674eba9179ba57c537e387bc3f7b0e5b63 (diff)
downloademacs-3812e17978547bd659b92da817f9ddd557bd511c.tar.gz
emacs-3812e17978547bd659b92da817f9ddd557bd511c.zip
Offer non-overwrite bookmark setter (Bug#15746)
* lisp/bookmark.el (bookmark-set-internal): New helper function to do what `bookmark-set' used to do, but with more choices for overwrite vs push, and with minor changes to the interactive prompt format. (bookmark-set): Rewrite as wrapper around above. If overwriting, inform the user of that in the prompt. (bookmark-set-no-overwrite): New function, also done as wrapper. Bind to "M" in `ctl-x-r-map' autoloads. (bookmark-map): Similarly bind "M" here.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/bookmark.el115
1 files changed, 89 insertions, 26 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index e9310259e7e..e3b1dc4ebd3 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -196,6 +196,7 @@ A non-nil value may result in truncated bookmark names."
196 196
197;;;###autoload (define-key ctl-x-r-map "b" 'bookmark-jump) 197;;;###autoload (define-key ctl-x-r-map "b" 'bookmark-jump)
198;;;###autoload (define-key ctl-x-r-map "m" 'bookmark-set) 198;;;###autoload (define-key ctl-x-r-map "m" 'bookmark-set)
199;;;###autoload (define-key ctl-x-r-map "M" 'bookmark-set-no-overwrite)
199;;;###autoload (define-key ctl-x-r-map "l" 'bookmark-bmenu-list) 200;;;###autoload (define-key ctl-x-r-map "l" 'bookmark-bmenu-list)
200 201
201;;;###autoload 202;;;###autoload
@@ -204,6 +205,7 @@ A non-nil value may result in truncated bookmark names."
204 ;; Read the help on all of these functions for details... 205 ;; Read the help on all of these functions for details...
205 (define-key map "x" 'bookmark-set) 206 (define-key map "x" 'bookmark-set)
206 (define-key map "m" 'bookmark-set) ;"m"ark 207 (define-key map "m" 'bookmark-set) ;"m"ark
208 (define-key map "M" 'bookmark-set-no-overwrite) ;"M"aybe mark
207 (define-key map "j" 'bookmark-jump) 209 (define-key map "j" 'bookmark-jump)
208 (define-key map "g" 'bookmark-jump) ;"g"o 210 (define-key map "g" 'bookmark-jump) ;"g"o
209 (define-key map "o" 'bookmark-jump-other-window) 211 (define-key map "o" 'bookmark-jump-other-window)
@@ -755,30 +757,19 @@ This expects to be called from `point-min' in a bookmark file."
755 map)) 757 map))
756 758
757;;;###autoload 759;;;###autoload
758(defun bookmark-set (&optional name no-overwrite) 760(defun bookmark-set-internal (prompt name overwrite-or-push)
759 "Set a bookmark named NAME at the current location. 761 "Interactively set a bookmark named NAME at the current location.
760If name is nil, then prompt the user. 762
761 763Begin the interactive prompt with PROMPT, followed by a space, a
762With a prefix arg (non-nil NO-OVERWRITE), do not overwrite any 764generated default name in parentheses, a colon and a space.
763existing bookmark that has the same name as NAME, but instead push the 765
764new bookmark onto the bookmark alist. The most recently set bookmark 766If OVERWRITE-OR-PUSH is nil, then error if there is already a
765with name NAME is thus the one in effect at any given time, but the 767bookmark named NAME; if `overwrite', then replace any existing
766others are still there, should the user decide to delete the most 768bookmark if there is one; if `push' then push the new bookmark
767recent one. 769onto the bookmark alist. The `push' behavior means that among
768 770bookmarks named NAME, this most recently set one becomes the one in
769To yank words from the text of the buffer and use them as part of the 771effect, but the others are still there, in order, if the topmost one
770bookmark name, type C-w while setting a bookmark. Successive C-w's 772is ever deleted."
771yank successive words.
772
773Typing C-u inserts (at the bookmark name prompt) the name of the last
774bookmark used in the document where the new bookmark is being set;
775this helps you use a single bookmark name to track progress through a
776large document. If there is no prior bookmark for this document, then
777C-u inserts an appropriate name based on the buffer or file.
778
779Use \\[bookmark-delete] to remove bookmarks (you give it a name and
780it removes only the first instance of a bookmark with that name from
781the list of bookmarks.)"
782 (interactive (list nil current-prefix-arg)) 773 (interactive (list nil current-prefix-arg))
783 (unwind-protect 774 (unwind-protect
784 (let* ((record (bookmark-make-record)) 775 (let* ((record (bookmark-make-record))
@@ -807,12 +798,24 @@ the list of bookmarks.)"
807 (let ((str 798 (let ((str
808 (or name 799 (or name
809 (read-from-minibuffer 800 (read-from-minibuffer
810 (format "Set bookmark (%s): " default) 801 (format "%s (default: \"%s\"): " prompt default)
811 nil 802 nil
812 bookmark-minibuffer-read-name-map 803 bookmark-minibuffer-read-name-map
813 nil nil defaults)))) 804 nil nil defaults))))
814 (and (string-equal str "") (setq str default)) 805 (and (string-equal str "") (setq str default))
815 (bookmark-store str (cdr record) no-overwrite) 806
807 (cond
808 ((eq overwrite-or-push nil)
809 (if (bookmark-get-bookmark str t)
810 (error "A bookmark named \"%s\" already exists." str)
811 (bookmark-store str (cdr record) nil)))
812 ((eq overwrite-or-push 'overwrite)
813 (bookmark-store str (cdr record) nil))
814 ((eq overwrite-or-push 'push)
815 (bookmark-store str (cdr record) t))
816 (t
817 (error "Unrecognized value for `overwrite-or-push': %S"
818 overwrite-or-push)))
816 819
817 ;; Ask for an annotation buffer for this bookmark 820 ;; Ask for an annotation buffer for this bookmark
818 (when bookmark-use-annotations 821 (when bookmark-use-annotations
@@ -821,6 +824,66 @@ the list of bookmarks.)"
821 (setq bookmark-current-buffer nil))) 824 (setq bookmark-current-buffer nil)))
822 825
823 826
827(defun bookmark-set (&optional name no-overwrite)
828 "Set a bookmark named NAME at the current location.
829If NAME is nil, then prompt the user.
830
831With a prefix arg (non-nil NO-OVERWRITE), do not overwrite any
832existing bookmark that has the same name as NAME, but instead push the
833new bookmark onto the bookmark alist. The most recently set bookmark
834with name NAME is thus the one in effect at any given time, but the
835others are still there, should the user decide to delete the most
836recent one.
837
838To yank words from the text of the buffer and use them as part of the
839bookmark name, type C-w while setting a bookmark. Successive C-w's
840yank successive words.
841
842Typing C-u inserts (at the bookmark name prompt) the name of the last
843bookmark used in the document where the new bookmark is being set;
844this helps you use a single bookmark name to track progress through a
845large document. If there is no prior bookmark for this document, then
846C-u inserts an appropriate name based on the buffer or file.
847
848Use \\[bookmark-delete] to remove bookmarks (you give it a name and
849it removes only the first instance of a bookmark with that name from
850the list of bookmarks.)"
851 (interactive (list nil current-prefix-arg))
852 (let ((prompt
853 (if no-overwrite "Set bookmark" "Set bookmark unconditionally")))
854 (bookmark-set-internal prompt name (if no-overwrite 'push 'overwrite))))
855
856(defun bookmark-set-no-overwrite (&optional name push-bookmark)
857 "Set a bookmark named NAME at the current location.
858If NAME is nil, then prompt the user.
859
860If a bookmark named NAME already exists and prefix argument
861PUSH-BOOKMARK is non-nil, then push the new bookmark onto the
862bookmark alist. Pushing it means that among bookmarks named
863NAME, this one becomes the one in effect, but the others are
864still there, in order, and become effective again if the user
865ever deletes the most recent one.
866
867Otherwise, if a bookmark named NAME already exists but PUSH-BOOKMARK
868is nil, raise an error.
869
870To yank words from the text of the buffer and use them as part of the
871bookmark name, type C-w while setting a bookmark. Successive C-w's
872yank successive words.
873
874Typing C-u inserts (at the bookmark name prompt) the name of the last
875bookmark used in the document where the new bookmark is being set;
876this helps you use a single bookmark name to track progress through a
877large document. If there is no prior bookmark for this document, then
878C-u inserts an appropriate name based on the buffer or file.
879
880Use \\[bookmark-delete] to remove bookmarks (you give it a name and
881it removes only the first instance of a bookmark with that name from
882the list of bookmarks.)"
883 (interactive (list nil current-prefix-arg))
884 (bookmark-set-internal "Set bookmark" name (if push-bookmark 'push nil)))
885
886
824(defun bookmark-kill-line (&optional newline-too) 887(defun bookmark-kill-line (&optional newline-too)
825 "Kill from point to end of line. 888 "Kill from point to end of line.
826If optional arg NEWLINE-TOO is non-nil, delete the newline too. 889If optional arg NEWLINE-TOO is non-nil, delete the newline too.