diff options
author | Eric Abrahamsen <eric@ericabrahamsen.net> | 2020-10-08 22:58:19 -0700 |
---|---|---|
committer | Eric Abrahamsen <eric@ericabrahamsen.net> | 2020-10-08 22:58:19 -0700 |
commit | a40b1be0618ed6cf130ff564db0b8a42249e445f (patch) | |
tree | d7494395422dd727862f0902a19957d0c2b0cbe5 | |
parent | 3d333b146a2f5af1e1cb5c41c79877c6fe47b89f (diff) | |
download | emacs-scratch/gnus-search.tar.gz |
Fix gnus-search-query-expand-keyscratch/gnus-search
* lisp/gnus/gnus-search.el (gnus-search-query-expand-key): Use the
proper built-in functions, rather than trying to replicate string
completion ourself.
-rw-r--r-- | lisp/gnus/gnus-search.el | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el index bad2b909c36..1db13a6ca7c 100644 --- a/lisp/gnus/gnus-search.el +++ b/lisp/gnus/gnus-search.el @@ -692,41 +692,18 @@ chunk of query syntax." addresses))))) (defun gnus-search-query-expand-key (key) - "Attempt to expand KEY to a full keyword." - (let ((bits (split-string key "-")) - bit out-bits comp) - (if (try-completion (car bits) gnus-search-expandable-keys) - (progn - (while (setq bit (pop bits)) - (setq comp (try-completion bit gnus-search-expandable-keys)) - (if (stringp comp) - (if (and (string= bit comp) - (null (member comp gnus-search-expandable-keys))) - (signal 'gnus-search-parse-error - (list (format "Ambiguous keyword: %s" key))) - (push comp out-bits)) - (push bit out-bits))) - (mapconcat #'identity (reverse out-bits) "-")) - key))) - -;; (defun gnus-search-query-expand-key (key) -;; "Attempt to expand (possibly abbreviated) KEY to a full keyword. - -;; Can handle any non-ambiguous abbreviation, with hyphens as substring separator." -;; (let* ((bits (split-string key "-")) -;; (bit (pop bits)) -;; (comp (all-completions bit gnus-search-expandable-keys))) -;; ;; Make a cl-labels recursive function, that accepts a rebuilt key and -;; ;; results of `all-completions' back in as a COLLECTION argument. -;; (if (= 1 (length comp)) -;; (setq key (car comp)) -;; (when (setq comp (try-completion bit gnus-search-expandable-keys)) -;; (if (and (string= bit comp) -;; (null (member comp gnus-search-expandable-keys))) -;; (error "Ambiguous keyword: %s" key))) -;; (unless (eq t (try-completion key gnus-search-expandable-keys)))) -;; key)) - + (cond ((test-completion key gnus-search-expandable-keys) + ;; We're done! + key) + ;; There is more than one possible completion. + ((consp (cdr (completion-all-completions + key gnus-search-expandable-keys #'stringp))) + (signal 'gnus-search-parse-error + (list (format "Ambiguous keyword: %s" key)))) + ;; Return KEY, either completed or untouched. + ((car-safe (completion-try-completion + key gnus-search-expandable-keys + #'stringp 0))))) (defun gnus-search-query-return-string (&optional delimited trim) "Return a string from the current buffer. |