For a small hack I needed to make a guess about what language a text is
written in. This in order to automatically set the correct `predictive'
dictionary. I could not find any existing elisp code that did the same
thing so I wrote it myself.
I present to you `guess-language':
(defun guess-language ()
"Guess in what language text after point is written in.
In a very simple manner, guess in what language text after point
is written in. It is done by looking for certain words common to
a specific language. Currently Swedish (sv) and English (en) is
supported. Returns a symbol."
(let ((lang-words '((sv . ("det" "att" "och" "en" "som"))
(en . ("the" "a" "of" "and" "an" "to"))))
found)
(catch 'found
(dolist (lang lang-words)
(let ((words (cdr lang)))
(dolist (word words)
(save-excursion
(when (search-forward-regexp (concat "\\<" word "\\>") nil t)
(throw 'found (car lang))))))))))
It works well for my purposes.
/Mathias
_______________________________________________
gnu-emacs-sources mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnu-emacs-sources