[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/spell-fu 32fcbd9e8e 68/86: Initial changes for multiple di
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/spell-fu 32fcbd9e8e 68/86: Initial changes for multiple dictionaries |
Date: |
Thu, 7 Jul 2022 12:03:44 -0400 (EDT) |
branch: elpa/spell-fu
commit 32fcbd9e8e1d97224c2addf06d1f5d02cf4b0e57
Author: Vladimir Panteleev <git@cy.md>
Commit: Vladimir Panteleev <git@cy.md>
Initial changes for multiple dictionaries
- Replace spell-fu--cache-table, a single hash table, with
spell-fu--cache-tables, a list of hash tables
- Replace spell-fu--ensure-dict with spell-fu--ensure-dicts, and make
it take a list of dictionary names
- Replace spell-fu--dictionary with spell-fu--dictionaries, which for
now returns a single dictionary
- Update related code. For now, spell-fu--word-add-or-remove assumes
the given word comes from the first dictionary.
---
spell-fu.el | 102 +++++++++++++++++++++++++++++++++---------------------------
1 file changed, 57 insertions(+), 45 deletions(-)
diff --git a/spell-fu.el b/spell-fu.el
index 0df240e0af..cd5c93db64 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -149,9 +149,9 @@ Notes:
;; List of language, dictionary mappings.
(defvar spell-fu--cache-table-alist nil)
-;; Buffer local dictionary.
-;; Note that this is typically the same dictionary shared across all buffers.
-(defvar-local spell-fu--cache-table nil)
+;; Buffer local dictionaries.
+;; Note that these are typically the same dictionaries shared across all
buffers.
+(defvar-local spell-fu--cache-tables nil)
;; Keep track of the last overlay, this allows expanding the existing overlay
where possible.
;; Useful since font-locking often uses multiple smaller ranges which can be
merged into one range.
@@ -162,9 +162,9 @@ Notes:
;; ---------------------------------------------------------------------------
;; Dictionary Utility Functions
-(defun spell-fu--dictionary ()
- "Access the current dictionary."
- (or ispell-local-dictionary ispell-dictionary "default"))
+(defun spell-fu--dictionaries ()
+ "Access the current dictionaries."
+ (list (or ispell-local-dictionary ispell-dictionary "default")))
(defun spell-fu--cache-file (dict)
"Return the location of the cache file with dictionary DICT."
@@ -507,40 +507,47 @@ the caller will need to regenerate the cache."
;;
;; Top level function, called when enabling the mode.
-(defun spell-fu--ensure-dict (dict)
- "Setup the dictionary, initializing new files as necessary with dictionary
DICT."
+(defun spell-fu--ensure-dicts (dicts)
+ "Setup the dictionaries, initializing them as necessary with dictionaries
DICTS."
- ;; First use the dictionary if it's in memory.
- ;; Once Emacs is running, this is used for all new buffers.
- (setq spell-fu--cache-table (assoc-default dict spell-fu--cache-table-alist))
+ (setq spell-fu--cache-tables
+ (mapcar
+ (lambda (dict)
- ;; Not loaded yet, initialize it.
- (unless spell-fu--cache-table
+ ;; First use the dictionary if it's in memory.
+ ;; Once Emacs is running, this is used for all new buffers.
+ (let ((cache-table (assoc-default dict spell-fu--cache-table-alist)))
- ;; Ensure our path exists.
- (unless (file-directory-p spell-fu-directory)
- (make-directory spell-fu-directory))
+ ;; Not loaded yet, initialize it.
+ (unless cache-table
- (let
- ( ;; Get the paths of both files, ensure the cache file is newer,
- ;; otherwise regenerate it.
- (words-file (spell-fu--words-file dict))
- (cache-file (spell-fu--cache-file dict)))
+ ;; Ensure our path exists.
+ (unless (file-directory-p spell-fu-directory)
+ (make-directory spell-fu-directory))
- (spell-fu--word-list-ensure words-file dict)
+ (let
+ ( ;; Get the paths of both files, ensure the cache file is newer,
+ ;; otherwise regenerate it.
+ (words-file (spell-fu--words-file dict))
+ (cache-file (spell-fu--cache-file dict)))
- ;; Load cache or create it, creating it returns the cache
- ;; to avoid some slow-down on first load.
- (setq spell-fu--cache-table
- (or
- (and
- (file-exists-p cache-file)
- (not (spell-fu--file-is-older cache-file words-file))
- (spell-fu--cache-words-load cache-file))
- (spell-fu--cache-from-word-list words-file cache-file)))
+ (spell-fu--word-list-ensure words-file dict)
+
+ ;; Load cache or create it, creating it returns the cache
+ ;; to avoid some slow-down on first load.
+ (setq cache-table
+ (or
+ (and
+ (file-exists-p cache-file)
+ (not (spell-fu--file-is-older cache-file words-file))
+ (spell-fu--cache-words-load cache-file))
+ (spell-fu--cache-from-word-list words-file cache-file)))
+
+ ;; Add to to `spell-fu--cache-table-alist' for reuse on next
load.
+ (push (cons dict cache-table) spell-fu--cache-table-alist)))
- ;; Add to to `spell-fu--cache-table-alist' for reuse on next load.
- (push (cons dict spell-fu--cache-table) spell-fu--cache-table-alist))))
+ cache-table))
+ dicts)))
;; ---------------------------------------------------------------------------
@@ -570,10 +577,14 @@ Otherwise remove all overlays."
Marking the spelling as incorrect using `spell-fu-incorrect-face' on failure.
Argument POINT-START the beginning position of WORD.
Argument POINT-END the end position of WORD."
- (unless (gethash (encode-coding-string (downcase word) 'utf-8)
spell-fu--cache-table nil)
+ (or
+ ;; Dictionary search.
+ (let ((encoded-word (encode-coding-string (downcase word) 'utf-8)))
+ (cl-find-if (lambda (table) (gethash encoded-word table nil))
spell-fu--cache-tables))
;; Ignore all uppercase words.
- (unless (equal word (upcase word))
- (spell-fu-mark-incorrect pos-beg pos-end))))
+ (equal word (upcase word))
+ ;; Mark as incorrect otherwise.
+ (spell-fu-mark-incorrect pos-beg pos-end)))
;; ---------------------------------------------------------------------------
@@ -1039,13 +1050,14 @@ Return t when found, otherwise nil."
"Reset spell-checked overlays for buffers using the dictionary from
CACHE-TABLE."
(dolist (buf (buffer-list))
(with-current-buffer buf
- (when (bound-and-true-p spell-fu-mode)
- (when (eq cache-table (bound-and-true-p spell-fu--cache-table))
- ;; For now simply clear syntax highlighting.
- (unless (<= spell-fu-idle-delay 0.0)
- (spell-fu--idle-overlays-remove))
- (spell-fu--overlays-remove)
- (font-lock-flush))))))
+ (when (and (bound-and-true-p spell-fu-mode) (bound-and-true-p
spell-fu--cache-tables))
+ (dolist (table spell-fu--cache-tables)
+ (when (eq cache-table table)
+ ;; For now simply clear syntax highlighting.
+ (unless (<= spell-fu-idle-delay 0.0)
+ (spell-fu--idle-overlays-remove))
+ (spell-fu--overlays-remove)
+ (font-lock-flush)))))))
(defun spell-fu--word-add-or-remove (word words-file action)
"Apply ACTION to WORD from the personal dictionary WORDS-FILE.
@@ -1060,7 +1072,7 @@ Return t when the action succeeded."
(message "personal dictionary not defined!")
(throw 'result nil))
- (let ((this-cache-table spell-fu--cache-table))
+ (let ((this-cache-table (car spell-fu--cache-tables)))
(with-temp-buffer
(insert-file-contents-literally words-file)
@@ -1212,7 +1224,7 @@ Return t when the word is removed."
(defun spell-fu-mode-enable ()
"Turn on option `spell-fu-mode' for the current buffer."
- (spell-fu--ensure-dict (spell-fu--dictionary))
+ (spell-fu--ensure-dicts (spell-fu--dictionaries))
;; We may want defaults for other modes,
;; although keep this general.
- [nongnu] elpa/spell-fu 1e6928f77d 05/86: Cleanup: add message for generating cache, some comments, (continued)
- [nongnu] elpa/spell-fu 1e6928f77d 05/86: Cleanup: add message for generating cache, some comments, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu bd76cb262e 15/86: Avoid 2x loops over the pending screen overlays, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 4f9732492c 01/86: Initial code., ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 6a7440044e 19/86: Cleanup: rename variables to make the assignment explicit, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 5915e0ae2a 24/86: Cleanup: use safer sharp-quoted function names, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 3f4fc34204 32/86: Add 'spell-fu-buffer' utility, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu ddad489f2c 43/86: Adds affix dict support via aspell expand cmd, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu ce64f4bc4d 51/86: Cleanup: remove arguments that are always fixed, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1b765f8029 58/86: Cleanup: replace setq with let binding, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1159eeec13 63/86: Fix including trailing single-quote in the word, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 32fcbd9e8e 68/86: Initial changes for multiple dictionaries,
ELPA Syncer <=
- [nongnu] elpa/spell-fu 1f3e5b8f05 72/86: readme: Fix typos, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 2f2fd6de00 83/86: Change URL to codeberg, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 00b75e5741 25/86: Cleanup: docstring, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1bc18879b6 27/86: Add license file, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu d0700095ea 28/86: Add header to cache loading & error checking for cache content, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu f6c849f860 30/86: Fix disabling spell-fu when used without a timer, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 502d523b46 31/86: Fix unintended modification of the standard syntax table, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu e62cfc4f08 34/86: Add support for personal dictionary management, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 86d46cf63e 37/86: fix: encode word to utf8, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 9180a77865 48/86: Fix #15: don't enable (when used globally) for application buffers, ELPA Syncer, 2022/07/07