branch: externals/guess-language
commit 6ee7f775e72173c9ca11faca6d763721712278cd
Author: Titus von der Malsburg <[email protected]>
Commit: Titus von der Malsburg <[email protected]>
Only guess when paragraph has some minimal length.
---
guess-language.el | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/guess-language.el b/guess-language.el
index 4cd4b7c..ef98cc3 100644
--- a/guess-language.el
+++ b/guess-language.el
@@ -29,6 +29,8 @@
(defvar guess-language-languages '(en de))
+(defvar guess-language-min-paragraph-length 40)
+
(defun guess-language-load-trigrams ()
(cl-loop
for lang in guess-language-languages
@@ -81,13 +83,16 @@ ispell dictionaries accordingly."
(defun guess-language-autoset-and-spellcheck (beginning end doublon)
"Runs `guess-language-autoset' and then the flyspell on the
current paragraph."
- (let ((old-dictionary ispell-local-dictionary))
- (guess-language-autoset)
- (unless (string= old-dictionary ispell-local-dictionary)
- (remove-hook 'flyspell-incorrect-hook
#'guess-language-autoset-and-spellcheck)
- (flyspell-region (save-excursion (backward-paragraph) (point))
- (save-excursion (forward-paragraph) (point)))
- (add-hook 'flyspell-incorrect-hook
#'guess-language-autoset-and-spellcheck))))
+ (let ((old-dictionary ispell-local-dictionary)
+ (beginning (save-excursion (backward-paragraph) (point)))
+ (end (save-excursion (forward-paragraph) (point))))
+ (when (> (- end beginning) guess-language-min-paragraph-length)
+ (guess-language-autoset)
+ (unless (string= old-dictionary ispell-local-dictionary)
+ (remove-hook 'flyspell-incorrect-hook
#'guess-language-autoset-and-spellcheck)
+ (flyspell-region (save-excursion (backward-paragraph) (point))
+ (save-excursion (forward-paragraph) (point)))
+ (add-hook 'flyspell-incorrect-hook
#'guess-language-autoset-and-spellcheck)))))
(add-hook 'flyspell-incorrect-hook #'guess-language-autoset-and-spellcheck)