info-gnus-english
[Top][All Lists]
Advanced

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

Re: Trigger spell checking before sending


From: Peter Münster
Subject: Re: Trigger spell checking before sending
Date: Mon, 15 Feb 2016 12:12:41 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

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




reply via email to

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