(defun gnus-set-dictionary ()
"Determine what dictionary to use based on the current message."
(let ((dictionary))
(if (message-news-p)
(setq dictionary "british")
(setq dictionary "dutch"))
(dolist (item gnus-dictionaries)
(when (string-match (car item) gnus-newsgroup-name)
(setq dictionary (cdr item))))
(ispell-change-dictionary dictionary)))
(add-hook 'message-mode-hook 'gnus-set-dictionary)
Default e-mail is in Dutch and newsgroup messages in English. But
sometimes it could be that it is otherwise. For example Dutch newsgroups
wants Dutch Messages. That is why I use gnus-dictionaries to check
for an exception.
I only have one problem. At the moment I need to use:
"^nl\\.\\|\\.nl\\.\\|\\.nl$"
for the regular expression. I would prefer to use something like:
"[\\.^]nl[\\.$]"
But that does not work. Is there another way to make the regular
expression simpler?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
CW> I only have one problem. At the moment I need to use:
CW> "^nl\\.\\|\\.nl\\.\\|\\.nl$"
CW> for the regular expression. I would prefer to use something like:
CW> "[\\.^]nl[\\.$]"
CW> But that does not work. Is there another way to make the regular
CW> expression simpler?
The simplest solution is probably to use split-string, since you'll get
all the path components that way:
(member "nl" (split-string "X.nl.X" "\\."))
Your regex character class of [\\.^] doesn't work because it's matching
the character ^ and not the beginning of the line. Same for the [\\.$]
class.
If the '.' character is not in your word class (it shouldn't be), you
can use
(string-match "\\bnl\\b" "X.nl.X")
which is probably the best regex-based solution, so it will work with
your existing code. You could also use \< and \> but that's probably
unnecessary. Look at the ELisp manual, section "Backslash Constructs in
Regular Expressions" for details.
Ted
> CW> I only have one problem. At the moment I need to use:
> CW> "^nl\\.\\|\\.nl\\.\\|\\.nl$"
> CW> for the regular expression. I would prefer to use something like:
> CW> "[\\.^]nl[\\.$]"
>
> CW> But that does not work. Is there another way to make the regular
> CW> expression simpler?
> If the '.' character is not in your word class (it shouldn't be), you
> can use
>
> (string-match "\\bnl\\b" "X.nl.X")
This also matches:
(string-match "\\bnl\\b" "X-nl-X")
But I do not think that is a problem. So I now use "\\bnl\\b". That is a
lot clearer as "^nl\\.\\|\\.nl\\.\\|\\.nl$" and easier to adopt when
another language has to be added.
Thanks.
>> (string-match "\\bnl\\b" "X.nl.X")
CW> This also matches:
CW> (string-match "\\bnl\\b" "X-nl-X")
CW> But I do not think that is a problem.
I think you can modify the syntax table to accomodate this, making '-' a
member of the word class, but you have to check the manual for the
details.
Ted
>>> (string-match "\\bnl\\b" "X.nl.X")
>
> CW> This also matches:
> CW> (string-match "\\bnl\\b" "X-nl-X")
>
> CW> But I do not think that is a problem.
>
> I think you can modify the syntax table to accomodate this, making '-' a
> member of the word class, but you have to check the manual for the
> details.
I would need to put a lot more in the word class, because the original
problem was that before nl needs to be a '.' or the beginning of the
line and after a '.' or the end of the line. So in principal the regular
expression is to lenient, but the chance that it is a real problem is
very small. When that is the case, I need to use my original expression
again. But it is used for parsing newsgroup names, so I think the
expression is good enough.