From: Eshel Yaron Date: Wed, 19 Jun 2024 11:07:09 +0000 (+0200) Subject: Simplify bookmark name reading and add minibuffer action X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e8c2cdb336e19d6568b06f1ab5ecac40c3045585;p=emacs.git Simplify bookmark name reading and add minibuffer action --- diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 062ef1146be..ccf4d247287 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -331,16 +331,7 @@ through a file easier.") (defvar bookmark-current-buffer nil - "The buffer in which a bookmark is currently being set or renamed. -Functions that insert strings into the minibuffer use this to know -the source buffer for that information; see `bookmark-yank-word' -for example.") - - -(defvar bookmark-yank-point 0 - "The next point from which to pull source text for `bookmark-yank-word'. -This point is in `bookmark-current-buffer'.") - + "The buffer in which a bookmark is currently being set or renamed.") (defvar bookmark-quit-flag nil "Non-nil means `bookmark-bmenu-search' quits immediately.") @@ -974,20 +965,15 @@ CODING is the symbol of the coding-system in which the file is encoded." (define-obsolete-function-alias 'bookmark-maybe-message 'message "27.1") (defvar-keymap bookmark-minibuffer-read-name-map - :parent minibuffer-local-map - "C-w" #'bookmark-yank-word) + :doc "This variable is obsolete and no longer used.") -(defun bookmark-set-internal (prompt name overwrite-or-push) +(make-obsolete-variable 'bookmark-minibuffer-read-name-map + 'minibuffer-local-map "30.1") + +(defun bookmark-set-internal (name overwrite-or-push) "Set a bookmark using specified NAME or prompting with PROMPT. The bookmark is set at the current location. -If NAME is non-nil, use it as the name of the new bookmark. In -this case, the value of PROMPT is ignored. - -Otherwise, prompt the user for the bookmark name. Begin the -interactive prompt with PROMPT, followed by a space, a generated -default name in parentheses, a colon and a space. - OVERWRITE-OR-PUSH controls what happens if there is already a bookmark with the same name: nil means signal an error; `overwrite' means replace any existing bookmark; `push' means @@ -995,65 +981,35 @@ push the new bookmark onto the bookmark alist. The `push' behavior means that among bookmarks with the same name, this most recently set one becomes the one in effect, but the others are still there, in order, if the topmost one is ever deleted." - (unwind-protect - (let* ((record (bookmark-make-record)) - ;; `defaults' is a transient element of the - ;; extensible format described above in the section - ;; `File format stuff'. Bookmark record functions - ;; can use it to specify a list of default values - ;; accessible via M-n while reading a bookmark name. - (defaults (bookmark-prop-get record 'defaults)) - (default (if (consp defaults) (car defaults) defaults))) - - (if defaults - ;; Don't store default values in the record. - (setq record (assq-delete-all 'defaults record)) - ;; When no defaults in the record, use its first element. - (setq defaults (car record) default defaults)) - - (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-prompt prompt default) - nil - bookmark-minibuffer-read-name-map - nil nil defaults)))) - (and (string-equal str "") (setq str default)) - - (cond - ((eq overwrite-or-push nil) - (if (bookmark-get-bookmark str t) - (error "A bookmark named \"%s\" already exists" str) - (bookmark-store str (cdr record) nil))) - ((eq overwrite-or-push 'overwrite) - (bookmark-store str (cdr record) nil)) - ((eq overwrite-or-push 'push) - (bookmark-store str (cdr record) t)) - (t - (error "Unrecognized value for `overwrite-or-push': %S" - overwrite-or-push))) - - ;; Ask for an annotation buffer for this bookmark - (when bookmark-use-annotations - (bookmark-edit-annotation str)) - (when bookmark-fringe-mark - (bookmark--set-fringe-mark)))) - (setq bookmark-yank-point nil) - (setq bookmark-current-buffer nil))) - + (with-current-buffer (or bookmark-current-buffer (current-buffer)) + (let* ((record (cdr (assq-delete-all 'defaults (bookmark-make-record))))) + (bookmark-maybe-load-default-file) + (cond + ((eq overwrite-or-push nil) + (if (bookmark-get-bookmark name t) + (error "A bookmark named \"%s\" already exists" name) + (bookmark-store name record nil))) + ((eq overwrite-or-push 'overwrite) + (bookmark-store name record nil)) + ((eq overwrite-or-push 'push) + (bookmark-store name record t)) + (t + (error "Unrecognized value for `overwrite-or-push': %S" + overwrite-or-push)))))) + +(defun bookmark-read-bookmark-name (prompt) + (let* ((buffer (current-buffer)) + (record (bookmark-make-record)) + (defaults (or (bookmark-prop-get record 'defaults) + (car record)))) + (minibuffer-with-setup-hook + (lambda () + (setq-local bookmark-current-buffer buffer)) + (read-string (format-prompt prompt defaults) nil nil defaults)))) ;;;###autoload -(defun bookmark-set (&optional name no-overwrite) +(defun bookmark-set (name &optional no-overwrite) "Set a bookmark named NAME at the current location. -If NAME is nil, then prompt the user. With a prefix arg (non-nil NO-OVERWRITE), do not overwrite any existing bookmark that has the same name as NAME, but instead push the @@ -1062,30 +1018,19 @@ with name NAME is thus the one in effect at any given time, but the others are still there, should the user decide to delete the most recent one. -To yank words from the text of the buffer and use them as part of the -bookmark name, type \\\ -\\[bookmark-yank-word] while setting a bookmark. Successive \ -\\[bookmark-yank-word]'s -yank successive words. - -Typing \\[universal-argument] inserts (at the bookmark name prompt) the name of the last -bookmark used in the document where the new bookmark is being set; -this helps you use a single bookmark name to track progress through a -large document. If there is no prior bookmark for this document, then -\\[universal-argument] inserts an appropriate name based on the buffer or file. - 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 ((prompt - (if no-overwrite "Add bookmark named" "Set bookmark named"))) - (bookmark-set-internal prompt name (if no-overwrite 'push 'overwrite)))) + (interactive (list (bookmark-read-bookmark-name + (if current-prefix-arg "Add bookmark named" "Set bookmark named")) + current-prefix-arg)) + (bookmark-set-internal name (if no-overwrite 'push 'overwrite))) + +(put 'bookmark-set 'minibuffer-action "set") ;;;###autoload -(defun bookmark-set-no-overwrite (&optional name push-bookmark) +(defun bookmark-set-no-overwrite (name &optional push-bookmark) "Set a bookmark named NAME at the current location. -If NAME is nil, then prompt the user. If a bookmark named NAME already exists and prefix argument PUSH-BOOKMARK is non-nil, then push the new bookmark onto the @@ -1097,24 +1042,13 @@ ever deletes the most recent one. Otherwise, if a bookmark named NAME already exists but PUSH-BOOKMARK is nil, raise an error. -To yank words from the text of the buffer and use them as part of the -bookmark name, type \\\ -\\[bookmark-yank-word] while setting a bookmark. Successive \ -\\[bookmark-yank-word]'s -yank successive words. - -Typing \\[universal-argument] inserts (at the bookmark name prompt) the name of the last -bookmark used in the document where the new bookmark is being set; -this helps you use a single bookmark name to track progress through a -large document. If there is no prior bookmark for this document, then -\\[universal-argument] inserts an appropriate name based on the buffer or file. - 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)) - (bookmark-set-internal "Set bookmark" name (if push-bookmark 'push nil))) + (interactive (list (bookmark-read-bookmark-name "Set bookmark") current-prefix-arg)) + (bookmark-set-internal name (if push-bookmark 'push nil))) +(put 'bookmark-set-no-overwrite 'minibuffer-action 'bookmark-set) (defun bookmark-kill-line (&optional newline-too) "Kill from point to end of line. @@ -1251,20 +1185,6 @@ If the buffer is associated with a file or directory, use that name." (buffer-name (current-buffer))))) -(defun bookmark-yank-word () - "Get the next word from buffer `bookmark-current-buffer' and append -it to the name of the bookmark currently being set, advancing -`bookmark-yank-point' by one word." - (interactive) - (let ((string (with-current-buffer bookmark-current-buffer - (goto-char bookmark-yank-point) - (buffer-substring-no-properties - (point) - (progn - (forward-word 1) - (setq bookmark-yank-point (point))))))) - (insert string))) - (defun bookmark-buffer-file-name () "Return the current buffer's file in a way useful for bookmarks." ;; Abbreviate the path, both so it's shorter and so it's more @@ -1557,42 +1477,22 @@ Optional second argument is obsolete and ignored." "-- Unknown location --")) ;;;###autoload -(defun bookmark-rename (old-name &optional new-name) +(defun bookmark-rename (old-name new-name) "Change the name of OLD-NAME bookmark to NEW-NAME name. If called from keyboard, prompt for OLD-NAME and NEW-NAME. -If called from menubar, select OLD-NAME from a menu and prompt for NEW-NAME. - -If called from Lisp, prompt for NEW-NAME if only OLD-NAME was passed -as an argument. If called with two strings, then no prompting is done. -You must pass at least OLD-NAME when calling from Lisp. - -While you are entering the new name, consecutive \ -\\\\[bookmark-yank-word]'s insert -consecutive words from the text of the buffer into the new bookmark -name." - (interactive (list (bookmark-completing-read "Old bookmark name"))) +If called from menubar, select OLD-NAME from a menu and prompt for NEW-NAME." + (interactive (let ((old (bookmark-completing-read "Old bookmark name"))) + (list old (bookmark-read-bookmark-name (format "Rename \"%s\" to" old))))) (bookmark-maybe-load-default-file) - (setq bookmark-yank-point (point)) - (setq bookmark-current-buffer (current-buffer)) - (let ((final-new-name - (or new-name ; use second arg, if non-nil - (read-from-minibuffer - (format-prompt "Rename \"%s\" to" nil old-name) - nil - (define-keymap - :parent minibuffer-local-map - "C-w" #'bookmark-yank-word) - nil - 'bookmark-history)))) - (bookmark-set-name old-name final-new-name) - (bookmark-update-last-modified final-new-name) - (setq bookmark-current-bookmark final-new-name) - (bookmark-bmenu-surreptitiously-rebuild-list) - (setq bookmark-alist-modification-count - (1+ bookmark-alist-modification-count)) - (if (bookmark-time-to-save-p) - (bookmark-save)))) + (bookmark-set-name old-name new-name) + (bookmark-update-last-modified new-name) + (setq bookmark-current-bookmark new-name) + (bookmark-bmenu-surreptitiously-rebuild-list) + (setq bookmark-alist-modification-count + (1+ bookmark-alist-modification-count)) + (if (bookmark-time-to-save-p) + (bookmark-save))) ;;;###autoload @@ -2525,6 +2425,7 @@ confirmation first." (interactive nil bookmark-bmenu-mode) (let ((bmrk (bookmark-bmenu-bookmark)) (thispoint (point))) + ;; FIXME: Second arg of `bookmark-rename'. (bookmark-rename bmrk) (goto-char thispoint))) diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el index a9caa83b15c..c7730e5ef67 100644 --- a/lisp/gnus/gnus-sum.el +++ b/lisp/gnus/gnus-sum.el @@ -13172,8 +13172,6 @@ If ALL is a number, fetch this number of articles." (declare-function bookmark-prop-get "bookmark" (bookmark prop)) (declare-function bookmark-default-handler "bookmark" (bmk)) (declare-function bookmark-get-bookmark-record "bookmark" (bmk)) -(defvar bookmark-yank-point) -(defvar bookmark-current-buffer) (defun gnus-summary-bookmark-make-record () "Make a bookmark entry for a Gnus summary buffer." @@ -13182,8 +13180,6 @@ If ALL is a number, fetch this number of articles." (save-restriction ; FIXME is it necessary to widen? (widen) (setq pos (point))) ; Set position in gnus-article buffer. (setq buf "art") ; We are recording bookmark from article buffer. - (setq bookmark-yank-point (point)) - (setq bookmark-current-buffer (current-buffer)) (gnus-article-show-summary)) ; Go back in summary buffer. ;; We are now recording bookmark from summary buffer. (unless buf (setq buf "sum")) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index aaf6a8065a8..582236e6de4 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4276,7 +4276,7 @@ possible completions." (when-let ((desc (cdr (minibuffer-action)))) (propertize "<" 'help-echo (concat - "mouse-2, \\\\[minibuffer-apply]: " + "\\\\[minibuffer-apply]: " desc))) (when minibuffer-completion-table (propertize ">" 'help-echo "Completion available"))