From: tsd@tsdye.com (Thomas S. Dye)
To: Sebastien Vauban
<public-sva-news-D0wtAvR13HarG/iDocfnWg@plane.gmane.org>
Cc: public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org
Subject: Re: Guess correct dictionary for Ispell
Date: Fri, 08 Nov 2013 14:39:31 -1000 [thread overview]
Message-ID: <m1y54yo1bw.fsf@tsdye.com> (raw)
In-Reply-To: <86zjpeecmq.fsf@somewhere.org> (Sebastien Vauban's message of "Fri, 08 Nov 2013 23:45:33 +0100")
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
prev parent reply other threads:[~2013-11-09 0:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-08 22:45 Guess correct dictionary for Ispell Sebastien Vauban
2013-11-09 0:39 ` Thomas S. Dye [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1y54yo1bw.fsf@tsdye.com \
--to=tsd@tsdye.com \
--cc=public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org \
--cc=public-sva-news-D0wtAvR13HarG/iDocfnWg@plane.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).