From 850ef7ae3d0c6a0598cc07cfdef7386775239cf4 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 20 May 2020 14:09:47 +0200 Subject: [PATCH 01/21] Pass minibuffer completion table and predicate --- selectrum.el | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/selectrum.el b/selectrum.el index e7131fd5..dc41a580 100644 --- a/selectrum.el +++ b/selectrum.el @@ -1042,7 +1042,9 @@ Otherwise, just eval BODY." (prompt candidates &rest args &key default-candidate initial-input require-match history no-move-default-candidate - may-modify-candidates) + may-modify-candidates + minibuffer-completion-table + minibuffer-completion-predicate) "Prompt user with PROMPT to select one of CANDIDATES. Return the selected string. @@ -1082,7 +1084,12 @@ is very confusing. MAY-MODIFY-CANDIDATES, if non-nil, means that Selectrum is allowed to modify the CANDIDATES list destructively. Otherwise a -copy is made." +copy is made. + +For MINIBUFFER-COMPLETION-TABLE and +MINIBUFFER-COMPLETION-PREDICATE see `minibuffer-completion-table' +and `minibuffer-completion-predicate'. They are used for internal +purposes and compatibility to emacs completion API." (unless may-modify-candidates (setq candidates (copy-sequence candidates))) (selectrum--save-global-state @@ -1149,7 +1156,9 @@ HIST, DEF, and INHERIT-INPUT-METHOD, see `completing-read'." :default-candidate (or (car-safe def) def) :require-match (eq require-match t) :history hist - :may-modify-candidates t)) + :may-modify-candidates t + :minibuffer-completion-table collection + :minibuffer-completion-predicate predicate)) (defvar selectrum--old-completing-read-function nil "Previous value of `completing-read-function'.") @@ -1206,7 +1215,9 @@ INHERIT-INPUT-METHOD, see `completing-read-multiple'." :initial-input initial-input :history hist :default-candidate def - :may-modify-candidates t))) + :may-modify-candidates t + :minibuffer-completion-table table + :minibuffer-completion-predicate predicate))) (split-string res crm-separator t))) ;;;###autoload @@ -1255,7 +1266,10 @@ COLLECTION, and PREDICATE, see `completion-in-region'." (`0 (message "No match")) (`1 (setq result (car cands))) ( _ (setq result (selectrum-read - "Completion: " cands :may-modify-candidates t)))) + "Completion: " cands + :may-modify-candidates t + :minibuffer-completion-table collection + :minibuffer-completion-predicate predicate)))) (when result (delete-region start end) (insert (substring-no-properties result))) @@ -1310,7 +1324,9 @@ PREDICATE, see `read-buffer'." :require-match (eq require-match t) :history 'buffer-name-history :no-move-default-candidate t - :may-modify-candidates t))) + :may-modify-candidates t + :minibuffer-completion-table #'internal-complete-buffer + :minibuffer-completion-predicate predicate))) (defvar selectrum--old-read-buffer-function nil "Previous value of `read-buffer-function'.") @@ -1355,7 +1371,9 @@ For PROMPT, COLLECTION, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, :initial-input (or (car-safe initial-input) initial-input) :history hist :require-match (eq require-match t) - :may-modify-candidates t))) + :may-modify-candidates t + :minibuffer-completion-table collection + :minibuffer-completion-predicate predicate))) ;;;###autoload (defun selectrum-read-file-name From 34269b6baf7a930dc8a3c252b1d6ceeb0c39d8d3 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Sun, 24 May 2020 17:08:34 +0200 Subject: [PATCH 02/21] Fix checkdoc warning --- selectrum.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selectrum.el b/selectrum.el index dc41a580..09b3d9e6 100644 --- a/selectrum.el +++ b/selectrum.el @@ -1089,7 +1089,7 @@ copy is made. For MINIBUFFER-COMPLETION-TABLE and MINIBUFFER-COMPLETION-PREDICATE see `minibuffer-completion-table' and `minibuffer-completion-predicate'. They are used for internal -purposes and compatibility to emacs completion API." +purposes and compatibility to Emacs completion API." (unless may-modify-candidates (setq candidates (copy-sequence candidates))) (selectrum--save-global-state From 32806f91d822d9d84738c3cb38ea7e10f85aaa16 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 27 May 2020 22:35:52 +0200 Subject: [PATCH 03/21] Mention dynamic binding via keyword arguments --- selectrum.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selectrum.el b/selectrum.el index 91ef6a4c..bcbd39aa 100644 --- a/selectrum.el +++ b/selectrum.el @@ -1089,7 +1089,9 @@ copy is made. For MINIBUFFER-COMPLETION-TABLE and MINIBUFFER-COMPLETION-PREDICATE see `minibuffer-completion-table' and `minibuffer-completion-predicate'. They are used for internal -purposes and compatibility to Emacs completion API." +purposes and compatibility to Emacs completion API. By passing +theses as keyword arguments they will be dynamically bound as per +semantics of `cl-defun'." (unless may-modify-candidates (setq candidates (copy-sequence candidates))) (selectrum--save-global-state From 60d8cf591b2a4427f4e40be739e6d6b12a5ec7ea Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 27 May 2020 22:48:27 +0200 Subject: [PATCH 04/21] Add changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a5c900..b173fa4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,13 @@ The format is based on [Keep a Changelog]. Appearance can be configured using the faces `selectrum-completion-annotation`, `selectrum-completion-docsig`, and `completions-common-part` ([#86]). +* `selectrum-read` accepts two additional keyword arguments + `minibuffer-completion-table` and + `minibuffer-completion-predicate`. These can be used to pass the + `completing-read` collection and predicate so they are available for + internal handling of completion API features and for other external + commands or packages which make use of them. + ### Enhancements * `selectrum-read-file-name` which is used as From 58a31e6a0ad44789bb2c8d435ae63ebedc7232da Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 27 May 2020 23:14:54 +0200 Subject: [PATCH 05/21] Delay computation of completion table --- selectrum.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/selectrum.el b/selectrum.el index bcbd39aa..21c4a4ed 100644 --- a/selectrum.el +++ b/selectrum.el @@ -535,6 +535,16 @@ just rendering it to the screen and then checking." (run-with-idle-timer 0 nil #'selectrum--ensure-current-candidate-centered))))))) +(defun selectrum--maybe-init-candidates-from-table () + "Initialize `selectrum--preprocessed-candidates' if necessary." + (when (and (not selectrum--preprocessed-candidates) + minibuffer-completion-table) + (setq selectrum--preprocessed-candidates + (funcall selectrum-preprocess-candidates-function + (selectrum--normalize-collection + minibuffer-completion-table + minibuffer-completion-predicate))))) + (defun selectrum--minibuffer-post-command-hook () "Update minibuffer in response to user input." (goto-char (max (point) selectrum--start-of-input-marker)) @@ -550,6 +560,7 @@ just rendering it to the screen and then checking." (bound (marker-position selectrum--end-of-input-marker)) (keep-mark-active (not deactivate-mark))) (unless (equal input selectrum--previous-input-string) + (selectrum--maybe-init-candidates-from-table) (setq selectrum--previous-input-string input) ;; Reset the persistent input, so that it will be nil if ;; there's no special attention needed. @@ -1051,7 +1062,8 @@ Return the selected string. CANDIDATES is a list of strings or a function to dynamically generate them. If CANDIDATES is a function, then it receives one argument, the current user input, and returns the list of -strings. +strings. If CANDIDATES are nil the candidates will be computed +from MINIBUFFER-COMPLETION-TABLE. Instead of a list of strings, the function may alternatively return an alist with the following keys: @@ -1151,7 +1163,7 @@ For PROMPT, COLLECTION, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF, and INHERIT-INPUT-METHOD, see `completing-read'." (ignore initial-input inherit-input-method) (selectrum-read - prompt (selectrum--normalize-collection collection predicate) + prompt nil ;; Don't pass `initial-input'. We use it internally but it's ;; deprecated in `completing-read' and doesn't work well with the ;; Selectrum paradigm except in specific cases that we control. From 2535b8ac1c4223db3a578a35fd94f82be8b2227c Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 28 May 2020 21:04:04 +0200 Subject: [PATCH 06/21] Add new helper function to get current input --- selectrum.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/selectrum.el b/selectrum.el index 21c4a4ed..d5b1a92a 100644 --- a/selectrum.el +++ b/selectrum.el @@ -475,6 +475,12 @@ This is used to implement `selectrum-repeat'.") selectrum--start-of-input-marker selectrum--end-of-input-marker))) +(defun selectrum--current-input () + "Get current minibuffer input." + (buffer-substring + selectrum--start-of-input-marker + selectrum--end-of-input-marker)) + ;;;; Hook functions (defun selectrum--count-info () From 1472b45156c4226a3c1214c30157dc1017aa51ae Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 28 May 2020 21:04:31 +0200 Subject: [PATCH 07/21] Handle display-sort-function metadata for completion tables --- selectrum.el | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/selectrum.el b/selectrum.el index d5b1a92a..8c6bb511 100644 --- a/selectrum.el +++ b/selectrum.el @@ -541,15 +541,21 @@ just rendering it to the screen and then checking." (run-with-idle-timer 0 nil #'selectrum--ensure-current-candidate-centered))))))) -(defun selectrum--maybe-init-candidates-from-table () - "Initialize `selectrum--preprocessed-candidates' if necessary." - (when (and (not selectrum--preprocessed-candidates) +(defun selectrum--init-candidates-from-table () + "Initialize candidates from `minibuffer-completion-table'." + (when (and (not selectrum--preprocessed-candidates) minibuffer-completion-table) - (setq selectrum--preprocessed-candidates - (funcall selectrum-preprocess-candidates-function - (selectrum--normalize-collection - minibuffer-completion-table - minibuffer-completion-predicate))))) + (let ((sortf (completion-metadata-get + (completion-metadata + (selectrum--current-input) + minibuffer-completion-table + minibuffer-completion-predicate) + 'display-sort-function))) + (setq selectrum--preprocessed-candidates + (funcall (or sortf selectrum-preprocess-candidates-function) + (selectrum--normalize-collection + minibuffer-completion-table + minibuffer-completion-predicate)))))) (defun selectrum--minibuffer-post-command-hook () "Update minibuffer in response to user input." @@ -566,7 +572,7 @@ just rendering it to the screen and then checking." (bound (marker-position selectrum--end-of-input-marker)) (keep-mark-active (not deactivate-mark))) (unless (equal input selectrum--previous-input-string) - (selectrum--maybe-init-candidates-from-table) + (selectrum--init-candidates-from-table) (setq selectrum--previous-input-string input) ;; Reset the persistent input, so that it will be nil if ;; there's no special attention needed. From 709cb5c0c08463c31f58c3c93b9a82681bdf4571 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 28 May 2020 21:05:50 +0200 Subject: [PATCH 08/21] Fix indent --- selectrum.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selectrum.el b/selectrum.el index 8c6bb511..56811c63 100644 --- a/selectrum.el +++ b/selectrum.el @@ -543,7 +543,7 @@ just rendering it to the screen and then checking." (defun selectrum--init-candidates-from-table () "Initialize candidates from `minibuffer-completion-table'." - (when (and (not selectrum--preprocessed-candidates) + (when (and (not selectrum--preprocessed-candidates) minibuffer-completion-table) (let ((sortf (completion-metadata-get (completion-metadata From 98c6c73004a08ce47e7d809cec8c53865bdd7a0c Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 28 May 2020 21:58:19 +0200 Subject: [PATCH 09/21] Refactor annotation and docsig --- selectrum.el | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/selectrum.el b/selectrum.el index 56811c63..74543dac 100644 --- a/selectrum.el +++ b/selectrum.el @@ -357,6 +357,29 @@ If PREDICATE is non-nil, then it filters the collection as in (or (get-text-property 0 'selectrum-candidate-full candidate) candidate)) +(defun selectrum--get-annotation-suffix (string annotation-func) + "Get `selectrum-candidate-display-suffix' value for annotation. + +Used to display STRING according to ANNOTATION-FUNC from +metadata." + (when annotation-func + ;; Rule out situations where the annotation + ;; is nil. + (when-let ((annotation (funcall annotation-func string))) + (propertize + annotation + 'face 'selectrum-completion-annotation)))) + +(defun selectrum--get-margin-docsig (string docsig-func) + "Get `selectrum-candidate-display-right-margin' value for docsig. + +Used to display STRING according to DOCSIG-FUNC from metadata." + (when docsig-func + (when-let ((docsig (funcall docsig-func string))) + (propertize + (format "%s" docsig) + 'face 'selectrum-completion-docsig)))) + ;;;; Minibuffer state (defvar selectrum--start-of-input-marker nil @@ -1286,20 +1309,11 @@ COLLECTION, and PREDICATE, see `completion-in-region'." (propertize cand 'selectrum-candidate-display-suffix - (when annotation-func - ;; Rule out situations where the annotation - ;; is nil. - (when-let ((annotation - (funcall annotation-func cand))) - (propertize - annotation - 'face 'selectrum-completion-annotation))) + (selectrum--get-annotation-suffix + cand annotation-func) 'selectrum-candidate-display-right-margin - (when docsig-func - (when-let ((docsig (funcall docsig-func cand))) - (propertize - (format "%s" docsig) - 'face 'selectrum-completion-docsig))))) + (selectrum--get-margin-docsig + cand docsig-func))) cands)) (selectrum-should-sort-p selectrum-should-sort-p)) (when display-sort-func From 9f9fe1a107c6ee72bd5cca0ea4d215b70d52319f Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 28 May 2020 22:05:50 +0200 Subject: [PATCH 10/21] Handle annotation metadata --- selectrum.el | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/selectrum.el b/selectrum.el index 74543dac..144d1636 100644 --- a/selectrum.el +++ b/selectrum.el @@ -568,17 +568,28 @@ just rendering it to the screen and then checking." "Initialize candidates from `minibuffer-completion-table'." (when (and (not selectrum--preprocessed-candidates) minibuffer-completion-table) - (let ((sortf (completion-metadata-get - (completion-metadata + (let* ((metad (completion-metadata (selectrum--current-input) minibuffer-completion-table - minibuffer-completion-predicate) - 'display-sort-function))) + minibuffer-completion-predicate)) + (sortf (completion-metadata-get + metad + 'display-sort-function)) + (annotf (completion-metadata-get + metad + 'annotation-function)) + (strings (selectrum--normalize-collection + minibuffer-completion-table + minibuffer-completion-predicate)) + (cands ())) + (dolist (string strings) + (push (propertize string + 'selectrum-candidate-display-suffix + (selectrum--get-annotation-suffix string annotf)) + cands)) (setq selectrum--preprocessed-candidates (funcall (or sortf selectrum-preprocess-candidates-function) - (selectrum--normalize-collection - minibuffer-completion-table - minibuffer-completion-predicate)))))) + (nreverse cands)))))) (defun selectrum--minibuffer-post-command-hook () "Update minibuffer in response to user input." From c6cdae8b0a48ba9fee979da07118213dc5d872c8 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 28 May 2020 22:20:54 +0200 Subject: [PATCH 11/21] Refactor --- selectrum.el | 116 +++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/selectrum.el b/selectrum.el index 144d1636..a60780f9 100644 --- a/selectrum.el +++ b/selectrum.el @@ -359,26 +359,22 @@ If PREDICATE is non-nil, then it filters the collection as in (defun selectrum--get-annotation-suffix (string annotation-func) "Get `selectrum-candidate-display-suffix' value for annotation. - Used to display STRING according to ANNOTATION-FUNC from metadata." - (when annotation-func - ;; Rule out situations where the annotation - ;; is nil. - (when-let ((annotation (funcall annotation-func string))) - (propertize - annotation - 'face 'selectrum-completion-annotation)))) + ;; Rule out situations where the annotation + ;; is nil. + (when-let ((annotation (funcall annotation-func string))) + (propertize + annotation + 'face 'selectrum-completion-annotation))) (defun selectrum--get-margin-docsig (string docsig-func) "Get `selectrum-candidate-display-right-margin' value for docsig. - Used to display STRING according to DOCSIG-FUNC from metadata." - (when docsig-func - (when-let ((docsig (funcall docsig-func string))) - (propertize - (format "%s" docsig) - 'face 'selectrum-completion-docsig)))) + (when-let ((docsig (funcall docsig-func string))) + (propertize + (format "%s" docsig) + 'face 'selectrum-completion-docsig))) ;;;; Minibuffer state @@ -498,6 +494,37 @@ This is used to implement `selectrum-repeat'.") selectrum--start-of-input-marker selectrum--end-of-input-marker))) +(defun selectrum--get-meta (setting &optional table pred input) + "Get metadata SETTING from TABLE. +TABLE defaults to `minibuffer-completion-table'. +PRED defaults to `minibuffer-completion-predicate'. +INPUT defaults to current selectrum input string." + (let ((input (or input (selectrum--current-input))) + (pred (or pred minibuffer-completion-predicate)) + (table (or table minibuffer-completion-table))) + (when table + (completion-metadata-get + (completion-metadata input table pred) setting)))) + +(defun selectrum--get-candidates-from-table (&optional table pred) + "Get candidates from TABLE. +TABLE defaults to `minibuffer-completion-table'. +PRED defaults to `minibuffer-completion-predicate'." + (let ((annotf (selectrum--get-meta 'annotation-function table pred)) + (strings (selectrum--normalize-collection + (or table minibuffer-completion-table) + (or pred minibuffer-completion-predicate)))) + (cond (annotf + (let ((cands ())) + (dolist (string strings (nreverse cands)) + (push (propertize + string + 'selectrum-candidate-display-suffix + (selectrum--get-annotation-suffix + string annotf)) + cands)))) + (t strings)))) + (defun selectrum--current-input () "Get current minibuffer input." (buffer-substring @@ -564,33 +591,6 @@ just rendering it to the screen and then checking." (run-with-idle-timer 0 nil #'selectrum--ensure-current-candidate-centered))))))) -(defun selectrum--init-candidates-from-table () - "Initialize candidates from `minibuffer-completion-table'." - (when (and (not selectrum--preprocessed-candidates) - minibuffer-completion-table) - (let* ((metad (completion-metadata - (selectrum--current-input) - minibuffer-completion-table - minibuffer-completion-predicate)) - (sortf (completion-metadata-get - metad - 'display-sort-function)) - (annotf (completion-metadata-get - metad - 'annotation-function)) - (strings (selectrum--normalize-collection - minibuffer-completion-table - minibuffer-completion-predicate)) - (cands ())) - (dolist (string strings) - (push (propertize string - 'selectrum-candidate-display-suffix - (selectrum--get-annotation-suffix string annotf)) - cands)) - (setq selectrum--preprocessed-candidates - (funcall (or sortf selectrum-preprocess-candidates-function) - (nreverse cands)))))) - (defun selectrum--minibuffer-post-command-hook () "Update minibuffer in response to user input." (goto-char (max (point) selectrum--start-of-input-marker)) @@ -606,7 +606,13 @@ just rendering it to the screen and then checking." (bound (marker-position selectrum--end-of-input-marker)) (keep-mark-active (not deactivate-mark))) (unless (equal input selectrum--previous-input-string) - (selectrum--init-candidates-from-table) + (when (and (not selectrum--preprocessed-candidates) + minibuffer-completion-table) + ;; No candidates were passed, initialize them from + ;; `minibuffer-completion-table'. + (setq selectrum--preprocessed-candidates + (funcall selectrum-preprocess-candidates-function + (selectrum--get-candidates-from-table)))) (setq selectrum--previous-input-string input) ;; Reset the persistent input, so that it will be nil if ;; there's no special attention needed. @@ -840,6 +846,10 @@ into the user input area to start with." (insert initial-input))) (setq selectrum--end-of-input-marker (point-marker)) (set-marker-insertion-type selectrum--end-of-input-marker t) + ;; If metadata specifies a custom sort function use it as + ;; `selectrum-preprocess-candidates-function' for this session. + (when-let ((sortf (selectrum--get-meta 'display-sort-function))) + (setq-local selectrum-preprocess-candidates-function sortf)) (setq selectrum--preprocessed-candidates (if (functionp candidates) candidates @@ -1320,24 +1330,32 @@ COLLECTION, and PREDICATE, see `completion-in-region'." (propertize cand 'selectrum-candidate-display-suffix - (selectrum--get-annotation-suffix - cand annotation-func) + (when annotation-func + (selectrum--get-annotation-suffix + cand annotation-func)) 'selectrum-candidate-display-right-margin - (selectrum--get-margin-docsig - cand docsig-func))) + (when docsig-func + (selectrum--get-margin-docsig + cand docsig-func)))) cands)) (selectrum-should-sort-p selectrum-should-sort-p)) (when display-sort-func (setq cands (funcall display-sort-func cands)) + ;; FIXME: This will set `selectrum-should-sort-p' for any + ;; recursive minibuffer sessions, too. (setq selectrum-should-sort-p nil)) (pcase (length cands) ;; We already rule out the situation where `cands' is empty. (`1 (setq result (car cands))) ( _ (setq result (selectrum-read "Completion: " cands - :may-modify-candidates t - :minibuffer-completion-table collection - :minibuffer-completion-predicate predicate)))) + ;; Don't pass + ;; `minibuffer-completion-table' and + ;; `minibuffer-completion-predicate' + ;; here because currently this function + ;; handles all metadata for region + ;; completion itself. + :may-modify-candidates t)))) (setq exit-status (cond ((not (member result cands)) 'sole) (t 'finished)))))) From f08fb787436197d5dd8cbc044224f3c2c5c02ec5 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 3 Jun 2020 19:46:17 +0200 Subject: [PATCH 12/21] Update Changelog --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b173fa4b..fdf9fd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,7 +69,11 @@ The format is based on [Keep a Changelog]. `minibuffer-completion-predicate`. These can be used to pass the `completing-read` collection and predicate so they are available for internal handling of completion API features and for other external - commands or packages which make use of them. + commands or packages which make use of them ([#94]). +* If the completion table passed to `completing-read` provides + `annotation-function` or `display-sort-function` in its metadata, + Selectrum will use this information to annotate or sort the + candidates accordingly ([#95]). ### Enhancements @@ -185,6 +189,8 @@ The format is based on [Keep a Changelog]. [#85]: https://github.com/raxod502/selectrum/pull/85 [#86]: https://github.com/raxod502/selectrum/pull/86 [#89]: https://github.com/raxod502/selectrum/pull/89 +[#94]: https://github.com/raxod502/selectrum/issues/94 +[#95]: https://github.com/raxod502/selectrum/pull/95 [raxod502/ctrlf#41]: https://github.com/raxod502/ctrlf/issues/41 ## 1.0 (released 2020-03-23) From 116c23ef10bac724c55172d1ac44d5f1f9fc9632 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 3 Jun 2020 20:07:57 +0200 Subject: [PATCH 13/21] Refactor --- selectrum.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/selectrum.el b/selectrum.el index a60780f9..9fff0c4b 100644 --- a/selectrum.el +++ b/selectrum.el @@ -526,10 +526,13 @@ PRED defaults to `minibuffer-completion-predicate'." (t strings)))) (defun selectrum--current-input () - "Get current minibuffer input." - (buffer-substring - selectrum--start-of-input-marker - selectrum--end-of-input-marker)) + "Get current Selectrum input." + (if (and selectrum--start-of-input-marker + selectrum--end-of-input-marker) + (buffer-substring + selectrum--start-of-input-marker + selectrum--end-of-input-marker) + "")) ;;;; Hook functions From be2d413be1a1a67f8e24eee744a3c808209e7fec Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 3 Jun 2020 20:08:08 +0200 Subject: [PATCH 14/21] Add selectrum-exhibit --- selectrum.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/selectrum.el b/selectrum.el index 9fff0c4b..f2bee845 100644 --- a/selectrum.el +++ b/selectrum.el @@ -534,6 +534,14 @@ PRED defaults to `minibuffer-completion-predicate'." selectrum--end-of-input-marker) "")) +(defun selectrum-exhibit () + "Trigger an update of Selectrums completion UI." + (when-let ((mini (active-minibuffer-window))) + (with-selected-window mini + (setq selectrum--preprocessed-candidates nil) + (setq selectrum--previous-input-string nil) + (selectrum--minibuffer-post-command-hook)))) + ;;;; Hook functions (defun selectrum--count-info () From d783891b08307a33b5fea75c05823c08e2ac7a31 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 3 Jun 2020 20:09:11 +0200 Subject: [PATCH 15/21] Update Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdf9fd42..7715287e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,8 @@ The format is based on [Keep a Changelog]. `annotation-function` or `display-sort-function` in its metadata, Selectrum will use this information to annotate or sort the candidates accordingly ([#95]). +* One can trigger an update of Selectrums completions UI manually by + calling `selectrum-exhibit` ([#95]). ### Enhancements From 2193ad0499c251964d38b9a4272fa4fb5a3b16d3 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Wed, 3 Jun 2020 20:13:26 +0200 Subject: [PATCH 16/21] Only reset candidates for appropriate cases --- selectrum.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/selectrum.el b/selectrum.el index f2bee845..c496e459 100644 --- a/selectrum.el +++ b/selectrum.el @@ -538,7 +538,9 @@ PRED defaults to `minibuffer-completion-predicate'." "Trigger an update of Selectrums completion UI." (when-let ((mini (active-minibuffer-window))) (with-selected-window mini - (setq selectrum--preprocessed-candidates nil) + (when (and minibuffer-completion-table + (not (functionp selectrum--preprocessed-candidates))) + (setq selectrum--preprocessed-candidates nil)) (setq selectrum--previous-input-string nil) (selectrum--minibuffer-post-command-hook)))) From 4a926b83ed7c46ccb7f6d7607470394be962572c Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Thu, 4 Jun 2020 14:33:47 +0200 Subject: [PATCH 17/21] Improve Changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7715287e..b7fb3e8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,11 +69,11 @@ The format is based on [Keep a Changelog]. `minibuffer-completion-predicate`. These can be used to pass the `completing-read` collection and predicate so they are available for internal handling of completion API features and for other external - commands or packages which make use of them ([#94]). + commands or packages which make use of them ([#94], [#95]). * If the completion table passed to `completing-read` provides `annotation-function` or `display-sort-function` in its metadata, Selectrum will use this information to annotate or sort the - candidates accordingly ([#95]). + candidates accordingly ([#82], [#95]). * One can trigger an update of Selectrums completions UI manually by calling `selectrum-exhibit` ([#95]). @@ -188,6 +188,7 @@ The format is based on [Keep a Changelog]. [#76]: https://github.com/raxod502/selectrum/pull/76 [#77]: https://github.com/raxod502/selectrum/pull/77 [#80]: https://github.com/raxod502/selectrum/issues/80 +[#82]: https://github.com/raxod502/selectrum/issues/82 [#85]: https://github.com/raxod502/selectrum/pull/85 [#86]: https://github.com/raxod502/selectrum/pull/86 [#89]: https://github.com/raxod502/selectrum/pull/89 From 61c79097f6f2b1d4f62b5cd397f715f08829edab Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Fri, 12 Jun 2020 17:49:35 +0200 Subject: [PATCH 18/21] Update CHANGELOG.md Co-authored-by: Radon Rosborough --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7fb3e8c..a80a4fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ The format is based on [Keep a Changelog]. `annotation-function` or `display-sort-function` in its metadata, Selectrum will use this information to annotate or sort the candidates accordingly ([#82], [#95]). -* One can trigger an update of Selectrums completions UI manually by +* One can trigger an update of Selectrum's completions UI manually by calling `selectrum-exhibit` ([#95]). From 0f7a754b27e9d85ac097b486f861724bb26405ab Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Fri, 12 Jun 2020 17:49:46 +0200 Subject: [PATCH 19/21] Update selectrum.el Co-authored-by: Radon Rosborough --- selectrum.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selectrum.el b/selectrum.el index c496e459..ba6ae4c0 100644 --- a/selectrum.el +++ b/selectrum.el @@ -535,7 +535,7 @@ PRED defaults to `minibuffer-completion-predicate'." "")) (defun selectrum-exhibit () - "Trigger an update of Selectrums completion UI." + "Trigger an update of Selectrum's completion UI." (when-let ((mini (active-minibuffer-window))) (with-selected-window mini (when (and minibuffer-completion-table From f4b47549e7dfd96fb7685efe37e7d87b77b8faa1 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Fri, 12 Jun 2020 17:50:04 +0200 Subject: [PATCH 20/21] Update selectrum.el Co-authored-by: Radon Rosborough --- selectrum.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selectrum.el b/selectrum.el index ba6ae4c0..8625565f 100644 --- a/selectrum.el +++ b/selectrum.el @@ -1171,7 +1171,7 @@ For MINIBUFFER-COMPLETION-TABLE and MINIBUFFER-COMPLETION-PREDICATE see `minibuffer-completion-table' and `minibuffer-completion-predicate'. They are used for internal purposes and compatibility to Emacs completion API. By passing -theses as keyword arguments they will be dynamically bound as per +these as keyword arguments they will be dynamically bound as per semantics of `cl-defun'." (unless may-modify-candidates (setq candidates (copy-sequence candidates))) From 47b46310bac14279502358d92a8991e2c668a9b1 Mon Sep 17 00:00:00 2001 From: Clemens Radermacher Date: Mon, 15 Jun 2020 14:30:22 +0200 Subject: [PATCH 21/21] Also handle completion-extra-properties --- CHANGELOG.md | 3 ++- selectrum.el | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80a4fc3..b864bff6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,7 +73,8 @@ The format is based on [Keep a Changelog]. * If the completion table passed to `completing-read` provides `annotation-function` or `display-sort-function` in its metadata, Selectrum will use this information to annotate or sort the - candidates accordingly ([#82], [#95]). + candidates accordingly. Annotations defined by + `completion-extra-properties` are handled, too ([#82], [#95]). * One can trigger an update of Selectrum's completions UI manually by calling `selectrum-exhibit` ([#95]). diff --git a/selectrum.el b/selectrum.el index 8625565f..22e8223d 100644 --- a/selectrum.el +++ b/selectrum.el @@ -510,7 +510,9 @@ INPUT defaults to current selectrum input string." "Get candidates from TABLE. TABLE defaults to `minibuffer-completion-table'. PRED defaults to `minibuffer-completion-predicate'." - (let ((annotf (selectrum--get-meta 'annotation-function table pred)) + (let ((annotf (or (selectrum--get-meta 'annotation-function table pred) + (plist-get completion-extra-properties + :annotation-function))) (strings (selectrum--normalize-collection (or table minibuffer-completion-table) (or pred minibuffer-completion-predicate))))