emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Guess correct dictionary for Ispell


From: Thomas S. Dye
Subject: Re: [O] Guess correct dictionary for Ispell
Date: Fri, 08 Nov 2013 14:39:31 -1000


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/address@hidden>
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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]