[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/spell-fu 676498f757 13/86: Support buffer local dictionari
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/spell-fu 676498f757 13/86: Support buffer local dictionaries |
Date: |
Thu, 7 Jul 2022 12:03:39 -0400 (EDT) |
branch: elpa/spell-fu
commit 676498f7578132e6118609630b0cb8b41f1e8b39
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Support buffer local dictionaries
---
readme.rst | 4 +++-
spell-fu.el | 53 ++++++++++++++++++++++++++++++++---------------------
2 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/readme.rst b/readme.rst
index d07bc504d7..e7811766c2 100644
--- a/readme.rst
+++ b/readme.rst
@@ -137,6 +137,9 @@ however they will be used when set:
When generating the word-list, this variable is used when present,
otherwise aspell's default dictionary is used.
+``ispell-local-dictionary``
+ Setting this allows you to have different languages set per-buffer.
+
``ispell-personal-dictionary``
When generating the word-list, this file is included when present.
@@ -163,5 +166,4 @@ TODO
- Support alternates to ``aspell`` for generating word lists.
- Support a custom command for generating a word list.
-- Support buffer local dictionaries.
- Support going to next/previous misspelled word.
diff --git a/spell-fu.el b/spell-fu.el
index 0405ee071b..bd1559857c 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -113,9 +113,12 @@ Notes:
;; ---------------------------------------------------------------------------
;; Internal Variables
-;; Hash table, keep it global,
-;; although we could support buffer local dictionaries.
-(defvar spell-fu--cache-table nil)
+;; 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)
;; ---------------------------------------------------------------------------
@@ -125,13 +128,13 @@ Notes:
"Access the current dictionary."
(or (bound-and-true-p ispell-local-dictionary) (bound-and-true-p
ispell-dictionary) "default"))
-(defun spell-fu--cache-file ()
+(defun spell-fu--cache-file (dict)
"Return the location of the cache file."
- (expand-file-name (format "words_%s.el" (spell-fu--dictionary))
spell-fu-directory))
+ (expand-file-name (format "words_%s.el" dict) spell-fu-directory))
-(defun spell-fu--words-file ()
+(defun spell-fu--words-file (dict)
"Return the location of the word-list."
- (expand-file-name (format "words_%s.txt" (spell-fu--dictionary))
spell-fu-directory))
+ (expand-file-name (format "words_%s.txt" dict) spell-fu-directory))
;; ---------------------------------------------------------------------------
@@ -223,7 +226,7 @@ Argument POS return faces at this point."
;; ---------------------------------------------------------------------------
;; Word List Generation
-(defun spell-fu--word-list-ensure (words-file)
+(defun spell-fu--word-list-ensure (words-file dict)
"Ensure the word list is generated.
Argument WORDS-FILE the file to write the word list into."
(let*
@@ -260,8 +263,7 @@ Argument WORDS-FILE the file to write the word list into."
(and
(bound-and-true-p ispell-really-aspell)
(bound-and-true-p ispell-program-name))
- (executable-find "aspell")))
- (dict (spell-fu--dictionary)))
+ (executable-find "aspell"))))
(cond
((string-equal dict "default")
@@ -322,7 +324,7 @@ save some time by not spending time reading it back."
;;
;; Top level function, called when enabling the mode.
-(defun spell-fu--init-dictionary ()
+(defun spell-fu--init-dictionary (dict)
"Setup the dictionary, initializing new files as necessary."
;; Ensure our path exists.
@@ -332,17 +334,26 @@ save some time by not spending time reading it back."
(let
( ;; Get the paths of both files, ensure the cache file is newer,
;; otherwise regenerate it.
- (words-file (spell-fu--words-file))
- (cache-file (spell-fu--cache-file)))
+ (words-file (spell-fu--words-file dict))
+ (cache-file (spell-fu--cache-file dict)))
+
+ (spell-fu--word-list-ensure words-file dict)
+
+
+ ;; Use previously loaded dictionary from language 'dict' where possible.
+ (setq spell-fu--cache-table (assoc-default dict
spell-fu--cache-table-alist))
- (spell-fu--word-list-ensure words-file)
+ ;; Not loaded yet, initialize it.
+ (unless spell-fu--cache-table
+ ;; Load cache or create it, creating it returns the cache
+ ;; to avoid some slow-down on first load.
+ (setq spell-fu--cache-table
+ (if (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)))
- ;; Load cache or create it, creating it returns the cache
- ;; to avoid some slow-down on first load.
- (setq spell-fu--cache-table
- (if (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 '(dict . spell-fu--cache-table) spell-fu--cache-table-alist))))
;; ---------------------------------------------------------------------------
@@ -569,7 +580,7 @@ range POINT-START to POINT-END. Otherwise remove all
overlays."
(defun spell-fu-mode-enable ()
"Turn on option `spell-fu-mode' for the current buffer."
- (spell-fu--init-dictionary)
+ (spell-fu--init-dictionary (spell-fu--dictionary))
;; We may want defaults for other modes,
;; although keep this general.
- [nongnu] branch elpa/spell-fu created (now cbe5cd84c3), ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu eeda8ef28e 06/86: Cleanup: minor non-functional changes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 676498f757 13/86: Support buffer local dictionaries,
ELPA Syncer <=
- [nongnu] elpa/spell-fu 073932be78 16/86: Cleanup: replace '(nth 5 ...' with file-attribute-modification-time, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 2c792330ac 18/86: Case insensitive sort lines as a list (not in the buffer), ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 03114080c8 20/86: Add requirements at the top of the file, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu fe557e3dff 21/86: Be explicit about using macro that sets values in-place, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 33a28e0df5 41/86: fix: encode word to utf-8 generating the cache, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 7770c005c4 47/86: Cleanup minor name change for spell-fu function name, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 866044304f 50/86: Check if faces can be used on property change, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 8f780a874c 66/86: Reduce idle overlay fragmentation, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 4fc84a9028 69/86: Fix spell-fu-directory's documentation, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 53bd2b24c6 81/86: Cleanup: add spell-fu--canonicalize-word utility function, ELPA Syncer, 2022/07/07