[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cape 67c3b75e2a 039/146: Refactor dabbrev, simplify
From: |
ELPA Syncer |
Subject: |
[elpa] externals/cape 67c3b75e2a 039/146: Refactor dabbrev, simplify |
Date: |
Sun, 9 Jan 2022 20:57:40 -0500 (EST) |
branch: externals/cape
commit 67c3b75e2a14c55fa0a4e943f882075a525fd7c9
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Refactor dabbrev, simplify
---
cape.el | 71 ++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 33 insertions(+), 38 deletions(-)
diff --git a/cape.el b/cape.el
index 62ff59c5c5..c13fa59ec9 100644
--- a/cape.el
+++ b/cape.el
@@ -48,6 +48,10 @@
"Company asynchronous busy waiting time."
:type 'float)
+(defcustom cape-dabbrev-min-length 4
+ "Minimum length of dabbrev expansions."
+ :type 'integer)
+
(defcustom cape-keywords
;; This variable was taken from company-keywords.el.
;; Please contribute corrections or additions to both Cape and Company.
@@ -342,59 +346,50 @@
(interactive)
(cape--complete-in-region 'symbol obarray cape--symbol-properties))
+(defun cape--cached-table (beg end cmp fun)
+ "Create caching completion table.
+BEG and END are the input bounds.
+CMP is the input comparison function, see `cape--input-changed-p'.
+FUN is the function which computes the candidates."
+ (let ((input 'init)
+ (beg (copy-marker beg))
+ (end (copy-marker end t))
+ (table nil))
+ (lambda (str pred action)
+ (let ((new-input (buffer-substring-no-properties beg end)))
+ (when (or (eq input 'init) (cape--input-changed-p input new-input cmp))
+ (setq table (funcall fun new-input) input new-input)))
+ (complete-with-action action table str pred))))
+
(defvar cape--dabbrev-properties
(list :annotation-function (lambda (_) " Dabbrev")
:company-kind (lambda (_) 'text)))
(defvar dabbrev-check-all-buffers)
(defvar dabbrev-check-other-buffers)
-(declare-function dabbrev--abbrev-at-point "dabbrev")
(declare-function dabbrev--ignore-case-p "dabbrev")
(declare-function dabbrev--find-all-expansions "dabbrev")
(declare-function dabbrev--reset-global-variables "dabbrev")
;;;###autoload
(defun cape-dabbrev-capf ()
- "Dabbrev completion-at-point-function."
- (require 'dabbrev)
+ "Ispell completion-at-point-function."
+ (when-let (bounds (bounds-of-thing-at-point 'word))
+ `(,(car bounds) ,(cdr bounds)
+ ,(cape--cached-table (car bounds) (cdr bounds) 'prefix
#'cape--dabbrev-expansions)
+ :exclusive no
+ ,@cape--dabbrev-properties)))
+
+(defun cape--dabbrev-expansions (word)
+ "Find all dabbrev expansions for WORD."
(let ((dabbrev-check-all-buffers nil)
(dabbrev-check-other-buffers nil))
(dabbrev--reset-global-variables))
- (let ((abbrev (ignore-errors (dabbrev--abbrev-at-point))))
- (when (and abbrev (not (string-match-p "[ \t\n]" abbrev)))
- (pcase ;; Interruptible scanning
- (while-no-input
- (let ((inhibit-message t)
- (message-log-max nil))
- (or (dabbrev--find-all-expansions
- abbrev (dabbrev--ignore-case-p abbrev))
- t)))
- ('nil (keyboard-quit))
- ('t nil)
- (words
- ;; Ignore completions which are too short
- (let ((min-len (+ 4 (length abbrev))))
- (setq words (seq-remove (lambda (x) (< (length x) min-len)) words)))
- (when words
- (let ((beg (progn (search-backward abbrev) (point)))
- (end (progn (search-forward abbrev) (point))))
- (unless (string-match-p "\n" (buffer-substring beg end))
- `(,beg ,end ,words :exclusive no
,@cape--dabbrev-properties)))))))))
-
-(defun cape--cached-table (beg end cmp fun)
- "Create caching completion table.
-BEG and END are the input bounds.
-CMP is the input comparison function, see `cape--input-changed-p'.
-FUN is the function which computes the candidates."
- (let ((input 'init)
- (beg (copy-marker beg))
- (end (copy-marker end t))
- (table nil))
- (lambda (str pred action)
- (let ((new-input (buffer-substring-no-properties beg end)))
- (when (or (eq input 'init) (cape--input-changed-p input new-input cmp))
- (setq table (funcall fun new-input) input new-input)))
- (complete-with-action action table str pred))))
+ (let* ((inhibit-message t)
+ (message-log-max nil)
+ (min-len (+ cape-dabbrev-min-length (length word)))
+ (words (dabbrev--find-all-expansions word (dabbrev--ignore-case-p
word))))
+ (cl-loop for w in words if (>= (length w) min-len) collect w)))
(defvar cape--ispell-properties
(list :annotation-function (lambda (_) " Ispell")
- [elpa] externals/cape edb2be3b71 092/146: Version 0.3, (continued)
- [elpa] externals/cape edb2be3b71 092/146: Version 0.3, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 08877dbf75 096/146: Improve comments, ELPA Syncer, 2022/01/09
- [elpa] externals/cape b5485b8878 031/146: cape-ispell-capf: Compute candidates later, ELPA Syncer, 2022/01/09
- [elpa] externals/cape dc26e9f7ab 049/146: cape-dict-capf: Load the dict lazily, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 2bcdd7bfe5 052/146: cape-file-capf: Require directory as prefix (Fix #9), ELPA Syncer, 2022/01/09
- [elpa] externals/cape 673b086dae 056/146: Annotate abbreviations with expansion, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 6ff72e5253 067/146: Unify cape-ispell and cape-ispell-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape d3e4d152ac 024/146: Add cape-symbol, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 8036636a0f 026/146: Add comment, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 9bd7bed258 029/146: cape-company-capf: Call the backend later in the completion process, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 67c3b75e2a 039/146: Refactor dabbrev, simplify,
ELPA Syncer <=
- [elpa] externals/cape 6e525cdfdd 040/146: Rework cape-company-to-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 6deb7d7a8b 044/146: Add docstrings, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 3ad6aa105e 045/146: cape-company-to-capf: Simplify, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 4a1f19af23 057/146: Fix super capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 26401bfa6a 069/146: Unify cape-abbrev and cape-abbrev-capf, ELPA Syncer, 2022/01/09
- [elpa] externals/cape d265a03e7f 074/146: cape-dabbrev: Make interactive, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 3eb7efc2d4 050/146: README: Expand reasoning, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 8cf2942881 085/146: Add comments regarding interruptible completion tables, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 488cfd9ed7 086/146: Move code around, ELPA Syncer, 2022/01/09
- [elpa] externals/cape 2008d809b6 088/146: Add cape-capf-with-predicate, ELPA Syncer, 2022/01/09