aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sainty2025-03-29 23:47:38 +1300
committerPhil Sainty2025-03-29 23:47:38 +1300
commit0c8f4e141c86e34353b9f691cad242c0cd038987 (patch)
tree5676a953a7e3541acd30be50403ad1631b5a0416
parent95873015624e91bfba709baeeca078cd4ccd2169 (diff)
downloademacs-scratch/narrow-to-thing-at-point.tar.gz
emacs-scratch/narrow-to-thing-at-point.zip
For the sake of consistency, always promptscratch/narrow-to-thing-at-point
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.
-rw-r--r--lisp/thingatpt.el32
1 files changed, 16 insertions, 16 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 11ec9f69ba3..3efe1b83c6f 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -909,9 +909,8 @@ validity."
909(defun read-thing-at-point-thing (&optional prompt all narrow) 909(defun read-thing-at-point-thing (&optional prompt all narrow)
910 "Return a \"thing\" suitable for `thing-at-point'. 910 "Return a \"thing\" suitable for `thing-at-point'.
911 911
912Test the known \"things\" to see which are valid. If only one thing is 912Test the known \"things\" to see which are valid, and PROMPT the user
913valid at point, return its symbol. If more than one thing is valid, 913to choose from the valid options.
914PROMPT the user to choose from the valid options.
915 914
916If ALL is non-nil, choose from all known \"things\" without testing 915If ALL is non-nil, choose from all known \"things\" without testing
917their validity. 916their validity.
@@ -922,19 +921,20 @@ context. (This is currently only `buffer', which means `point-min' to
922 (let ((things (thing-at-point-things all))) 921 (let ((things (thing-at-point-things all)))
923 (when narrow 922 (when narrow
924 (setq things (delq 'buffer things))) 923 (setq things (delq 'buffer things)))
925 (cond ((null things) (user-error "No thing at point")) 924 (when (null things)
926 ((eql 1 (length things)) (car things)) 925 (user-error "No thing at point"))
927 (t (let ((default (cond ((and (use-region-p) (memq 'region things)) 926 ;; Try to offer a useful default.
928 'region) 927 (let ((default (cond ((and (use-region-p) (memq 'region things))
929 ((memq 'sexp things) 928 'region)
930 'sexp) 929 ((memq 'sexp things)
931 (t 930 'sexp)
932 (car things))))) 931 (t
933 (intern (completing-read 932 (car things)))))
934 (format (or prompt "Thing (default %s): ") 933 (intern (completing-read
935 default) 934 (format (or prompt "Thing (default %s): ")
936 things nil :require-match nil nil 935 default)
937 (symbol-name default)))))))) 936 things nil :require-match nil nil
937 (symbol-name default))))))
938 938
939;;;###autoload 939;;;###autoload
940(defun narrow-to-thing-at-point (thing) 940(defun narrow-to-thing-at-point (thing)