[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cape e341f81a79 098/146: README: Add emoji example
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cape e341f81a79 098/146: README: Add emoji example |
Date: |
Sun, 9 Jan 2022 20:57:45 -0500 (EST) |
branch: externals/cape
commit e341f81a79be8d6880b9cf608432e6098af034f8
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
README: Add emoji example
---
README.org | 33 +++++++++++++++++++++++++++++++++
cape.el | 15 ++++++++++-----
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/README.org b/README.org
index 87b81af7e0..7bc9784ac9 100644
--- a/README.org
+++ b/README.org
@@ -88,6 +88,39 @@ have certain edge cases. The adapter can be used as follows:
(list #'company-files #'company-ispell #'company-dabbrev)))
#+end_src
+Note that the adapter does not require Company to be installed. Backends
+implementing the Company specification do not necessarily have to depend on
+Company, however in practice most backends do. The following shows a small
+example completion backend, which can be used with both ~completion-at-point~
+(Corfu, default completion) and Company.
+
+#+begin_src emacs-lisp
+ (defvar emojis
+ '((":-D" . "😀")
+ (";-)" . "😉")
+ (":-/" . "😕")
+ (":-(" . "🙁")
+ (":-*" . "😙")))
+
+ (defun emoji-backend (action &optional arg &rest _)
+ (pcase action
+ ('prefix (and (memq (char-before) '(?: ?\;))
+ (cons (string (char-before)) t)))
+ ('candidates (all-completions arg emojis))
+ ('annotation (concat " " (cdr (assoc arg emojis))))
+ ('post-completion
+ (let ((str (buffer-substring (- (point) 3) (point))))
+ (delete-region (- (point) 3) (point))
+ (insert (cdr (assoc str emojis)))))))
+
+ ;; Register emoji backend with `completion-at-point'
+ (setq completion-at-point-functions
+ (list (cape-company-to-capf #'emoji-backend)))
+
+ ;; Register emoji backend with Company.
+ (setq company-backends '(emoji-backend))
+#+end_src
+
** Super-Capf - Merging multiple Capfs
/Throw multiple Capfs under the Cape and get a Super-Capf!/
diff --git a/cape.el b/cape.el
index 8656c3e078..3a90031b6b 100644
--- a/cape.el
+++ b/cape.el
@@ -42,6 +42,14 @@
"Dictionary word list file."
:type 'string)
+(defcustom cape-company-async-timeout 1.0
+ "Company asynchronous timeout."
+ :type 'float)
+
+(defcustom cape-company-async-wait 0.02
+ "Company asynchronous busy waiting time."
+ :type 'float)
+
(defcustom cape-dabbrev-min-length 4
"Minimum length of dabbrev expansions."
:type 'integer)
@@ -727,9 +735,6 @@ If INTERACTIVE is nil the function acts like a capf."
:annotation-function (funcall extra-fun :annotation-function)
:exit-function (lambda (x _status) (funcall (funcall extra-fun
:exit-function) x)))))))
-(defvar company-async-wait)
-(defvar company-async-timeout)
-
(defun cape--company-call (backend &rest args)
"Call Company BACKEND with ARGS."
;; Company backends are non-interruptible.
@@ -741,8 +746,8 @@ If INTERACTIVE is nil the function acts like a capf."
(let (throw-on-input) (funcall fetcher (lambda (arg) (setq res arg))))
;; Force synchronization. The synchronization is interruptible!
(while (eq res 'trash)
- (sleep-for company-async-wait)
- (when (> (- (time-to-seconds) start) company-async-timeout)
+ (sleep-for cape-company-async-wait)
+ (when (> (- (time-to-seconds) start) cape-company-async-timeout)
(error "Cape company backend async timeout")))
res))
(res res)))
- [elpa] externals/cape 15491cef1a 087/146: Add link to Emacs, (continued)
- [elpa] externals/cape 15491cef1a 087/146: Add link to Emacs, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 659f710682 089/146: Add comment, ELPA Syncer, 2022/01/09
- [elpa] externals/cape ceca3a3d06 077/146: Expand readme, ELPA Syncer, 2022/01/09
- [elpa] externals/cape c57b01e982 091/146: Improve dynamic table support of cape-super-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 7008958b02 078/146: Minor corrections, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 9e4651649b 094/146: Treat company backends as non-interruptible., ELPA Syncer, 2022/01/09
- [elpa] externals/cape c7feeee10b 080/146: Simplify, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 02c9629bc6 081/146: Refactor and simplify, ELPA Syncer, 2022/01/09
- [elpa] externals/cape d3d9d926ac 082/146: Add cape-interactive-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 3c44bff1f6 095/146: Minor refactoring, ELPA Syncer, 2022/01/09
- [elpa] externals/cape e341f81a79 098/146: README: Add emoji example,
ELPA Syncer <=
- [elpa] externals/cape b06e3271e0 099/146: README: Be more precise about supported completion tables, ELPA Syncer, 2022/01/09
- [elpa] externals/cape b612af5754 101/146: Capf query should always be interruptible, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 15279b57fa 103/146: Remove todo, ELPA Syncer, 2022/01/09
- [elpa] externals/cape dcb5a139c4 105/146: Add cape-capf-with-case-fold, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 4cd6cdd4a2 106/146: Respect ignore-case for company backends, ELPA Syncer, 2022/01/09
- [elpa] externals/cape b8776afc9f 107/146: Add cape-dabbrev-check-other-buffers, ELPA Syncer, 2022/01/09
- [elpa] externals/cape b52829ad6d 110/146: Add comments, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 26d6025da2 111/146: Minor adjustments, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 5e6abb568a 113/146: Rename capf function in analogy to the table function, ELPA Syncer, 2022/01/09
- [elpa] externals/cape aae065830c 115/146: Add cape-sgml and cape-tex, ELPA Syncer, 2022/01/09