From mboxrd@z Thu Jan 1 00:00:00 1970 From: tsd@tsdye.com (Thomas S. Dye) Subject: Re: Guess correct dictionary for Ispell Date: Fri, 08 Nov 2013 14:39:31 -1000 Message-ID: References: <86zjpeecmq.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vewag-0002p1-MX for emacs-orgmode@gnu.org; Fri, 08 Nov 2013 19:40:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VewaZ-0007QG-6n for emacs-orgmode@gnu.org; Fri, 08 Nov 2013 19:39:54 -0500 Received: from plane.gmane.org ([80.91.229.3]:48528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VewaY-0007QC-VI for emacs-orgmode@gnu.org; Fri, 08 Nov 2013 19:39:47 -0500 Received: from public by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VewaX-0001ZQ-HR for emacs-orgmode@gnu.org; Sat, 09 Nov 2013 01:39:45 +0100 In-Reply-To: <86zjpeecmq.fsf@somewhere.org> (Sebastien Vauban's message of "Fri, 08 Nov 2013 23:45:33 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sebastien Vauban Cc: public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org 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" 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