diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2025-11-05 20:10:57 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2025-11-05 20:10:57 +0100 |
| commit | 98c375e6279c55c4e0c1a14df5ab8fbc0c8018d4 (patch) | |
| tree | edfeedd7fbbafe7e48b16f3291c252038c74f85f | |
| parent | 0a82f1e3cc8e5c852b43d26e61a73704d4341f9c (diff) | |
Improve cape-capf-sort
| -rw-r--r-- | CHANGELOG.org | 2 | ||||
| -rw-r--r-- | README.org | 27 | ||||
| -rw-r--r-- | cape.el | 2 |
3 files changed, 21 insertions, 10 deletions
diff --git a/CHANGELOG.org b/CHANGELOG.org index e15f360..830e3d8 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -5,6 +5,8 @@ * Development - Mark ~cape-capf-purify~ and ~cape-wrap-purify~ as obsolete. +- ~cape-capf-sort~: Make ~SORT~ function argument optional. If the ~SORT~ argument is + nil or not given, the completion UI sorting will take over. * Version 2.2 (2025-10-13) @@ -176,12 +176,12 @@ with ~cape-capf-super~. /Throw multiple Capfs under the Cape and get a Super-Capf!/ Cape supports merging multiple Capfs using the function ~cape-capf-super~. Due to -some technical details, not all Capfs can be merged successfully. Merge Capfs +technical details, not all Capfs can be merged successfully. Try to merge Capfs one by one and make sure that you get the desired outcome. -Note that ~cape-capf-super~ is not needed if multiple Capfs should betried one -after the other, for example you can use ~cape-file~ together with programming -mode Capfs by adding ~cape-file~ to the ~completion-at-point-functions~ list. File +Note that ~cape-capf-super~ is not needed if multiple Capfs should be tried one +after another, for example you can use ~cape-file~ together with programming mode +Capfs by adding ~cape-file~ to the ~completion-at-point-functions~ list. File completion will then be available in comments and string literals, but not in normal code. ~cape-capf-super~ is only necessary if you want to combine multiple Capfs, such that the candidates from multiple sources appear /together/ in the @@ -194,15 +194,24 @@ and completion functions which do not define completion boundaries. static completion functions like ~cape-dabbrev~, ~cape-keyword~, ~cape-dict~, etc., but not for multi-step completions like ~cape-file~. +The results returned by the individual Capfs are listed after each other, where +the the order of the completion candidates is preserved. In order to override +this sorting behavior use ~cape-capf-sort~, such that the completion UI can apply +its own sorting. + #+begin_src emacs-lisp ;; Merge the dabbrev, dict and keyword capfs, display candidates together. (setq-local completion-at-point-functions - (list (cape-capf-super #'cape-dabbrev #'cape-dict #'cape-keyword))) + (list (cape-capf-super #'cape-dabbrev #'cape-dict))) + +;; Let the UI (e.g. Corfu) sort the candidates by overriding the sort function. +(setq-local completion-at-point-functions + (list (cape-capf-sort (cape-capf-super #'cape-dabbrev #'cape-dict)))) -;; Alternative: Define named Capf instead of using the anonymous Capf directly -(defun cape-dabbrev-dict-keyword () - (cape-wrap-super #'cape-dabbrev #'cape-dict #'cape-keyword)) -(setq-local completion-at-point-functions (list #'cape-dabbrev-dict-keyword)) +;; Define named Capf instead of using the anonymous Capf directly. +(defun cape-dabbrev-dict () + (cape-wrap-super #'cape-dabbrev #'cape-dict)) +(setq-local completion-at-point-functions (list #'cape-dabbrev-dict)) #+end_src See also the aforementioned ~company--multi-backend-adapter~ from Company, which @@ -1110,7 +1110,7 @@ This function can be used as an advice around an existing Capf." (cape-wrap-properties capf :exclusive 'no)) ;;;###autoload -(defun cape-wrap-sort (capf sort) +(defun cape-wrap-sort (capf &optional sort) "Call CAPF and add SORT function. This function can be used as an advice around an existing Capf." (cape-wrap-properties |
