[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cape 84c128ae9b 013/146: Add cape-merge-capfs (Fix #2)
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cape 84c128ae9b 013/146: Add cape-merge-capfs (Fix #2) |
Date: |
Sun, 9 Jan 2022 20:57:38 -0500 (EST) |
branch: externals/cape
commit 84c128ae9bbc80a5e890f4edf16e0c112f9374da
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add cape-merge-capfs (Fix #2)
---
README.org | 14 +++++++++++++-
cape.el | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index f35596c31a..90d0b96180 100644
--- a/README.org
+++ b/README.org
@@ -62,8 +62,20 @@ completion mechanism. The adapter is still experimental and
may have certain edg
cases. It can be used as follows:
#+begin_src emacs-lisp
- ;; Use Company backends as Capfs!
+ ;; Use Company backends as Capfs.
(setq-local completion-at-point-functions
(mapcar #'cape-company-to-capf
(list #'company-files #'company-ispell #'company-dabbrev)))
#+end_src
+
+* Merging Capf
+
+Cape supports merging multiple Capfs using the function ~cape-merge-capfs~.
This
+feature is experimental and works only for well-behaved Capfs and simple
+completion tables. But it is a start to emulate the corresponding Company
feature.
+
+#+begin_src emacs-lisp
+ ;; Merge the dabbrev and dict capfs, display candidates together.
+ (setq-local completion-at-point-functions
+ (list (cape-merge-capfs #'cape-dabbrev-capf #'cape-dict-capf)))
+#+end_src
diff --git a/cape.el b/cape.el
index 7ab68b3627..fb4507e0d6 100644
--- a/cape.el
+++ b/cape.el
@@ -29,6 +29,8 @@
;;; Code:
+(eval-when-compile (require 'cl-lib))
+
(defgroup cape nil
"Completion At Point Extensions."
:group 'convenience
@@ -464,6 +466,40 @@
(user-error "No keywords for %s" major-mode))
cape--keyword-properties))
+(defun cape--merged-function (ht prop)
+ "Return merged function for PROP given HT."
+ (lambda (x)
+ (when-let (fun (plist-get (gethash x ht) prop))
+ (funcall fun x))))
+
+(defun cape-merge-capfs (&rest capfs)
+ "Merge CAPFS and return new Capf which includes all candidates."
+ (lambda ()
+ (when-let (results (delq nil (mapcar #'funcall capfs)))
+ (pcase-let ((`((,beg ,end . ,_)) results)
+ (candidates nil)
+ (ht (make-hash-table :test #'equal)))
+ (cl-loop for (beg2 end2 table . plist) in results do
+ (when (and (= beg beg2) (= end end2))
+ (setq table (all-completions "" table (plist-get plist
:predicate))
+ candidates (nconc candidates table))
+ (cl-loop for cand in table do (puthash cand plist ht))))
+ (list beg end
+ (lambda (str pred action)
+ (if (eq action 'metadata)
+ '(metadata
+ (display-sort-function . identity)
+ (cycle-sort-function . identity))
+ (complete-with-action action candidates str pred)))
+ :exclusive 'no
+ :company-doc-buffer (cape--merged-function ht
:company-doc-buffer)
+ :company-location (cape--merged-function ht :company-location)
+ :company-docsig (cape--merged-function ht :company-docsig)
+ :company-deprecated (cape--merged-function ht
:company-deprecated)
+ :company-kind (cape--merged-function ht :company-kind)
+ :annotation-function (cape--merged-function ht
:annotation-function)
+ :exit-function (lambda (x _status) (funcall
(cape--merged-function ht :exit-function) x)))))))
+
(defun cape--company-call (backend &rest args)
"Call Company BACKEND with ARGS."
(pcase (apply backend args)
- [elpa] branch externals/cape created (now 5ccece0e34), ELPA Syncer, 2022/01/09
- [elpa] externals/cape 4b3f29e565 001/146: Initial commit, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 139ffe8720 002/146: Add license, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 8ed1e4e9cd 005/146: Remove parens from annotations, ELPA Syncer, 2022/01/09
- [elpa] externals/cape a8d00aa3ef 006/146: Add defcustoms, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 97eacd933d 016/146: README: Update example, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 9833045077 017/146: Add completion categories, ELPA Syncer, 2022/01/09
- [elpa] externals/cape b3c5e4ec69 018/146: cape-merge-capfs: Fix sorting, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 26b822db0a 011/146: Add MELPA badges, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 84c128ae9b 013/146: Add cape-merge-capfs (Fix #2),
ELPA Syncer <=
- [elpa] externals/cape 6c124b6cfd 015/146: README: Add some justification for the name :), ELPA Syncer, 2022/01/09
- [elpa] externals/cape 63ded5fde4 028/146: Improve cape-company-to-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape f270456b5d 041/146: Improve cape-dabbrev-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape a8e10cf7ae 014/146: Update README, ELPA Syncer, 2022/01/09
- [elpa] externals/cape d6b13d3055 027/146: Fix no-cache call, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 0e60999893 032/146: cape-ispell: Fix caching, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 7325c5002f 035/146: Update README, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 0a374042c9 003/146: README: Update configuration, ELPA Syncer, 2022/01/09
- [elpa] externals/cape d7c765d057 004/146: Add cape-keyword and cape-keyword-capf (Fix #3), ELPA Syncer, 2022/01/09
- [elpa] externals/cape 1aaca0fd74 008/146: Expand comment, ELPA Syncer, 2022/01/09