emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/guess-language 6ee7f77 005/101: Only guess when paragra


From: Stefan Monnier
Subject: [elpa] externals/guess-language 6ee7f77 005/101: Only guess when paragraph has some minimal length.
Date: Sat, 23 Feb 2019 10:34:31 -0500 (EST)

branch: externals/guess-language
commit 6ee7f775e72173c9ca11faca6d763721712278cd
Author: Titus von der Malsburg <address@hidden>
Commit: Titus von der Malsburg <address@hidden>

    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)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]