diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2021-11-24 08:21:53 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2021-11-24 08:21:53 +0100 |
| commit | 90ad5d68d58cdb56838df6dc525daa9e3ccf12e4 (patch) | |
| tree | f7c19a40e53bdfbd5860f00a80aa3c9abcd7d7e7 | |
| parent | 04a332c5fe24ac112155e49e2c7934ae97007198 (diff) | |
Extract cape--cached-table
| -rw-r--r-- | cape.el | 38 |
1 files changed, 24 insertions, 14 deletions
@@ -381,27 +381,37 @@ (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 nil) + (beg (copy-marker beg)) + (end (copy-marker end t)) + (table 'init)) + (lambda (str pred action) + (let ((new-input (buffer-substring-no-properties beg end))) + (when (or (eq table '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--ispell-properties (list :annotation-function (lambda (_) " Ispell") :company-kind (lambda (_) 'text))) (declare-function ispell-lookup-words "ispell") +(defun cape--ispell-words (str) + "Return all words from Ispell matching STR." + (with-demoted-errors "Ispell Error: %S" + (require 'ispell) + (let ((message-log-max nil) + (inhibit-message t)) + (ispell-lookup-words (format "*%s*" str))))) + (defun cape--ispell-table (bounds) "Return completion table for Ispell completion between BOUNDS." - (let ((input nil) - (beg (copy-marker (car bounds))) - (end (copy-marker (car bounds) t)) - (words 'init)) - (lambda (str pred action) - (let ((new-input (buffer-substring-no-properties beg end))) - (when (or (eq words 'init) (not (string-match-p (regexp-quote input) new-input))) - (setq input new-input - words (with-demoted-errors "Ispell Error: %S" - (require 'ispell) - (let ((message-log-max nil) - (inhibit-message t)) - (ispell-lookup-words (format "*%s*" input))))))) - (complete-with-action action words str pred)))) + (cape--cached-table (car bounds) (cdr bounds) 'substring #'cape--ispell-words)) ;;;###autoload (defun cape-ispell-capf () |
