1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

For the sake of consistency, always prompt

Now that `thing-at-point-things' is more comprehensive, it seems
unlikely unlikely that the list of things would ever be only a single
item; but if that did happen it would probably be quite jarring to not
see the usual prompt.
This commit is contained in:
Phil Sainty 2025-03-29 23:47:38 +13:00
parent 9587301562
commit 0c8f4e141c

View file

@ -909,9 +909,8 @@ validity."
(defun read-thing-at-point-thing (&optional prompt all narrow) (defun read-thing-at-point-thing (&optional prompt all narrow)
"Return a \"thing\" suitable for `thing-at-point'. "Return a \"thing\" suitable for `thing-at-point'.
Test the known \"things\" to see which are valid. If only one thing is Test the known \"things\" to see which are valid, and PROMPT the user
valid at point, return its symbol. If more than one thing is valid, to choose from the valid options.
PROMPT the user to choose from the valid options.
If ALL is non-nil, choose from all known \"things\" without testing If ALL is non-nil, choose from all known \"things\" without testing
their validity. their validity.
@ -922,19 +921,20 @@ context. (This is currently only `buffer', which means `point-min' to
(let ((things (thing-at-point-things all))) (let ((things (thing-at-point-things all)))
(when narrow (when narrow
(setq things (delq 'buffer things))) (setq things (delq 'buffer things)))
(cond ((null things) (user-error "No thing at point")) (when (null things)
((eql 1 (length things)) (car things)) (user-error "No thing at point"))
(t (let ((default (cond ((and (use-region-p) (memq 'region things)) ;; Try to offer a useful default.
'region) (let ((default (cond ((and (use-region-p) (memq 'region things))
((memq 'sexp things) 'region)
'sexp) ((memq 'sexp things)
(t 'sexp)
(car things))))) (t
(intern (completing-read (car things)))))
(format (or prompt "Thing (default %s): ") (intern (completing-read
default) (format (or prompt "Thing (default %s): ")
things nil :require-match nil nil default)
(symbol-name default)))))))) things nil :require-match nil nil
(symbol-name default))))))
;;;###autoload ;;;###autoload
(defun narrow-to-thing-at-point (thing) (defun narrow-to-thing-at-point (thing)