* Guess correct dictionary for Ispell
@ 2013-11-08 22:45 Sebastien Vauban
2013-11-09 0:39 ` Thomas S. Dye
0 siblings, 1 reply; 2+ messages in thread
From: Sebastien Vauban @ 2013-11-08 22:45 UTC (permalink / raw)
To: emacs-orgmode-mXXj517/zsQ
Hello,
In case that can be useful for someone, here is how I detect which dictionary
to use on a file basis:
--8<---------------cut here---------------start------------->8---
(defun my-org-switch-language ()
"Switch language if a `#+LANGUAGE:' Org meta-tag is on top 8 lines."
(save-excursion
(goto-line (1+ 8))
(let (lang
(dico-alist '(("fr" . "francais")
("en" . "american"))))
(when (re-search-backward "#\\+LANGUAGE: +\\([[:alpha:]_]*\\)" 1 t)
(setq lang (match-string 1))
(ispell-change-dictionary (cdr (assoc lang dico-alist)))))))
(add-hook 'org-mode-hook 'my-org-switch-language)
--8<---------------cut here---------------end--------------->8---
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Guess correct dictionary for Ispell
2013-11-08 22:45 Guess correct dictionary for Ispell Sebastien Vauban
@ 2013-11-09 0:39 ` Thomas S. Dye
0 siblings, 0 replies; 2+ messages in thread
From: Thomas S. Dye @ 2013-11-09 0:39 UTC (permalink / raw)
To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ
Aloha Seb,
John Kitchin posted some code to the list a while back that uses
Nicolas' parser for querying the values of keywords and other elements.
I modified his code slightly to include keywords assigned in property
drawers.
Using this would save your code from having to re-search and presumably
would remove the limitation that the tag be one of the first 8 lines of
the file.
I'm not sure you need this, but I've found it to be generally helpful.
All the best,
Tom
#+name: jk-keywords
#+header: :results silent
#+begin_src emacs-lisp
(defun jk-org-kwds ()
"parse the buffer and return a cons list of (property . value)
from lines like: #+PROPERTY: value"
(org-element-map (org-element-parse-buffer 'element) '(keyword node-property)
(lambda (keyword) (cons (org-element-property :key keyword)
(org-element-property :value keyword)))))
(defun jk-org-kwd (KEYWORD)
"get the value of a KEYWORD in the form of #+KEYWORD: value"
(cdr (assoc KEYWORD (jk-org-kwds))))
#+end_src
#+name: test-properties
#+begin_src emacs-lisp
(jk-org-kwd "LANGUAGE")
#+end_src
#+results: test-properties
: en
"Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:
> Hello,
>
> In case that can be useful for someone, here is how I detect which dictionary
> to use on a file basis:
>
> (defun my-org-switch-language ()
> "Switch language if a `#+LANGUAGE:' Org meta-tag is on top 8 lines."
> (save-excursion
> (goto-line (1+ 8))
> (let (lang
> (dico-alist '(("fr" . "francais")
> ("en" . "american"))))
> (when (re-search-backward "#\\+LANGUAGE: +\\([[:alpha:]_]*\\)" 1 t)
> (setq lang (match-string 1))
> (ispell-change-dictionary (cdr (assoc lang dico-alist)))))))
>
> (add-hook 'org-mode-hook 'my-org-switch-language)
>
> Best regards,
> Seb
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-11-09 0:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-08 22:45 Guess correct dictionary for Ispell Sebastien Vauban
2013-11-09 0:39 ` Thomas S. Dye
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).