[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/guess-language e1db84e 006/101: Make this into a minor
From: |
Stefan Monnier |
Subject: |
[elpa] externals/guess-language e1db84e 006/101: Make this into a minor mode. |
Date: |
Sat, 23 Feb 2019 10:34:32 -0500 (EST) |
branch: externals/guess-language
commit e1db84e2b9502c3b417ad882c8593a853b2e70b1
Author: Titus von der Malsburg <address@hidden>
Commit: Titus von der Malsburg <address@hidden>
Make this into a minor mode.
---
guess-language.el | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/guess-language.el b/guess-language.el
index ef98cc3..28fe06e 100644
--- a/guess-language.el
+++ b/guess-language.el
@@ -80,7 +80,7 @@ ispell dictionaries accordingly."
(ispell-change-dictionary "de")
(typo-change-language "German")))))
-(defun guess-language-autoset-and-spellcheck (beginning end doublon)
+(defun guess-language-autoset-and-spellcheck-maybe (beginning end doublon)
"Runs `guess-language-autoset' and then the flyspell on the
current paragraph."
(let ((old-dictionary ispell-local-dictionary)
@@ -89,16 +89,41 @@ current paragraph."
(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)
+ (remove-hook 'flyspell-incorrect-hook
#'guess-language-autoset-and-spellcheck-maybe)
(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)
+ (add-hook 'flyspell-incorrect-hook
#'guess-language-autoset-and-spellcheck-maybe)))))
(setq flyspell-issue-welcome-flag nil)
(setq flyspell-issue-message-flag nil)
+(define-minor-mode guess-language-mode
+ "Toggle guess-language mode.
+Interactively with no argument, this command toggles the mode.
+A positive prefix argument enables the mode, any other prefix
+argument disables it. From Lisp, argument omitted or nil enables
+the mode, `toggle' toggles the state.
+
+Guess-language mode is a buffer-local minor mode. When enabled,
+it guesses the language when flyspell detects words that are
+incorrectly and changes the ispell's dictionary and typo-mode
+accordingly. If the language settings change, flyspell is run on
+the current paragraph. If the paragraph is shorter than
+`guess-language-min-paragraph-length' none of the above happens
+because there is likely not enough text to guess the language
+correctly."
+ ;; The initial value.
+ :init-value nil
+ ;; The indicator for the mode line.
+ :lighter " Guess-lang"
+ :global nil
+ :group 'guess-language
+ (if guess-language-mode
+ (add-hook 'flyspell-incorrect-hook
+ #'guess-language-autoset-and-spellcheck-maybe)
+ (remove-hook 'flyspell-incorrect-hook
+ #'guess-language-autoset-and-spellcheck-maybe)))
+
(provide 'guess-language)
;; Local Variables:
- [elpa] branch externals/guess-language created (now 1107b93), Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 43eb329 004/101: Fixed version number., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 2792ac4 003/101: Guesses the language only if flyspell is unhappy with what we, Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language e4c103c 009/101: Compile regexps after load., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language e1db84e 006/101: Make this into a minor mode.,
Stefan Monnier <=
- [elpa] externals/guess-language 5261d2f 010/101: Make defcustoms., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language e6ffe8d 011/101: Added some documentation., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 6ee7f77 005/101: Only guess when paragraph has some minimal length., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 30e23aa 001/101: Added initial proof of concept., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language e13f5a9 013/101: (Re)compile regexps when necessary., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 24213cb 032/101: Added some data for testing., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 9b1048f 026/101: More idiomatic way to do local hooks., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 38d7ab1 017/101: README: minor fixes, Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 9117deb 027/101: Made it easier to add new languages., Stefan Monnier, 2019/02/23
- [elpa] externals/guess-language 47ff6ad 022/101: Fix package, Stefan Monnier, 2019/02/23