[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cape aae065830c 115/146: Add cape-sgml and cape-tex
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cape aae065830c 115/146: Add cape-sgml and cape-tex |
Date: |
Sun, 9 Jan 2022 20:57:47 -0500 (EST) |
branch: externals/cape
commit aae065830c26cbd9e21ac7205dff0dfec423392b
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add cape-sgml and cape-tex
---
README.org | 19 +++++++++++++++-
cape.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 92 insertions(+), 3 deletions(-)
diff --git a/README.org b/README.org
index 9aee1a9df8..1866b23bdb 100644
--- a/README.org
+++ b/README.org
@@ -31,6 +31,19 @@ packages or configurations, since it completes elisp symbols
anywere.
On the more experimental side, Cape has the super power to transform Company
backends into Capfs and merge multiple Capfs into a Super-Capf!
+* Available Capfs
+
+* ~cape-dabbrev~: Complete word from current buffers
+* ~cape-file~: Complete file name
+* ~cape-keyword~: Complete programming language keyword
+* ~cape-symbol~: Complete Elisp symbol
+* ~cape-abbrev~: Complete abbreviation (~add-global-abbrev~, ~add-mode-abbrev~)
+* ~cape-ispell~: Complete word from Ispell dictionary
+* ~cape-dict~: Complete word from dictionary file
+* ~cape-line~: Complete entire line from file
+* ~cape-tex~: Complete unicode char from TeX command, e.g. ~\hbar~,
+* ~cape-sgml~: Complete unicode char from Sgml entity, e.g., ~&alpha~.
+
* Configuration
Cape is available from MELPA. In the long term some of the Capfs provided by
@@ -55,12 +68,16 @@ 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 \\" . cape-tex)
+ ("C-c p &" . cape-sgml))
:init
;; Add `completion-at-point-functions', used by `completion-at-point'.
(add-to-list 'completion-at-point-functions #'cape-file)
+ (add-to-list 'completion-at-point-functions #'cape-tex)
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
(add-to-list 'completion-at-point-functions #'cape-keyword)
+ ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
;;(add-to-list 'completion-at-point-functions #'cape-ispell)
;;(add-to-list 'completion-at-point-functions #'cape-dict)
diff --git a/cape.el b/cape.el
index 2cc00bd594..67e6fefcc5 100644
--- a/cape.el
+++ b/cape.el
@@ -567,6 +567,71 @@ If INTERACTIVE is nil the function acts like a capf."
,(cape--table-with-properties (cape--dict-words) :category 'cape-dict)
:exclusive no ,@cape--dict-properties))))
+;;;;; cape-tex and cape-sgml
+
+(defmacro cape--quail-define (name method prefix)
+ "Define quail translation variable with NAME.
+METHOD is the input method.
+PREFIX is the prefix regular expression."
+ (describe-input-method method)
+ (let ((capf (intern (format "cape-%s" name)))
+ (list (intern (format "cape--%s-list" name)))
+ (ann (intern (format "cape--%s-annotation" name)))
+ (exit (intern (format "cape--%s-exit" name)))
+ (properties (intern (format "cape--%s-properties" name)))
+ (translation
+ (with-current-buffer "*Help*"
+ (let ((str (replace-regexp-in-string
+ "\n\n\\(\n\\|.\\)*" ""
+ (replace-regexp-in-string
+ "\\`\\(\n\\|.\\)*?----\n" ""
+ (replace-regexp-in-string
+ "\\`\\(\n\\|.\\)*?KEY SEQUENCE\n-+\n" ""
+ (buffer-substring-no-properties (point-min)
(point-max))))))
+ (pos 0)
+ (list nil)
+ (regexp (format "\\(%s[^ \t\n]+\\)[ \t\n]+\\([^ \t\n]+\\)"
prefix)))
+ (while (string-match regexp str pos)
+ (let ((char (match-string 2 str))
+ (name (if (equal method "sgml")
+ (string-remove-suffix ";" (match-string 1 str))
+ (match-string 1 str))))
+ (push (cons name char) list)
+ (setq pos (match-end 0))))
+ (kill-buffer-and-window)
+ (sort list (lambda (x y) (string< (car x) (car y))))))))
+ `(progn
+ (defvar ,list ',translation)
+ (defun ,ann (name)
+ (concat " " (cdr (assoc name ,list))))
+ (defun ,exit (name status)
+ (unless (eq status 'exact)
+ (when-let (str (cdr (assoc name ,list)))
+ (delete-region (- (point) (length name)) (point))
+ (insert str))))
+ (defvar ,properties
+ (list :annotation-function #',ann
+ :exit-function #',exit
+ :company-kind (lambda (_) 'text)))
+ (defun ,capf (&optional interactive)
+ (interactive (list t))
+ (if interactive
+ ;; NOTE: Disable cycling since replacement breaks it.
+ (let (completion-cycle-threshold)
+ (cape--interactive #',capf))
+ (require 'thingatpt)
+ (let ((bounds (if (thing-at-point-looking-at ,(format "%s[^ \n\t]*"
prefix))
+ (cons (match-beginning 0) (match-end 0))
+ (cons (point) (point)))))
+ (append
+ (list (car bounds) (cdr bounds)
+ (cape--table-with-properties ,list :category ',capf)
+ :exclusive 'no)
+ ,properties)))))))
+
+(cape--quail-define tex "TeX" "[\\\\^_]")
+(cape--quail-define sgml "sgml" "&")
+
;;;;; cape-abbrev
(defun cape--abbrev-list ()
@@ -583,9 +648,14 @@ If INTERACTIVE is nil the function acts like a capf."
(abbrev--symbol abbrev global-abbrev-table)))
30 0 nil t)))
+(defun cape--abbrev-exit (_str status)
+ "Expand expansion if STATUS is not exact."
+ (unless (eq status 'exact)
+ (expand-abbrev)))
+
(defvar cape--abbrev-properties
(list :annotation-function #'cape--abbrev-annotation
- :exit-function (lambda (&rest _) (expand-abbrev))
+ :exit-function #'cape--abbrev-exit
:company-kind (lambda (_) 'snippet))
"Completion extra properties for `cape-abbrev'.")
@@ -595,7 +665,9 @@ If INTERACTIVE is nil the function acts like a capf."
If INTERACTIVE is nil the function acts like a capf."
(interactive (list t))
(if interactive
- (cape--interactive #'cape-abbrev)
+ ;; NOTE: Disable cycling since abbreviation replacement breaks it.
+ (let (completion-cycle-threshold)
+ (cape--interactive #'cape-abbrev))
(when-let (abbrevs (cape--abbrev-list))
(let ((bounds (cape--bounds 'symbol)))
`(,(car bounds) ,(cdr bounds)
- [elpa] externals/cape e341f81a79 098/146: README: Add emoji example, (continued)
- [elpa] externals/cape e341f81a79 098/146: README: Add emoji example, ELPA Syncer, 2022/01/09
- [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 <=
- [elpa] externals/cape 6ddd50e7b7 116/146: Improve prefix setting of file capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape fab063f187 119/146: Add cape-rfc1345, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 6652d62c5a 118/146: README: Fix list, ELPA Syncer, 2022/01/09
- [elpa] externals/cape ad7f35fdbe 121/146: cape-tex: Fix range issue, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 516eb36e8d 120/146: Minor fixes, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 1e73d032e4 125/146: Fix compilation error (Fix #16), ELPA Syncer, 2022/01/09
- [elpa] externals/cape 89aaca7789 128/146: Protect cape--char-translation from macro expansion, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 399fdad016 122/146: cape-tex/sgml: Add docsig, improve parsing of describe-input-method, ELPA Syncer, 2022/01/09
- [elpa] externals/cape c2db8ce4d9 127/146: Expand docstrings, ELPA Syncer, 2022/01/09
- [elpa] externals/cape ab91f727fb 126/146: cape-tex/sgml: Filter candidates during compilation, ELPA Syncer, 2022/01/09