diff options
| author | Karl Fogel | 2015-11-08 14:16:43 -0500 |
|---|---|---|
| committer | Karl Fogel | 2015-11-08 14:18:53 -0500 |
| commit | 3812e17978547bd659b92da817f9ddd557bd511c (patch) | |
| tree | 2efcc02f6276fb01de8fcbf027a3ea544541ca48 /lisp | |
| parent | 2ce0c0674eba9179ba57c537e387bc3f7b0e5b63 (diff) | |
| download | emacs-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.el | 115 |
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. |
| 760 | If name is nil, then prompt the user. | 762 | |
| 761 | 763 | Begin the interactive prompt with PROMPT, followed by a space, a | |
| 762 | With a prefix arg (non-nil NO-OVERWRITE), do not overwrite any | 764 | generated default name in parentheses, a colon and a space. |
| 763 | existing bookmark that has the same name as NAME, but instead push the | 765 | |
| 764 | new bookmark onto the bookmark alist. The most recently set bookmark | 766 | If OVERWRITE-OR-PUSH is nil, then error if there is already a |
| 765 | with name NAME is thus the one in effect at any given time, but the | 767 | bookmark named NAME; if `overwrite', then replace any existing |
| 766 | others are still there, should the user decide to delete the most | 768 | bookmark if there is one; if `push' then push the new bookmark |
| 767 | recent one. | 769 | onto the bookmark alist. The `push' behavior means that among |
| 768 | 770 | bookmarks named NAME, this most recently set one becomes the one in | |
| 769 | To yank words from the text of the buffer and use them as part of the | 771 | effect, but the others are still there, in order, if the topmost one |
| 770 | bookmark name, type C-w while setting a bookmark. Successive C-w's | 772 | is ever deleted." |
| 771 | yank successive words. | ||
| 772 | |||
| 773 | Typing C-u inserts (at the bookmark name prompt) the name of the last | ||
| 774 | bookmark used in the document where the new bookmark is being set; | ||
| 775 | this helps you use a single bookmark name to track progress through a | ||
| 776 | large document. If there is no prior bookmark for this document, then | ||
| 777 | C-u inserts an appropriate name based on the buffer or file. | ||
| 778 | |||
| 779 | Use \\[bookmark-delete] to remove bookmarks (you give it a name and | ||
| 780 | it removes only the first instance of a bookmark with that name from | ||
| 781 | the 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. | ||
| 829 | If NAME is nil, then prompt the user. | ||
| 830 | |||
| 831 | With a prefix arg (non-nil NO-OVERWRITE), do not overwrite any | ||
| 832 | existing bookmark that has the same name as NAME, but instead push the | ||
| 833 | new bookmark onto the bookmark alist. The most recently set bookmark | ||
| 834 | with name NAME is thus the one in effect at any given time, but the | ||
| 835 | others are still there, should the user decide to delete the most | ||
| 836 | recent one. | ||
| 837 | |||
| 838 | To yank words from the text of the buffer and use them as part of the | ||
| 839 | bookmark name, type C-w while setting a bookmark. Successive C-w's | ||
| 840 | yank successive words. | ||
| 841 | |||
| 842 | Typing C-u inserts (at the bookmark name prompt) the name of the last | ||
| 843 | bookmark used in the document where the new bookmark is being set; | ||
| 844 | this helps you use a single bookmark name to track progress through a | ||
| 845 | large document. If there is no prior bookmark for this document, then | ||
| 846 | C-u inserts an appropriate name based on the buffer or file. | ||
| 847 | |||
| 848 | Use \\[bookmark-delete] to remove bookmarks (you give it a name and | ||
| 849 | it removes only the first instance of a bookmark with that name from | ||
| 850 | the 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. | ||
| 858 | If NAME is nil, then prompt the user. | ||
| 859 | |||
| 860 | If a bookmark named NAME already exists and prefix argument | ||
| 861 | PUSH-BOOKMARK is non-nil, then push the new bookmark onto the | ||
| 862 | bookmark alist. Pushing it means that among bookmarks named | ||
| 863 | NAME, this one becomes the one in effect, but the others are | ||
| 864 | still there, in order, and become effective again if the user | ||
| 865 | ever deletes the most recent one. | ||
| 866 | |||
| 867 | Otherwise, if a bookmark named NAME already exists but PUSH-BOOKMARK | ||
| 868 | is nil, raise an error. | ||
| 869 | |||
| 870 | To yank words from the text of the buffer and use them as part of the | ||
| 871 | bookmark name, type C-w while setting a bookmark. Successive C-w's | ||
| 872 | yank successive words. | ||
| 873 | |||
| 874 | Typing C-u inserts (at the bookmark name prompt) the name of the last | ||
| 875 | bookmark used in the document where the new bookmark is being set; | ||
| 876 | this helps you use a single bookmark name to track progress through a | ||
| 877 | large document. If there is no prior bookmark for this document, then | ||
| 878 | C-u inserts an appropriate name based on the buffer or file. | ||
| 879 | |||
| 880 | Use \\[bookmark-delete] to remove bookmarks (you give it a name and | ||
| 881 | it removes only the first instance of a bookmark with that name from | ||
| 882 | the 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. |
| 826 | If optional arg NEWLINE-TOO is non-nil, delete the newline too. | 889 | If optional arg NEWLINE-TOO is non-nil, delete the newline too. |