[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/spell-fu 98424adbea 42/86: adds helper routine to get lang
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/spell-fu 98424adbea 42/86: adds helper routine to get lang from dict |
Date: |
Thu, 7 Jul 2022 12:03:42 -0400 (EDT) |
branch: elpa/spell-fu
commit 98424adbea00e38ebe8127c1255c008db4a2b35b
Author: Hanno Perrey <hanno@hoowl.se>
Commit: Campbell Barton <ideasman42@gmail.com>
adds helper routine to get lang from dict
Determines the language from the dictionary, e.g. "de" from "de_DE".
Supports aspell alias dictionaries, e.g. "german" for "de_DE" using
ispell's lookup routines.
---
spell-fu.el | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/spell-fu.el b/spell-fu.el
index a21d489c8f..0afc332e30 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -159,6 +159,49 @@ Notes:
"Return the location of the word-list with dictionary DICT."
(expand-file-name (format "words_%s.txt" dict) spell-fu-directory))
+(defun spell-fu--aspell-find-data-file (dict)
+ "For Aspell dictionary DICT, return an associated data file path or nil."
+ ;; Based on `ispell-aspell-find-dictionary'.
+
+ ;; Make sure `ispell-aspell-dict-dir' is defined.
+ (unless ispell-aspell-dict-dir
+ (setq ispell-aspell-dict-dir (ispell-get-aspell-config-value "dict-dir")))
+
+ ;; Make sure `ispell-aspell-data-dir' is defined.
+ (unless ispell-aspell-data-dir
+ (setq ispell-aspell-data-dir (ispell-get-aspell-config-value "data-dir")))
+
+ ;; Try finding associated data-file. aspell will look for master .dat
+ ;; file in `dict-dir' and `data-dir'. Associated .dat files must be
+ ;; in the same directory as master file.
+ (catch 'datafile
+ (save-match-data
+ (dolist (tmp-path (list ispell-aspell-dict-dir ispell-aspell-data-dir))
+ ;; Try `xx.dat' first, strip out variant, country code, etc,
+ ;; then try `xx_YY.dat' (without stripping country code),
+ ;; then try `xx-alt.dat', for `de-alt' etc.
+ (dolist (dict-re (list "^[[:alpha:]]+" "^[[:alpha:]_]+"
"^[[:alpha:]]+-\\(alt\\|old\\)"))
+ (let ((dict-match (and (string-match dict-re dict) (match-string 0
dict))))
+ (when dict-match
+ (let ((fullpath (concat (file-name-as-directory tmp-path)
dict-match ".dat")))
+ (if (file-readable-p fullpath)
+ (throw 'datafile fullpath))))))))))
+
+(defun spell-fu--aspell-lang-from-dict (dict)
+ "Return the language of a DICT or nil if identification fails.
+
+Supports aspell alias dictionaries, e.g. 'german' or 'deutsch'
+for 'de_DE' using Ispell's lookup routines. The language is
+identified by looking for the data file associated with the
+dictionary."
+ (unless ispell-aspell-dictionary-alist
+ (ispell-find-aspell-dictionaries))
+ (let ((dict-name (cadr (nth 5 (assoc dict ispell-aspell-dictionary-alist)))))
+ (when dict-name
+ (let ((data-file (spell-fu--aspell-find-data-file dict-name)))
+ (when data-file
+ (file-name-base data-file))))))
+
;; ---------------------------------------------------------------------------
;; Generic Utility Functions
- [nongnu] elpa/spell-fu bd00417a0e 09/86: Improve status messages when generating word-list & cache, (continued)
- [nongnu] elpa/spell-fu bd00417a0e 09/86: Improve status messages when generating word-list & cache, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu afeb1fd46f 10/86: readme: add some TODO's, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu b7e5cf3d73 11/86: Fix missing checks that ispell variables are bound before use, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 30be3683b2 12/86: readme: update settings docs, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 18724c2e53 14/86: Avoid potentially accessing the same files time multiple times, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 8e8711f1fa 22/86: Add TODO's to the readme, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 88d803e994 26/86: Cleanup: use updated auto-formatting results, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu db0eef27ab 33/86: Add: spell-fu-goto-next-error, spell-fu-goto-previous-error, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu a7db587471 36/86: Remove redundant escaping, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu c58be13845 39/86: Fix #3 default word regex now excludes trailing apostrophes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 98424adbea 42/86: adds helper routine to get lang from dict,
ELPA Syncer <=
- [nongnu] elpa/spell-fu 143233734a 46/86: Allow global-spell-fu to be ignored per mode or using a function, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 103d3a19ce 49/86: Fix checking words that spanned different faces, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 1c0424b4c9 55/86: Cleanup: minor tweak to docstring, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu fd27978614 57/86: Update readme.rst, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu a7879fe9e7 59/86: Cleanup: over-wide docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu a2a0e3b786 60/86: Cleanup: remove redundant group properties, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 570ccd84ed 64/86: Fix spell-fu-goto-{next/prev}-error silently failing, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu b2da2874f3 67/86: Cleanup: use shorter variable names, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 00af362af3 71/86: Add multiple dictionary support, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 2ba65de269 74/86: Cleanup: include all arguments in doc-strings, ELPA Syncer, 2022/07/07