diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-04-05 21:09:19 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-04-05 21:09:39 +0200 |
| commit | 36256bb15c342ed89a141b77fdf0bf18e0cfb86b (patch) | |
| tree | 8df525349499a5818a0f0b8ad812ac52df794124 /cape.el | |
| parent | 0053340082a81ef84b3c8e303d0e4f2dc98e6834 (diff) | |
Deprecate cape-ispell in favor of cape-dict
cape-ispell just used grep to scan /usr/share/dict/words. We can replicate
`ispell-lookup-words' with very little code thanks to the function
`process-lines-ignore-status'. This way we avoid loading ispell.el. Also the
name `cape-ispell' was rather confusing since it suggested that some kind of
spell-checking is going on, which was never the case.
Diffstat (limited to 'cape.el')
| -rw-r--r-- | cape.el | 65 |
1 files changed, 27 insertions, 38 deletions
@@ -35,7 +35,6 @@ ;; 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. @@ -67,6 +66,14 @@ "Dictionary word list file." :type 'string) +(defcustom cape-dict-grep t + "Use grep to search through `cape-dict-file'. +If this variable is non-nil, the dictionary will be searched with +grep in a separate process. Otherwise the whole dictionary will +be loaded into Emacs. Depending on the size of your dictionary +one or the other approach is preferable." + :type 'boolean) + (defcustom cape-dabbrev-min-length 4 "Minimum length of dabbrev expansions. This setting ensures that words which are too short @@ -391,37 +398,6 @@ See the user options `cape-dabbrev-min-length' and for w in (dabbrev--find-all-expansions word (dabbrev--ignore-case-p word)) if (>= (length w) min-len) collect w))) -;;;;; cape-ispell - -(defvar cape--ispell-properties - (list :annotation-function (lambda (_) " Ispell") - :company-kind (lambda (_) 'text) - :exclusive 'no) - "Completion extra properties for `cape-ispell'.") - -(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) - (cape--silent (ispell-lookup-words (format "*%s*" str))))) - -;;;###autoload -(defun cape-ispell (&optional interactive) - "Complete word at point with Ispell. -If INTERACTIVE is nil the function acts like a Capf." - (interactive (list t)) - (if interactive - (cape-interactive #'cape-ispell) - (let ((bounds (cape--bounds 'word))) - `(,(car bounds) ,(cdr bounds) - ,(cape--table-with-properties - (cape--cached-table (car bounds) (cdr bounds) - #'cape--ispell-words - #'string-search) - :category 'cape-ispell) - ,@cape--ispell-properties)))) - ;;;;; cape-dict (defvar cape--dict-properties @@ -430,11 +406,16 @@ If INTERACTIVE is nil the function acts like a Capf." :exclusive 'no) "Completion extra properties for `cape-dict'.") -(defvar cape--dict-words nil) -(defun cape--dict-words () - "Dictionary words." - (or cape--dict-words - (setq cape--dict-words +(defun cape--dict-grep-words (str) + "Return all words from `cape-dict-file' matching STR." + (unless (equal str "") + (process-lines-ignore-status "grep" "-Fi" str cape-dict-file))) + +(defvar cape--dict-all-words nil) +(defun cape--dict-all-words () + "Load all words from `cape-dict-file'." + (or cape--dict-all-words + (setq cape--dict-all-words (split-string (with-temp-buffer (insert-file-contents cape-dict-file) (buffer-string)) @@ -450,9 +431,17 @@ If INTERACTIVE is nil the function acts like a Capf." (cape-interactive #'cape-dict) (let ((bounds (cape--bounds 'word))) `(,(car bounds) ,(cdr bounds) - ,(cape--table-with-properties (cape--dict-words) :category 'cape-dict) + ,(cape--table-with-properties + (if cape-dict-grep + (cape--cached-table (car bounds) (cdr bounds) + #'cape--dict-grep-words + #'string-search) + (cape--dict-all-words)) + :category 'cape-dict) ,@cape--dict-properties)))) +(define-obsolete-function-alias 'cape-ispell 'cape-dict "0.13") + ;;;;; cape-abbrev (defun cape--abbrev-tables () |
