aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2022-06-17 13:34:36 +0200
committerStefan Kangas2022-06-17 13:41:29 +0200
commitdc6157bef758cf5ba490219eebccaf33e14430d3 (patch)
tree70cfb095c40e5be9bbdb9f08ef202071a80705f1
parentabdc5887c1fb81ec7ce22d0645e4dfa10f9eee29 (diff)
downloademacs-dc6157bef758cf5ba490219eebccaf33e14430d3.tar.gz
emacs-dc6157bef758cf5ba490219eebccaf33e14430d3.zip
Cancel editing bookmark annotations with C-c C-k
* lisp/bookmark.el (bookmark-edit-annotation-cancel): New command. (bookmark-edit-annotation-mode): Document it. (bookmark-edit-annotation-mode-map): Bind it to 'C-c C-k'. (bookmark-default-annotation-text): Announce it when editing annotations. (bookmark-edit-annotation--maybe-display-list): New macro. (bookmark-send-edited-annotation): Use above new macro.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/bookmark.el55
2 files changed, 39 insertions, 20 deletions
diff --git a/etc/NEWS b/etc/NEWS
index dd7996b2775..3b9515c2d46 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1786,6 +1786,10 @@ This will display bookmark list from most recently set to least
1786recently set. 1786recently set.
1787 1787
1788--- 1788---
1789*** When editing a bookmark annotation, 'C-c C-k' will now cancel.
1790It is bound to the new command 'bookmark-edit-annotation-cancel'.
1791
1792---
1789*** New minor mode 'elide-head-mode'. 1793*** New minor mode 'elide-head-mode'.
1790Enabling this minor mode turns on hiding header material, like 1794Enabling this minor mode turns on hiding header material, like
1791'elide-head' does; disabling it shows the header. The commands 1795'elide-head' does; disabling it shows the header. The commands
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 4a8ffc0fa07..fdaea381abb 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1028,10 +1028,12 @@ annotations."
1028 (format-message 1028 (format-message
1029 "# All lines which start with a `#' will be deleted.\n") 1029 "# All lines which start with a `#' will be deleted.\n")
1030 (substitute-command-keys 1030 (substitute-command-keys
1031 "# Type \\[bookmark-send-edited-annotation] when done.\n#\n") 1031 (concat
1032 "# Type \\[bookmark-send-edited-annotation] when done. Type "
1033 "\\[bookmark-edit-annotation-cancel] to cancel.\n#\n"))
1032 "# Author: " (user-full-name) " <" (user-login-name) "@" 1034 "# Author: " (user-full-name) " <" (user-login-name) "@"
1033 (system-name) ">\n" 1035 (system-name) ">\n"
1034 "# Date: " (current-time-string) "\n")) 1036 "# Date: " (current-time-string) "\n"))
1035 1037
1036 1038
1037(defvar bookmark-edit-annotation-text-func 'bookmark-default-annotation-text 1039(defvar bookmark-edit-annotation-text-func 'bookmark-default-annotation-text
@@ -1041,7 +1043,8 @@ It takes one argument, the name of the bookmark, as a string.")
1041(defvar-keymap bookmark-edit-annotation-mode-map 1043(defvar-keymap bookmark-edit-annotation-mode-map
1042 :doc "Keymap for editing an annotation of a bookmark." 1044 :doc "Keymap for editing an annotation of a bookmark."
1043 :parent text-mode-map 1045 :parent text-mode-map
1044 "C-c C-c" #'bookmark-send-edited-annotation) 1046 "C-c C-c" #'bookmark-send-edited-annotation
1047 "C-c C-k" #'bookmark-edit-annotation-cancel)
1045 1048
1046(defun bookmark-insert-annotation (bookmark-name-or-record) 1049(defun bookmark-insert-annotation (bookmark-name-or-record)
1047 "Insert annotation for BOOKMARK-NAME-OR-RECORD at point." 1050 "Insert annotation for BOOKMARK-NAME-OR-RECORD at point."
@@ -1055,10 +1058,30 @@ It takes one argument, the name of the bookmark, as a string.")
1055(define-derived-mode bookmark-edit-annotation-mode 1058(define-derived-mode bookmark-edit-annotation-mode
1056 text-mode "Edit Bookmark Annotation" 1059 text-mode "Edit Bookmark Annotation"
1057 "Mode for editing the annotation of bookmarks. 1060 "Mode for editing the annotation of bookmarks.
1058When you have finished composing, type \\[bookmark-send-edited-annotation]. 1061\\<bookmark-edit-annotation-mode-map>\
1062When you have finished composing, type \\[bookmark-send-edited-annotation] \
1063or \\[bookmark-edit-annotation-cancel] to cancel.
1059 1064
1060\\{bookmark-edit-annotation-mode-map}") 1065\\{bookmark-edit-annotation-mode-map}")
1061 1066
1067(defmacro bookmark-edit-annotation--maybe-display-list (&rest body)
1068 "Display bookmark list after editing if appropriate."
1069 `(let ((from-bookmark-list bookmark--annotation-from-bookmark-list)
1070 (old-buffer (current-buffer)))
1071 ,@body
1072 (quit-window)
1073 (bookmark-bmenu-surreptitiously-rebuild-list)
1074 (when from-bookmark-list
1075 (pop-to-buffer (get-buffer bookmark-bmenu-buffer))
1076 (goto-char (point-min))
1077 (bookmark-bmenu-bookmark))
1078 (kill-buffer old-buffer)))
1079
1080(defun bookmark-edit-annotation-cancel ()
1081 "Cancel the current annotation edit."
1082 (interactive nil bookmark-edit-annotation-mode)
1083 (bookmark-edit-annotation--maybe-display-list
1084 (message "Canceled by user")))
1062 1085
1063(defun bookmark-send-edited-annotation () 1086(defun bookmark-send-edited-annotation ()
1064 "Use buffer contents as annotation for a bookmark. 1087 "Use buffer contents as annotation for a bookmark.
@@ -1072,22 +1095,14 @@ Lines beginning with `#' are ignored."
1072 (bookmark-kill-line t) 1095 (bookmark-kill-line t)
1073 (forward-line 1))) 1096 (forward-line 1)))
1074 ;; Take no chances with text properties. 1097 ;; Take no chances with text properties.
1075 (let ((annotation (buffer-substring-no-properties (point-min) (point-max))) 1098 (bookmark-edit-annotation--maybe-display-list
1076 (bookmark-name bookmark-annotation-name) 1099 (let ((annotation (buffer-substring-no-properties (point-min) (point-max)))
1077 (from-bookmark-list bookmark--annotation-from-bookmark-list) 1100 (bookmark-name bookmark-annotation-name))
1078 (old-buffer (current-buffer))) 1101 (bookmark-set-annotation bookmark-name annotation)
1079 (bookmark-set-annotation bookmark-name annotation) 1102 (bookmark-update-last-modified bookmark-name)
1080 (bookmark-update-last-modified bookmark-name) 1103 (setq bookmark-alist-modification-count
1081 (setq bookmark-alist-modification-count 1104 (1+ bookmark-alist-modification-count))
1082 (1+ bookmark-alist-modification-count)) 1105 (message "Annotation updated for \"%s\"" bookmark-name))))
1083 (message "Annotation updated for \"%s\"" bookmark-name)
1084 (quit-window)
1085 (bookmark-bmenu-surreptitiously-rebuild-list)
1086 (when from-bookmark-list
1087 (pop-to-buffer (get-buffer bookmark-bmenu-buffer))
1088 (goto-char (point-min))
1089 (bookmark-bmenu-bookmark))
1090 (kill-buffer old-buffer)))
1091 1106
1092 1107
1093(defun bookmark-edit-annotation (bookmark-name-or-record &optional from-bookmark-list) 1108(defun bookmark-edit-annotation (bookmark-name-or-record &optional from-bookmark-list)