[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cape 8a2cc4c7bb 060/146: Add completion categories
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cape 8a2cc4c7bb 060/146: Add completion categories |
Date: |
Sun, 9 Jan 2022 20:57:42 -0500 (EST) |
branch: externals/cape
commit 8a2cc4c7bbbe4227bc585ee6938dded401b1b5f3
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add completion categories
---
cape.el | 69 +++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 44 insertions(+), 25 deletions(-)
diff --git a/cape.el b/cape.el
index 073e8b383e..ef1b8b4536 100644
--- a/cape.el
+++ b/cape.el
@@ -355,7 +355,20 @@
(defun cape-symbol ()
"Complete symbol at point."
(interactive)
- (cape--complete-in-region 'symbol obarray cape--symbol-properties))
+ (cape--complete-in-region 'symbol
+ (cape--table-with-properties obarray :category
'symbol)
+ cape--symbol-properties))
+
+(cl-defun cape--table-with-properties (table &key category sort)
+ "Create completion TABLE with properties.
+CATEGORY is the optional completion category.
+SORT is an optional sort function."
+ (lambda (str pred action)
+ (if (eq action 'metadata)
+ `(metadata (category . ,category)
+ (display-sort-function . ,sort)
+ (cycle-sort-function . ,sort))
+ (complete-with-action action table str pred))))
(cl-defun cape--cached-table (beg end fun &key valid category sort)
"Create caching completion table.
@@ -401,7 +414,8 @@ SORT is an optional sort function."
(end (progn (search-forward abbrev) (point))))
`(,beg ,end
;; Use equal check, since candidates must be longer than
cape-dabbrev-min-length
- ,(cape--cached-table beg end #'cape--dabbrev-expansions :valid
'equal :category 'dabbrev)
+ ,(cape--cached-table beg end #'cape--dabbrev-expansions
+ :valid 'equal :category 'cape-dabbrev)
:exclusive no
,@cape--dabbrev-properties)))))
@@ -434,7 +448,8 @@ SORT is an optional sort function."
(defun cape--ispell-table (bounds)
"Return completion table for Ispell completion between BOUNDS."
- (cape--cached-table (car bounds) (cdr bounds) #'cape--ispell-words :valid
'substring :category 'ispell))
+ (cape--cached-table (car bounds) (cdr bounds) #'cape--ispell-words
+ :valid 'substring :category 'cape-ispell))
;;;###autoload
(defun cape-ispell-capf ()
@@ -458,15 +473,17 @@ SORT is an optional sort function."
:company-kind (lambda (_) 'text))
"Completion extra properties for `cape-dict-capf'.")
-(defvar cape--dict-words nil)
-(defun cape--dict-words ()
- "Return list of dictionary words."
- (or cape--dict-words
- (setq cape--dict-words
- (split-string (with-temp-buffer
- (insert-file-contents-literally cape-dict-file)
- (buffer-string))
- "\n" 'omit-nulls))))
+(defvar cape--dict-table nil)
+(defun cape--dict-table ()
+ "Dictionary completion table."
+ (or cape--dict-table
+ (setq cape--dict-table
+ (cape--table-with-properties
+ (split-string (with-temp-buffer
+ (insert-file-contents-literally cape-dict-file)
+ (buffer-string))
+ "\n" 'omit-nulls)
+ :category 'cape-dict))))
;;;###autoload
(defun cape-dict-capf ()
@@ -475,19 +492,20 @@ SORT is an optional sort function."
`(,(car bounds) ,(cdr bounds)
,(lambda (str pred action)
;; Load the dict lazily
- (complete-with-action action (cape--dict-words) str pred))
+ (complete-with-action action (cape--dict-table) str pred))
:exclusive no ,@cape--dict-properties)))
;;;###autoload
(defun cape-dict ()
"Complete word at point."
(interactive)
- (cape--complete-in-region 'word (cape--dict-words) cape--dict-properties))
+ (cape--complete-in-region 'word (cape--dict-table) cape--dict-properties))
-(defun cape--abbrev-completions ()
- "Return all abbreviations."
- (delete "" (nconc (all-completions "" global-abbrev-table)
- (all-completions "" local-abbrev-table))))
+(defun cape--abbrev-table ()
+ "Abbreviation completion table."
+ (when-let (abbrevs (delete "" (nconc (all-completions "" global-abbrev-table)
+ (all-completions ""
local-abbrev-table))))
+ (cape--table-with-properties abbrevs :category 'cape-abbrev)))
(defun cape--abbrev-annotation (abbrev)
"Annotate ABBREV with expansion."
@@ -508,21 +526,22 @@ SORT is an optional sort function."
(defun cape-abbrev-capf ()
"Abbrev completion-at-point-function."
(when-let ((bounds (bounds-of-thing-at-point 'symbol))
- (abbrevs (cape--abbrev-completions)))
+ (abbrevs (cape--abbrev-table)))
`(,(car bounds) ,(cdr bounds) ,abbrevs :exclusive no
,@cape--abbrev-properties)))
;;;###autoload
(defun cape-abbrev ()
"Complete abbreviation at point."
(interactive)
- (cape--complete-in-region 'symbol (or (cape--abbrev-completions)
+ (cape--complete-in-region 'symbol (or (cape--abbrev-table)
(user-error "No abbreviations"))
cape--abbrev-properties))
-(defun cape--keywords ()
+(defun cape--keyword-table ()
"Return keywords for current major mode."
- (when-let (kw (alist-get major-mode cape-keywords))
- (if (symbolp (cadr kw)) (alist-get (cadr kw) cape-keywords) kw)))
+ (when-let* ((kw (alist-get major-mode cape-keywords))
+ (kw (if (symbolp (cadr kw)) (alist-get (cadr kw) cape-keywords)
kw)))
+ (cape--table-with-properties kw :category 'cape-keyword)))
(defvar cape--keyword-properties
(list :annotation-function (lambda (_) " Keyword")
@@ -533,7 +552,7 @@ SORT is an optional sort function."
(defun cape-keyword-capf ()
"Dictionary completion-at-point-function."
(when-let ((bounds (bounds-of-thing-at-point 'symbol))
- (keywords (cape--keywords)))
+ (keywords (cape--keyword-table)))
`(,(car bounds) ,(cdr bounds) ,keywords :exclusive no
,@cape--keyword-properties)))
;;;###autoload
@@ -541,7 +560,7 @@ SORT is an optional sort function."
"Complete word at point."
(interactive)
(cape--complete-in-region 'symbol
- (or (cape--keywords)
+ (or (cape--keyword-table)
(user-error "No keywords for %s" major-mode))
cape--keyword-properties))
- [elpa] externals/cape be2014538a 144/146: cape-dabbrev: Use thing-at-point-looking-at, (continued)
- [elpa] externals/cape be2014538a 144/146: cape-dabbrev: Use thing-at-point-looking-at, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 5ccece0e34 146/146: Add to GNU ELPA, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 700c9d7bc2 137/146: Remove cape-repair-misbehaving-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape bc1c1ee9fc 140/146: Make cape-tex etc less aggressive, add cape-tex-prefix-required variable, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 8726bc7246 138/146: cape--interactive: Simplify, ELPA Syncer, 2022/01/09
- [elpa] externals/cape ac65f2acdf 048/146: Add autoloads, renamings, README, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 0a05e51d2a 053/146: Add cape-capf-with-predicate (See #9), ELPA Syncer, 2022/01/09
- [elpa] externals/cape 75cb8c799a 071/146: Unify cape-file and cape-file-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 1d72f84b64 046/146: Add cape-capf-with-properties and cape-silent-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 693a376913 054/146: Revert "Add cape-capf-with-predicate (See #9)", ELPA Syncer, 2022/01/09
- [elpa] externals/cape 8a2cc4c7bb 060/146: Add completion categories,
ELPA Syncer <=
- [elpa] externals/cape 496bb4a5e4 065/146: Rename function, ELPA Syncer, 2022/01/09
- [elpa] externals/cape ba85197981 075/146: Update README, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 202345e954 083/146: cape-capf-with-properties: Add support for :sort and :category, ELPA Syncer, 2022/01/09
- [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