summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2021-12-07 19:13:45 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2021-12-07 19:13:45 +0100
commit918c15049c06cdf0deb8362e9ccee8de2eb6dbb0 (patch)
tree881d1004e09b539ee4e309e370536308e5d8e5fd
parentb895c8cf280f80a0cf724f137de06217679cb846 (diff)
Add cape-charchar
-rw-r--r--README.org3
-rw-r--r--cape.el29
2 files changed, 31 insertions, 1 deletions
diff --git a/README.org b/README.org
index 9aee1a9..a1461cf 100644
--- a/README.org
+++ b/README.org
@@ -55,7 +55,8 @@ this package should be upstreamed into Emacs itself.
("C-c p a" . cape-abbrev)
("C-c p i" . cape-ispell)
("C-c p l" . cape-line)
- ("C-c p w" . cape-dict))
+ ("C-c p w" . cape-dict)
+ ("C-c p c" . cape-char))
:init
;; Add `completion-at-point-functions', used by `completion-at-point'.
(add-to-list 'completion-at-point-functions #'cape-file)
diff --git a/cape.el b/cape.el
index 2cc00bd..b72ca5e 100644
--- a/cape.el
+++ b/cape.el
@@ -392,6 +392,35 @@ VALID is the input comparator, see `cape--input-valid-p'."
;;;; Capfs
+;;;;; cape-char
+
+(defvar cape--char-properties
+ (list :annotation-function #'cape--char-annotation
+ :exit-function #'cape--char-replace
+ :company-kind (lambda (_) 'text))
+ "Completion extra properties for `cape-char'.")
+
+(defun cape--char-replace (name _status)
+ "Replace character with NAME."
+ (when-let (char (gethash name ucs-names))
+ (delete-region (- (point) (length name)) (point))
+ (insert (char-to-string char))))
+
+(defun cape--char-annotation (name)
+ "Return annotation for character with NAME."
+ (when-let (char (gethash name ucs-names))
+ (format " %c" char)))
+
+;;;###autoload
+(defun cape-char (&optional interactive)
+ "Complete character at point.
+If INTERACTIVE is nil the function acts like a capf."
+ (interactive (list t))
+ (if interactive
+ (cape--interactive #'cape-char)
+ `(,(point) ,(point) ,(ucs-names)
+ :exclusive no ,@cape--char-properties)))
+
;;;;; cape-file
(defvar cape--file-properties