Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Trigger spell checking before sending
@ 2016-02-11 22:47 Pietro
  2016-02-11 23:34 ` Emanuel Berg
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Pietro @ 2016-02-11 22:47 UTC (permalink / raw)
  To: info-gnus-english

Hi all,

I normally use the ispell-buffer command before sending an email or
article to check what I have written, anyway sometimes I just forgot it.

Is there a way to configure Gnus to start the spell check before sending
the message ? I was thinking of an "hook"  which can be configured to
call a function - as ispell-buffer - triggered by the send command.

Does it make any sense at all ?

Thanks in advance,
P.



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-11 22:47 Trigger spell checking before sending Pietro
@ 2016-02-11 23:34 ` Emanuel Berg
  2016-02-12 14:05   ` Pietro
  2016-02-12  0:07 ` Trigger spell checking before sending [flyspell?] Andrzej A. Filip
  2016-02-12  7:31 ` Trigger spell checking before sending Eric S Fraga
  2 siblings, 1 reply; 22+ messages in thread
From: Emanuel Berg @ 2016-02-11 23:34 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> I normally use the ispell-buffer command before
> sending an email or article to check what I have
> written, anyway sometimes I just forgot it.
>
> Is there a way to configure Gnus to start the spell
> check before sending the message ? I was thinking of
> an "hook" which can be configured to call a function
> - as ispell-buffer - triggered by the send command.

There are many options to achieve what you want.
As for the hooks, yes:

    message-send-hook ; early

    message-send-mail-hook ; late
    message-send-news-hook

But that might not be the best move. Spelling can be
confusing with a lot of options and strange words will
pop up that makes your mind wander and you bring up
Emacs-w3m to Google it and you... oh, the message!

Or the opposite, when you are in a rush and you have
written a three liner and it yams every time you send
it, the thrice-accursed spellchecker starting
all over!

Instead, I'd do it like this:

Write one defun "message-send-no-check" that *always*
sends. It could be `C-u C-c C-c' or whatever.

Then write another defun
"message-send-ask-if-not-spelled" (`C-c C-c') which
checks a variable "is-spelled". This variable is
(re)set to nil when you create a new message (put it
in `message-setup-hook', likely). When you spell, the
variable is set to t.

If is-spelled is nil, message-send-ask-if-not-spelled
simply says "Hey, it is not spelled. Use `C-u C-c C-c'
to send anyway." If it is t, the message is sent
normally by means of `message-send-and-exit'.

This perhaps sounds complicated but it is super simple
- just setting, testing, and branching, like all
programming. Nothing new under the Sun Microsystems.

Here is what I have for spelling:

    http://user.it.uu.se/~embe8573/conf/emacs-init/spell-new.el

Note especially the `ispell-message' stuff! Which has
a bug by the way if you do `C-g' while spelling... But
you only get a wierd message (in the echo area, not
a message-message).

And for the message mode:

    http://user.it.uu.se/~embe8573/conf/emacs-init/gnus/message-my.el

Good luck! Ask more if need be!

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending [flyspell?]
  2016-02-11 22:47 Trigger spell checking before sending Pietro
  2016-02-11 23:34 ` Emanuel Berg
@ 2016-02-12  0:07 ` Andrzej A. Filip
  2016-02-12  0:21   ` Emanuel Berg
       [not found]   ` <mailman.4442.1455236524.843.info-gnus-english@gnu.org>
  2016-02-12  7:31 ` Trigger spell checking before sending Eric S Fraga
  2 siblings, 2 replies; 22+ messages in thread
From: Andrzej A. Filip @ 2016-02-12  0:07 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> wrote:
> Hi all,
>
> I normally use the ispell-buffer command before sending an email or
> article to check what I have written, anyway sometimes I just forgot it.
>
> Is there a way to configure Gnus to start the spell check before sending
> the message ? I was thinking of an "hook"  which can be configured to
> call a function - as ispell-buffer - triggered by the send command.
>
> Does it make any sense at all ?

Do you use flyspell?  It may deliver what you want in another way.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Spelling.html
> flyspell mode is a minor mode that performs automatic spell checking
> as you type. When it finds a word that it does not recognize, it
> highlights that word. Type M-x flyspell-mode to toggle Flyspell mode
> in the current buffer. To enable Flyspell mode in all text mode
> buffers, add flyspell-mode to text-mode-hook. See Hooks.
> When Flyspell mode highlights a word as misspelled, you can click on
> it with Mouse-2 to display a menu of possible corrections and
> actions. You can also correct the word by editing it manually in any
> way you like.  

-- 
A. Filip


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending [flyspell?]
  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
       [not found]   ` <mailman.4442.1455236524.843.info-gnus-english@gnu.org>
  1 sibling, 1 reply; 22+ messages in thread
From: Emanuel Berg @ 2016-02-12  0:21 UTC (permalink / raw)
  To: info-gnus-english

"Andrzej A. Filip" <andrzej.filip@gmail.com> writes:

> Do you use flyspell? It may deliver what you want in
> another way.

Ispell is better. Write, then spell, then send. Do it
all at once you loose your mindfulness and the result
will suffer. Flyspell sounds good but in practice too
many words that should be there aren't, which means
correct words will pop up as incorrect or unknown all
the time while typing. This is when the brain should
not focus on spelling but on conveying a message from
one person to another. The fingers should do the
spelling and in time they will. For the occasional
mistake spellcheck just before send is a much
better idea.

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-11 22:47 Trigger spell checking before sending Pietro
  2016-02-11 23:34 ` Emanuel Berg
  2016-02-12  0:07 ` Trigger spell checking before sending [flyspell?] Andrzej A. Filip
@ 2016-02-12  7:31 ` Eric S Fraga
  2 siblings, 0 replies; 22+ messages in thread
From: Eric S Fraga @ 2016-02-12  7:31 UTC (permalink / raw)
  To: info-gnus-english

On Thursday, 11 Feb 2016 at 22:47, Pietro wrote:
> Hi all,
>
> I normally use the ispell-buffer command before sending an email or
> article to check what I have written, anyway sometimes I just forgot it.

Maybe not the answer you were looking for but what about using, for
instance, flyspell-mode, and check and correct your spelling as you go?

-- 
: Eric S Fraga, GnuPG: 0xFFFCF67D
: in Emacs 25.0.90.1 + Ma Gnus v0.16 + evil-git-ff74cfb
: BBDB version 3.1.2 (2015-10-28 10:47:01+00:00)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending [flyspell?]
  2016-02-12  0:21   ` Emanuel Berg
@ 2016-02-12  8:58     ` Andrzej A. Filip
  2016-02-13  4:47       ` Emanuel Berg
  0 siblings, 1 reply; 22+ messages in thread
From: Andrzej A. Filip @ 2016-02-12  8:58 UTC (permalink / raw)
  To: info-gnus-english

Emanuel Berg <embe8573@student.uu.se> wrote:
> "Andrzej A. Filip" <andrzej.filip@gmail.com> writes:
>
>> Do you use flyspell? It may deliver what you want in
>> another way.
>
> Ispell is better. Write, then spell, then send. Do it
> all at once you loose your mindfulness and the result
> will suffer. Flyspell sounds good but in practice too
> many words that should be there aren't, which means
> correct words will pop up as incorrect or unknown all
> the time while typing. This is when the brain should
> not focus on spelling but on conveying a message from
> one person to another. The fingers should do the
> spelling and in time they will. For the occasional
> mistake spellcheck just before send is a much
> better idea.

My opinion is quite different but I sure you are the expert in judging
what is the best for YOU :-) .  I am sure flyspell is a thing worth to
_try_ .  I am quite sure it will not be the best choice _for everyone_ .

After a few months+ of flyspelling I get bad spelling marks hardly ever.


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending [flyspell?]
       [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
  0 siblings, 1 reply; 22+ messages in thread
From: Loris Bennett @ 2016-02-12  9:41 UTC (permalink / raw)
  To: info-gnus-english

Emanuel Berg <embe8573@student.uu.se> writes:

> "Andrzej A. Filip" <andrzej.filip@gmail.com> writes:
>
>> Do you use flyspell? It may deliver what you want in
>> another way.
>
> Ispell is better. Write, then spell, then send. Do it
> all at once you loose your mindfulness and the result
> will suffer.

We didn't have mindfulness (or spell-checking, for that matter) when I
was growing up.  Historians of the future will tell us (or themselves)
whether the results suffered.

> Flyspell sounds good but in practice too
> many words that should be there aren't, which means
> correct words will pop up as incorrect or unknown all
> the time while typing.

To avoid this, add the words to your personal dictionary (don't you have
to do with ispell too?).

> This is when the brain should not focus on spelling but on conveying a
> message from one person to another. The fingers should do the spelling
> and in time they will. For the occasional mistake spellcheck just
> before send is a much better idea.

When I'm writing English, my first language, flyspell tends to pickup
typos rather than real spelling mistakes.  In German, my second
language, I'm more likely to misspell a word (although German spelling
is easier, even if they do change it every few years ...)

It would be interesting to know whether there is any empirical evidence
as to whether being corrected as you go à la flyspell as opposed to
doing a final spell-check ispell-style has any effect on the quality of
one's spelling over time.

Cheers,

Loris

-- 
This signature is currently under construction.
_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-11 23:34 ` Emanuel Berg
@ 2016-02-12 14:05   ` Pietro
  2016-02-13  3:27     ` Emanuel Berg
                       ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Pietro @ 2016-02-12 14:05 UTC (permalink / raw)
  To: info-gnus-english

Emanuel Berg <embe8573@student.uu.se> writes:

> Pietro <pulsarpietro@posteo.net> writes:
>
>> I normally use the ispell-buffer command before
>> sending an email or article to check what I have
>> written, anyway sometimes I just forgot it.
>>
>> Is there a way to configure Gnus to start the spell
>> check before sending the message ? I was thinking of
>> an "hook" which can be configured to call a function
>> - as ispell-buffer - triggered by the send command.
>
> There are many options to achieve what you want.
> As for the hooks, yes:
>
>     message-send-hook ; early
>
>     message-send-mail-hook ; late
>     message-send-news-hook
>
> But that might not be the best move. Spelling can be
> confusing with a lot of options and strange words will
> pop up that makes your mind wander and you bring up
> Emacs-w3m to Google it and you... oh, the message!
>
> Or the opposite, when you are in a rush and you have
> written a three liner and it yams every time you send
> it, the thrice-accursed spellchecker starting
> all over!
>
> Instead, I'd do it like this:
>
> Write one defun "message-send-no-check" that *always*
> sends. It could be `C-u C-c C-c' or whatever.
>
> Then write another defun
> "message-send-ask-if-not-spelled" (`C-c C-c') which
> checks a variable "is-spelled". This variable is
> (re)set to nil when you create a new message (put it
> in `message-setup-hook', likely). When you spell, the
> variable is set to t.
>
> If is-spelled is nil, message-send-ask-if-not-spelled
> simply says "Hey, it is not spelled. Use `C-u C-c C-c'
> to send anyway." If it is t, the message is sent
> normally by means of `message-send-and-exit'.
>
> This perhaps sounds complicated but it is super simple
> - just setting, testing, and branching, like all
> programming. Nothing new under the Sun Microsystems.
>
> Here is what I have for spelling:
>
>     http://user.it.uu.se/~embe8573/conf/emacs-init/spell-new.el
>
> Note especially the `ispell-message' stuff! Which has
> a bug by the way if you do `C-g' while spelling... But
> you only get a wierd message (in the echo area, not
> a message-message).
>
> And for the message mode:
>
>     http://user.it.uu.se/~embe8573/conf/emacs-init/gnus/message-my.el
>
> Good luck! Ask more if need be!
Thanks for all your answers guys.

Well my first language isn't English and I do like the idea of focusing
on what I am writing and only at a second time run the spell checker to
make sure everything is correct, I did not know of fly spell but I would
prefer not to use it. I am pretty sure there is not an unique answer to
this matter and everybody has his own preferences, this is why a fully
customizable tools like Gnus comes in handy.

The more I use it the more I like it.

I prefer to run the spell checker at a separate stage since it takes a
bit of concentration to me when I am writing in English I couldn't cope
with external interactions/distractions of any sort very well, however
this is a *pretty personal* view.

I went through the links you pointed me in and they gave me the
spark to more patiently read the Gnus manual and there I found these
these few lines :

Page 138, right at the top:

(add-hook 'message-send-hook #'ispell-message)

Even though I was excited at the idea of writing my own function
everything was already there and I haven't been the first to think about
it :-)

Now that I got this working my following question is : would it be possible
to auto-detect the language the spell checker should check ? 

Alternatively I am thinking of writing a function which asks the user
for the language the ispell function should check for, it does not need
to accept all the languages and for instance I would be more than happy to have
something like that :

Mini-buffer says: [Which language ?[e : English, i: Italian]

In this manner I do not need to remember all the dictionary names but I
could set up a simple mapping inside my functions for the ones I more
often using.

For example typing 'e' would cause:

(ispell-change-dictionary 'english)
(ispell-message)

Such function would be inserted among the 'message-send-hook functions'
list.

Am I talking completely non-sense ?





^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-12 14:05   ` Pietro
@ 2016-02-13  3:27     ` Emanuel Berg
  2016-02-13  4:42     ` Emanuel Berg
  2016-02-15 11:12     ` Peter Münster
  2 siblings, 0 replies; 22+ messages in thread
From: Emanuel Berg @ 2016-02-13  3:27 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> I prefer to run the spell checker at a separate
> stage since it takes a bit of concentration to me
> when I am writing in English I couldn't cope with
> external interactions/distractions of any sort very
> well ...

Indeed, there is that, but there is also the problem
of the incomplete wordlists.

When I just now wrote in Swedish only two short
paragraphs, and after that did spelling, it found the
following words -

    Sydostpassaden
    Humboldtströmmen
    Galapagosströmmarna
    Sydekvatorialströmmarna
    Pizarro
    guldmakrill
    flygfiskbete

- which are all correct what I can see. But it also
found one real mistake so I'm not complaining. But to
have it mark all those words as potentially trouble
while I write the paragraphs - that would be equal to
not writing but instead go back all the time and
verify the correct-but-indicated words...

> Now that I got this working my following question is
> would it be possible to auto-detect the language the
> spell checker should check ?

It is possible but you have to find an algorithm to
detect the language - go hunt. If you find one, it is
easy to implement. But I don't think it is worth the
effort unless you find one like instantly and really
want it.

> Alternatively I am thinking of writing a function
> which asks the user for the language the ispell
> function should check for, it does not need to
> accept all the languages and for instance I would be
> more than happy to have something like that :
>
> Mini-buffer says: [Which language ?[e : English, i:
> Italian]

That's better, do that, or have two shortcuts to two
functions which is what I do:

(defun is-code () (member major-mode '(c++-mode
                                       emacs-lisp-mode
                                       sh-mode) )) ; add more here
(defun is-message () (eq major-mode 'message-mode))

(defun do-spell-dict (dict)
  "Spell with DICT.
If there is a region, `ispell-region'.
if in a code mode, `ispell-comments-and-strings'.
if in `message-mode', do `ispell-message'.
Otherwise, spell everything with `ispell-buffer'."
  (ispell-change-dictionary dict)
  (save-excursion
    (cond
     (mark-active   (ispell-region (mark) (point)))
     ((is-message)  (ispell-message))
     ((is-code)     (ispell-comments-and-strings))
     (t             (ispell-buffer)) )))

(defun spell-swedish ()
  (interactive)
  (do-spell-dict swe-dict))
(defun spell-english ()
  (interactive)
  (do-spell-dict eng-dict))

All code: http://user.it.uu.se/~embe8573/conf/emacs-init/spell-new.el

Then:

    (define-prefix-command       'C-o-prefix)
    (super-global-set-key "\C-o" 'C-o-prefix)

    (global-set-key "\C-oe" #'spell-english)
    (global-set-key "\C-os" #'spell-swedish)

> Am I talking completely non-sense ?

Yes. The rest of the message was good tho :)

-- 
underground experts united
http://user.it.uu.se/~embe8573


_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  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-15 11:12     ` Peter Münster
  2 siblings, 1 reply; 22+ messages in thread
From: Emanuel Berg @ 2016-02-13  4:42 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> Alternatively I am thinking of writing a function
> which asks the user for the language the ispell
> function should check for, it does not need to
> accept all the languages and for instance I would be
> more than happy to have something like that :
>
> Mini-buffer says: [Which language ?[e : English, i:
> Italian]

I still don't like the idea of having this complicated
a thing in a hook; on the other hand, I just realized
that the code I provided isn't compatible with the
hook solution, so it isn't of any help if you are set
on that idea.

OK, try this, only change the Swedish stuff for
Italian, no?

(defun message-spell-before-send (lang-char)
  (interactive "s(e)nglish or (s)wedish: ")
  (let ((lang (pcase lang-char
                ("e" "american-insane") ; these has to be added outside of Emacs
                ("s" "svenska") )))
    (if lang
        (progn
          (ispell-change-dictionary lang) ; N.B. side-effect - this isn't reset
          (ispell-message) )
      (message "Spelling not done - no support for: %s" lang-char) )))

If you don't want to spell, just hit RET.

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending [flyspell?]
  2016-02-12  8:58     ` Andrzej A. Filip
@ 2016-02-13  4:47       ` Emanuel Berg
  0 siblings, 0 replies; 22+ messages in thread
From: Emanuel Berg @ 2016-02-13  4:47 UTC (permalink / raw)
  To: info-gnus-english

"Andrzej A. Filip" <andrzej.filip@gmail.com> writes:

> My opinion is quite different but I sure you are the
> expert in judging what is the best for YOU :-) .
> I am sure flyspell is a thing worth to _try_ . I am
> quite sure it will not be the best choice _for
> everyone_ .
>
> After a few months+ of flyspelling I get bad
> spelling marks hardly ever.

Indeed, that would make flyspelling much better.

I'm on Debian where I use the "american-insane"
dictionary, but it isn't insane enough by far.

Either you have a better dictionary, or you write in
a style that has less words that are even beyond the
realms of insanity... (Ha ha, I always said Emacs and
acid are quite close :))

PS. In this message: "flyspelling" marked! DS.

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending [flyspell?]
  2016-02-12  9:41     ` Loris Bennett
@ 2016-02-13  5:00       ` Emanuel Berg
  0 siblings, 0 replies; 22+ messages in thread
From: Emanuel Berg @ 2016-02-13  5:00 UTC (permalink / raw)
  To: info-gnus-english

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:

> We didn't have mindfulness (or spell-checking, for
> that matter) when I was growing up. Historians of
> the future will tell us (or themselves) whether the
> results suffered.

When we were growing up there wasn't Google, YouTube,
MSN, Facebook, Twitter either. And in school you were
reading, writing, and doing math.

But just because the old times weren't like that,
doesn't mean the "old timers" are immune to modern-day
lack of mindfulness...

And as for the youngsters put them on a raft in the
Pacific ocean and have them do fishing and reading
under the stars a couple of weeks and they will be
very mindful indeed...

So there is both concern and hope!

> To avoid this, add the words to your personal
> dictionary (don't you have to do with ispell too?).

Yes, but it is not enough! It is just too many words
which are correct that turns up.

They turn up with ispell as well but it is another
thing to deal with all that quickly once when you do
not type and you yourself has decided "I'm going to
deal with that" compared to having to do that because
your fingers are slippery and Emacs won't shut up
about it!

> When I'm writing English, my first language,
> flyspell tends to pickup typos rather than real
> spelling mistakes.

OK, here, I never thought about that distinction.

> It would be interesting to know whether there is any
> empirical evidence as to whether being corrected as
> you go à la flyspell as opposed to doing a final
> spell-check ispell-style has any effect on the
> quality of one's spelling over time.

Interesting indeed. I don't have an educated guess.

But I do have an educated guess with respect to the
quality of the writing - here, ispell wins.

Because with ispell there is more enjoyment,
relaxation, and focus on getting the thoughts on paper
(screen) rather than - "is this word correct?
should I add it?" in the middle of writing a sentence!
It makes sense. That sentence.

PS. In this message: "MSN". DS.

-- 
underground experts united
http://user.it.uu.se/~embe8573


_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-12 14:05   ` Pietro
  2016-02-13  3:27     ` Emanuel Berg
  2016-02-13  4:42     ` Emanuel Berg
@ 2016-02-15 11:12     ` Peter Münster
  2 siblings, 0 replies; 22+ messages in thread
From: Peter Münster @ 2016-02-15 11:12 UTC (permalink / raw)
  To: info-gnus-english

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-13  4:42     ` Emanuel Berg
@ 2016-02-18 16:11       ` Pietro
  2016-02-19  0:17         ` Emanuel Berg
  0 siblings, 1 reply; 22+ messages in thread
From: Pietro @ 2016-02-18 16:11 UTC (permalink / raw)
  To: info-gnus-english

Emanuel Berg <embe8573@student.uu.se> writes:

> Pietro <pulsarpietro@posteo.net> writes:
>
>> Alternatively I am thinking of writing a function
>> which asks the user for the language the ispell
>> function should check for, it does not need to
>> accept all the languages and for instance I would be
>> more than happy to have something like that :
>>
>> Mini-buffer says: [Which language ?[e : English, i:
>> Italian]
>
> I still don't like the idea of having this complicated
> a thing in a hook; on the other hand, I just realized
> that the code I provided isn't compatible with the
> hook solution, so it isn't of any help if you are set
> on that idea.
>
> OK, try this, only change the Swedish stuff for
> Italian, no?
>
> (defun message-spell-before-send (lang-char)
>   (interactive "s(e)nglish or (s)wedish: ")
>   (let ((lang (pcase lang-char
>                 ("e" "american-insane") ; these has to be added outside of Emacs
>                 ("s" "svenska") )))
>     (if lang
>         (progn
>           (ispell-change-dictionary lang) ; N.B. side-effect - this isn't reset
>           (ispell-message) )
>       (message "Spelling not done - no support for: %s" lang-char) )))
>
> If you don't want to spell, just hit RET.
Hi,
sorry for my late reply, I was busy ... working! Ouch!

Thanks a lot for your answers guys, much appreciated :-)

I would like to implement one of the previous follow up which explained how to auto
detect the buffer's language but for now I would be more than happy with
this simple and good solution, the function works fine when I call it
from M-x "name-function" but something strange happens when that is
called by the message-send hook:

run-hooks: Wrong number of arguments: (lambda (lang-char) (interactive
"s(e)nglish or (s)wedish: ") (let ((lang (cond ((equal lang-char "e")
(let nil "british")) ((equal lang-char "i") (let nil "italiano")) (t
nil)))) (if lang (progn (ispell-change-dictionary lang)
(ispell-message)) (message "Spelling not done - no support for: %s"
lang-char)))), 0

This is what I get in my mini-buffer when I send my email, any thoughts ?
I am new to Emacs Lisp therefore I could some  silly mistake.

Thanks a lot.
Pietro



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-18 16:11       ` Pietro
@ 2016-02-19  0:17         ` Emanuel Berg
  2016-02-19 10:20           ` Pietro
  2016-02-19 13:53           ` B.V. Raghav
  0 siblings, 2 replies; 22+ messages in thread
From: Emanuel Berg @ 2016-02-19  0:17 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> run-hooks: Wrong number of arguments [...]
>
> This is what I get in my mini-buffer when I send my
> email, any thoughts?

OK, I see the problem, it doesn't get
called interactively.

Try this instead:

(defun spell-before-send ()
  (let*((lang-input (read-from-minibuffer "Language [e or s]: "))
        (lang (pcase lang-input
                ("e" "american-insane")
                ("s" "svenska") )))
    (when lang
      (ispell-change-dictionary lang)
      (ispell-message) )))

You have to change the interface at the second line,
as well as the dictionaries at lines four and five,
of course.

Another thing - here is a hint how to do hooks without
the lambda stuff. It amounts to the same but gives
more control and more easy-to-handle code.

First check out if you have anything in the hook
variable already. If you do, and you want it, put it
before (or after) the third line below.

Then, evaluate the commented (first) line, then
evaluate the function (at the second line), then set
the hook to the hook function (the fourth line).

;; (setq message-send-hook nil)
(defun message-send-hook-f ()
  (spell-before-send) )
(setq message-send-hook #'message-send-hook-f)

> I am new to Emacs Lisp therefore I could some
> silly mistake.

You don't have to be new to Lisp to do that.

Is there anything you don't understand in the code?
If it is, find out using the documentation (online
help: `C-h f', `C-h v', etc.) *or* ask here. ("Online"
= not on paper :))

When you understand it move on to do other things :)

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-19  0:17         ` Emanuel Berg
@ 2016-02-19 10:20           ` Pietro
  2016-03-05 17:38             ` Pietro
  2016-02-19 13:53           ` B.V. Raghav
  1 sibling, 1 reply; 22+ messages in thread
From: Pietro @ 2016-02-19 10:20 UTC (permalink / raw)
  To: info-gnus-english

Emanuel Berg <embe8573@student.uu.se> writes:

> Pietro <pulsarpietro@posteo.net> writes:
>
>> run-hooks: Wrong number of arguments [...]
>>
>> This is what I get in my mini-buffer when I send my
>> email, any thoughts?
>
> OK, I see the problem, it doesn't get
> called interactively.
>
> Try this instead:
>
> (defun spell-before-send ()
>   (let*((lang-input (read-from-minibuffer "Language [e or s]: "))
>         (lang (pcase lang-input
>                 ("e" "american-insane")
>                 ("s" "svenska") )))
>     (when lang
>       (ispell-change-dictionary lang)
>       (ispell-message) )))
>
Thanks a lot, it works fine now.
> You have to change the interface at the second line,
> as well as the dictionaries at lines four and five,
> of course.
>
> Another thing - here is a hint how to do hooks without
> the lambda stuff. It amounts to the same but gives
> more control and more easy-to-handle code.
>
> First check out if you have anything in the hook
> variable already. If you do, and you want it, put it
> before (or after) the third line below.
>
> Then, evaluate the commented (first) line, then
> evaluate the function (at the second line), then set
> the hook to the hook function (the fourth line).
>
> ;; (setq message-send-hook nil)
> (defun message-send-hook-f ()
>   (spell-before-send) )
> (setq message-send-hook #'message-send-hook-f)
>
>> I am new to Emacs Lisp therefore I could some
>> silly mistake.
>
> You don't have to be new to Lisp to do that.
>
> Is there anything you don't understand in the code?
> If it is, find out using the documentation (online
> help: `C-h f', `C-h v', etc.) *or* ask here. ("Online"
> = not on paper :))
>
No I fully understand it, it does not look that far from the Racket, the
Lisp dialect I have studied
> When you understand it move on to do other things :)
Sure, and thanks a lot, I hope I will give something back to the
community soon!



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-19  0:17         ` Emanuel Berg
  2016-02-19 10:20           ` Pietro
@ 2016-02-19 13:53           ` B.V. Raghav
  2016-02-19 20:15             ` Emanuel Berg
  1 sibling, 1 reply; 22+ messages in thread
From: B.V. Raghav @ 2016-02-19 13:53 UTC (permalink / raw)
  To: info-gnus-english

>
> OK, I see the problem, it doesn't get
> called interactively.
>
> Try this instead:
>
> (defun spell-before-send ()
>   (let*((lang-input (read-from-minibuffer "Language [e or s]: "))

Would it have been possible to hook the _interactively_defined_ `spell-before-send'
as follows:

(add-hook message-send-hook
          (lambda ()
                  "Calls spell-before-send interactively"
                  (call-interactively 'spell-before-send)))

If so, please enlighten the difference.

Thanks,
r
-- 
(B.V. Raghav)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-19 13:53           ` B.V. Raghav
@ 2016-02-19 20:15             ` Emanuel Berg
  2016-02-20  7:12               ` B.V. Raghav
  0 siblings, 1 reply; 22+ messages in thread
From: Emanuel Berg @ 2016-02-19 20:15 UTC (permalink / raw)
  To: info-gnus-english

"B.V. Raghav" <bvraghav@iitk.ac.in> writes:

>> OK, I see the problem, it doesn't get called
>> interactively. Try this instead: (defun
>> spell-before-send () (let*((lang-input
>> (read-from-minibuffer "Language [e or s]: "))
>
> Would it have been possible to hook the
> _interactively_defined_ `spell-before-send' as
> follows:
>
> (add-hook message-send-hook (lambda () "Calls
> spell-before-send interactively" (call-interactively
> 'spell-before-send)))
>
> If so, please enlighten the difference.

I would prefer not to use `add-hook' nor the `lambda'
notation but in essence a non-interactive function
that prompts for input vs. an interactive function
that is called interactively from Elisp code - that
should amount to the same what I can see.

If you want the function to be used interactively *as
well* (i.e., the user invokes it directly) then
obviously it should be interactive.

Or perhaps you are benefited from the
`interactive' interface.

From a principal/esthetic point of view interactive
stuff doesn't really belong in hooks because those are
all about automatization. But in reality if that is
what you want and it works - why not?

Try it:

(require 'message)

(defun spell-before-send (lang-input)
  (interactive "sLanguage [e or s]: ")
  (let((lang (pcase lang-input
                ("e" "american-insane")
                ("s" "svenska") )))
    (when lang
      (ispell-change-dictionary lang)
      (ispell-message) )))

;; (setq message-send-hook nil)
(defun message-send-hook-f ()
  (call-interactively #'spell-before-send) )
(setq message-send-hook #'message-send-hook-f)

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-19 20:15             ` Emanuel Berg
@ 2016-02-20  7:12               ` B.V. Raghav
  0 siblings, 0 replies; 22+ messages in thread
From: B.V. Raghav @ 2016-02-20  7:12 UTC (permalink / raw)
  To: info-gnus-english

Emanuel Berg <embe8573@student.uu.se> writes:

> "B.V. Raghav" <bvraghav@iitk.ac.in> writes:
>
>>> OK, I see the problem, it doesn't get called
>>> interactively. Try this instead: (defun
>>> spell-before-send () (let*((lang-input
>>> (read-from-minibuffer "Language [e or s]: "))
>>
>> Would it have been possible to hook the
>> _interactively_defined_ `spell-before-send' as
   [snip]
>> If so, please enlighten the difference.
>
> I would prefer not to use `add-hook' nor the `lambda'
> notation but in essence a non-interactive function
  [snip]
> From a principal/esthetic point of view interactive
> stuff doesn't really belong in hooks because those are
> all about automatization. But in reality if that is
> what you want and it works - why not?

Thanks,
r
-- 
(B.V. Raghav)


^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-02-19 10:20           ` Pietro
@ 2016-03-05 17:38             ` Pietro
  2016-03-05 17:43               ` Pietro
  0 siblings, 1 reply; 22+ messages in thread
From: Pietro @ 2016-03-05 17:38 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> Emanuel Berg <embe8573@student.uu.se> writes:
>
>> Pietro <pulsarpietro@posteo.net> writes:
>>
>>> run-hooks: Wrong number of arguments [...]
>>>
>>> This is what I get in my mini-buffer when I send my
>>> email, any thoughts?
>>
>> OK, I see the problem, it doesn't get
>> called interactively.
>>
>> Try this instead:
>>
>> (defun spell-before-send ()
>>   (let*((lang-input (read-from-minibuffer "Language [e or s]: "))
>>         (lang (pcase lang-input
>>                 ("e" "american-insane")
>>                 ("s" "svenska") )))
>>     (when lang
>>       (ispell-change-dictionary lang)
>>       (ispell-message) )))
How can I modify this function to skip the spell checking ? I would like to
have a third choice which directly sends the message straight away.

> Thanks a lot, it works fine now.
>> You have to change the interface at the second line,
>> as well as the dictionaries at lines four and five,
>> of course.
>>
>> Another thing - here is a hint how to do hooks without
>> the lambda stuff. It amounts to the same but gives
>> more control and more easy-to-handle code.
>>
>> First check out if you have anything in the hook
>> variable already. If you do, and you want it, put it
>> before (or after) the third line below.
>>
>> Then, evaluate the commented (first) line, then
>> evaluate the function (at the second line), then set
>> the hook to the hook function (the fourth line).
>>
>> ;; (setq message-send-hook nil)
>> (defun message-send-hook-f ()
>>   (spell-before-send) )
>> (setq message-send-hook #'message-send-hook-f)
>>
>>> I am new to Emacs Lisp therefore I could some
>>> silly mistake.
>>
>> You don't have to be new to Lisp to do that.
>>
>> Is there anything you don't understand in the code?
>> If it is, find out using the documentation (online
>> help: `C-h f', `C-h v', etc.) *or* ask here. ("Online"
>> = not on paper :))
>>
> No I fully understand it, it does not look that far from the Racket, the
> Lisp dialect I have studied
>> When you understand it move on to do other things :)
> Sure, and thanks a lot, I hope I will give something back to the
> community soon!
I am afraid I am not ready yet ... :-(



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-03-05 17:38             ` Pietro
@ 2016-03-05 17:43               ` Pietro
  2016-03-06  5:53                 ` Emanuel Berg
  0 siblings, 1 reply; 22+ messages in thread
From: Pietro @ 2016-03-05 17:43 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> Pietro <pulsarpietro@posteo.net> writes:
>
>> Emanuel Berg <embe8573@student.uu.se> writes:
>>
>>> Pietro <pulsarpietro@posteo.net> writes:
>>>
>>>> run-hooks: Wrong number of arguments [...]
>>>>
>>>> This is what I get in my mini-buffer when I send my
>>>> email, any thoughts?
>>>
>>> OK, I see the problem, it doesn't get
>>> called interactively.
>>>
>>> Try this instead:
>>>
>>> (defun spell-before-send ()
>>>   (let*((lang-input (read-from-minibuffer "Language [e or s]: "))
>>>         (lang (pcase lang-input
>>>                 ("e" "american-insane")
>>>                 ("s" "svenska") )))
>>>     (when lang
>>>       (ispell-change-dictionary lang)
>>>       (ispell-message) )))
> How can I modify this function to skip the spell checking ? I would like to
> have a third choice which directly sends the message straight away.
>
Oh, gosh, I just needed to press enter, and since lang is null at that
point my message is sent straightaway ... :-)

>> Thanks a lot, it works fine now.
>>> You have to change the interface at the second line,
>>> as well as the dictionaries at lines four and five,
>>> of course.
>>>
>>> Another thing - here is a hint how to do hooks without
>>> the lambda stuff. It amounts to the same but gives
>>> more control and more easy-to-handle code.
>>>
>>> First check out if you have anything in the hook
>>> variable already. If you do, and you want it, put it
>>> before (or after) the third line below.
>>>
>>> Then, evaluate the commented (first) line, then
>>> evaluate the function (at the second line), then set
>>> the hook to the hook function (the fourth line).
>>>
>>> ;; (setq message-send-hook nil)
>>> (defun message-send-hook-f ()
>>>   (spell-before-send) )
>>> (setq message-send-hook #'message-send-hook-f)
>>>
>>>> I am new to Emacs Lisp therefore I could some
>>>> silly mistake.
>>>
>>> You don't have to be new to Lisp to do that.
>>>
>>> Is there anything you don't understand in the code?
>>> If it is, find out using the documentation (online
>>> help: `C-h f', `C-h v', etc.) *or* ask here. ("Online"
>>> = not on paper :))
>>>
>> No I fully understand it, it does not look that far from the Racket, the
>> Lisp dialect I have studied
>>> When you understand it move on to do other things :)
>> Sure, and thanks a lot, I hope I will give something back to the
>> community soon!
> I am afraid I am not ready yet ... :-(

Definitely not ready !



^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: Trigger spell checking before sending
  2016-03-05 17:43               ` Pietro
@ 2016-03-06  5:53                 ` Emanuel Berg
  0 siblings, 0 replies; 22+ messages in thread
From: Emanuel Berg @ 2016-03-06  5:53 UTC (permalink / raw)
  To: info-gnus-english

Pietro <pulsarpietro@posteo.net> writes:

> Oh, gosh, I just needed to press enter, and since
> lang is null at that point my message is sent
> straightaway ... :-)

Yes, only "null" is C, in Lisp it is nil.

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-03-06  5:53 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-11 22:47 Trigger spell checking before sending 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
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

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).