From: "Peter Münster" <pmlists@free.fr>
To: info-gnus-english@gnu.org
Subject: Re: Trigger spell checking before sending
Date: Mon, 15 Feb 2016 12:12:41 +0100 [thread overview]
Message-ID: <87ziv2p6qe.fsf@roche-blanche.net> (raw)
In-Reply-To: <87vb5uvxbd.fsf@pietrop-debian64RfL.eng.citrite.net>
On Fri, Feb 12 2016, Pietro wrote:
> Now that I got this working my following question is : would it be possible
> to auto-detect the language the spell checker should check ?
Hi,
Here some code snippets of my configuration, that could help perhaps:
--8<---------------cut here---------------start------------->8---
(defvar pm/language "fr"
"Language of current buffer.")
(make-variable-buffer-local 'pm/language)
(require 'auto-dictionary)
(defun pm/update-lang ()
"Check current buffer and update pm/language accordingly."
(setq pm/language (adict--evaluate-buffer-find-lang nil)))
(defun pm/spell (&optional lang)
"hunspell"
(unless lang
(pm/update-lang)
(setq lang (cdr (assoc-string pm/language '(("fr" . "fr_FR")
("de" . "de_DE")
("en" . "en_GB"))))))
(ispell-change-dictionary lang)
(if (and (eq major-mode 'message-mode) (not (use-region-p)))
(let ((ispell-skip-region-alist
(append '(("^<#.*>$")
("^On .+ [0-9]\\{2\\} [0-9]\\{4\\}, .+ wrote:$"))
ispell-skip-region-alist)))
(ispell-message))
(ispell)))
(defun adict-evaluate-buffer (&optional idle-only)
"Evaluate all words in the current buffer to find out the text's language.
If IDLE-ONLY is set, abort when an input event occurs."
(save-excursion
(let* ((counts (make-vector (length adict-language-list) 0))
(mm (eq major-mode 'message-mode))
(b-min (point-min))
(b-max (point-max))
(min (or (and mm (goto-char b-min)
(re-search-forward
(concat "^" (regexp-quote mail-header-separator) "$")
nil t)) b-min))
(max (or (and mm (goto-char b-max)
(re-search-backward
message-signature-separator nil t)) b-max)))
(adict-foreach-word
min max 8
(lambda (word)
;; increase language count of WORD by one
(callf incf (elt counts (adict-evaluate-word word))))
idle-only)
counts)))
(setenv "LC_ALL" "en_GB.utf8") ; needed by hunspell
(setq-default ispell-program-name "hunspell")
(global-set-key [?\C-c ?s] (lambda () (interactive) (pm/spell)))
(global-set-key [?\C-c ?f] (lambda () (interactive) (pm/spell "fr_FR")))
(global-set-key [?\C-c ?d] (lambda () (interactive) (pm/spell "de_DE")))
(global-set-key [?\C-c ?e] (lambda () (interactive) (pm/spell "en_GB")))
(defun pm/message-send ()
(unless (message-field-value gnus-delay-header)
(unless (string-equal pm/role "list")
(if (jl-epg-check-unique-keys (jl-mail-recipients))
(mml-secure-message-sign-encrypt)
(mml-secure-message-sign)))
(pm/spell)))
(defun pm/make-signature ()
"Check role, lang and level."
(cl-case pm/sig-level
(0 nil)
(1 " Peter")
(2 " Peter Münster")
(3 (concat " Peter Münster\n " (pm/phone)))
(4 (concat " Peter Münster\n"
(pm/address " ")
" " (pm/phone)))
(t
(setq pm/sig-level 0)
(pm/make-signature))))
(defun pm/message-setup ()
(cond (gnus-article-reply
(pm/update-role)
(pm/update-lang)
(incf pm/sig-level)
(save-excursion
(message-insert-signature)))
((save-excursion (message-goto-signature))
(pm/update-role)
(pm/update-lang))
(t
(pm/ask-role)
(let ((message-signature-insert-empty-line t))
(incf pm/sig-level)
(save-excursion
(message-insert-signature))))))
(add-hook 'gnus-message-setup-hook 'pm/message-setup)
(add-hook 'message-send-hook 'pm/message-send)
--8<---------------cut here---------------end--------------->8---
HTH,
--
Peter
_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english
next prev parent reply other threads:[~2016-02-15 11:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-11 22:47 Pietro
2016-02-11 23:34 ` Emanuel Berg
2016-02-12 14:05 ` Pietro
2016-02-13 3:27 ` Emanuel Berg
2016-02-13 4:42 ` Emanuel Berg
2016-02-18 16:11 ` Pietro
2016-02-19 0:17 ` Emanuel Berg
2016-02-19 10:20 ` Pietro
2016-03-05 17:38 ` Pietro
2016-03-05 17:43 ` Pietro
2016-03-06 5:53 ` Emanuel Berg
2016-02-19 13:53 ` B.V. Raghav
2016-02-19 20:15 ` Emanuel Berg
2016-02-20 7:12 ` B.V. Raghav
2016-02-15 11:12 ` Peter Münster [this message]
2016-02-12 0:07 ` Trigger spell checking before sending [flyspell?] Andrzej A. Filip
2016-02-12 0:21 ` Emanuel Berg
2016-02-12 8:58 ` Andrzej A. Filip
2016-02-13 4:47 ` Emanuel Berg
[not found] ` <mailman.4442.1455236524.843.info-gnus-english@gnu.org>
2016-02-12 9:41 ` Loris Bennett
2016-02-13 5:00 ` Emanuel Berg
2016-02-12 7:31 ` Trigger spell checking before sending Eric S Fraga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ziv2p6qe.fsf@roche-blanche.net \
--to=pmlists@free.fr \
--cc=info-gnus-english@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).