Discussion:
spell checking message buffer
Peter Münster
2014-04-21 04:22:08 UTC
Permalink
Hi,

How would it be possible to spell-check (M-x ispell) only the subject
line and in the body only the unquoted lines please?

TIA for any hints,
--
Peter
Katsumi Yamaoka
2014-04-21 05:38:38 UTC
Permalink
Post by Peter Münster
How would it be possible to spell-check (M-x ispell) only the subject
line and in the body only the unquoted lines please?
TIA for any hints,
A quick hack is here:
Peter Münster
2014-04-21 19:09:33 UTC
Permalink
(defun my-ispell-message ()
Thanks! Would it make sense to integrate it into Gnus?
--
Peter
Ted Zlatanov
2014-09-24 21:57:40 UTC
Permalink
(defun my-ispell-message ()
PM> Thanks! Would it make sense to integrate it into Gnus?

I'm in favor.

Ted
Peter Münster
2014-09-25 22:05:49 UTC
Permalink
Post by Ted Zlatanov
(defun my-ispell-message ()
PM> Thanks! Would it make sense to integrate it into Gnus?
I'm in favor.
Before doing that, here is a slightly enhanced version:

--8<---------------cut here---------------start------------->8---
(defun my-ispell-message ()
"Do ispell on the subject line and the unquoted body lines."
(interactive)
(let ((case-fold-search t)
(res t)
start end)
(message-goto-subject)
(setq end (point))
(beginning-of-line)
(while (memq (char-after) '(?\t ? ))
(forward-line -1))
(when (looking-at "subject:[\t\n ]*\\(?:\\(fwd\\|re\\):[\t\n ]*\\)*")
(setq start (match-end 0)))
(when (< start end)
(unless (ispell-region start end) (setq res nil)))
(message-goto-body)
(while (not (eobp))
(while (and (not (eobp))
(or (looking-at message-cite-prefix-regexp)
(looking-at "<#.*>$")
(looking-at "[\t ]*$")))
(forward-line 1))
(setq start (point))
(while (not (or (eobp)
(looking-at message-cite-prefix-regexp)
(looking-at "<#.*>$")
(looking-at "[\t ]*$")))
(forward-line 1))
(setq end (point-marker))
(unless (ispell-region start end) (setq res nil))
(goto-char end))
(when (markerp end)
(set-marker end nil))
res))
--8<---------------cut here---------------end--------------->8---

First, mml-tags are excluded from spell-checking.
Second, when ispell fails, the function returns nil.

The latter is useful, when this function is called from the
message-send-hook, and while spell-checking the user sees big mistakes
and wants to edit further the message and wishes to stop the sending.
See for example the last line of my message-send-hook:

--8<---------------cut here---------------start------------->8---
(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)))
(or (pm/spell) (keyboard-quit)))) ; here the sending can be cancelled
--8<---------------cut here---------------end--------------->8---
--
Peter
Lars Ingebrigtsen
2015-01-28 06:16:23 UTC
Permalink
(defun my-ispell-message ()
"Do ispell on the subject line and the unquoted body lines."
(interactive)
Looks good. Can you submit a patch to message.el along with some
documentation in message.texi?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
Peter Münster
2015-01-28 16:45:11 UTC
Permalink
Post by Lars Ingebrigtsen
(defun my-ispell-message ()
"Do ispell on the subject line and the unquoted body lines."
(interactive)
Looks good. Can you submit a patch to message.el along with some
documentation in message.texi?
I've just discovered a reference to `ispell-message' in message.el. It seems,
that `ispell-message' is exactly doing the same as `my-ispell-message'.
It's even mentioned in the message manual. I should have looked there
before asking for help...
--
Peter
Loading...