From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Buffer local value lost when exporting? (was Evaluate all org tables in file before exporting) Date: Fri, 13 May 2016 18:25:31 +0200 Message-ID: <87lh3e7wn8.fsf@saiph.selenimh> References: <1ce7789874d84d4d861eabf587693621@HE1PR01MB1898.eurprd01.prod.exchangelabs.com> <87mvnujv5j.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1FuG-0007pa-Q1 for emacs-orgmode@gnu.org; Fri, 13 May 2016 12:25:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1FuE-00048z-3I for emacs-orgmode@gnu.org; Fri, 13 May 2016 12:25:39 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:38746) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1FuD-00048s-Ra for emacs-orgmode@gnu.org; Fri, 13 May 2016 12:25:38 -0400 In-Reply-To: <87mvnujv5j.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Fri, 13 May 2016 08:04:40 +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" To: Kaushal Modi Cc: emacs-org list Hello, Eric S Fraga writes: > On Thursday, 12 May 2016 at 15:54, Kaushal Modi wrote: >> Hi all, >> >> I almost have a squeaky clean solution to this thanks to the hint >> provided by someone on emacs.SE ( >> http://emacs.stackexchange.com/a/22215/115 ). >> >> But in the process, I seem to have stumbled upon a bug.. the buffer >> local value of variables are not respected at the time of exports. > > It's not a bug but a known design feature. A new buffer is created as > part of the export process and this buffer does not inherit local > variable values. What you need to do is tell org to set specific > variables upon export. You can use the #+BIND: directive to do this. > > I don't know where this is documented but there is mention of whether to > allow this to happen in the org info manual: > > If =E2=80=98org-export-allow-bind-keywords=E2=80=99 is non-=E2=80=98ni= l=E2=80=99, Emacs variables can > become buffer-local during export by using the BIND keyword. Its > syntax is =E2=80=98#+BIND: variable value=E2=80=99. This is particula= rly useful for > in-buffer settings that cannot be changed using specific keywords. > > Give this a try. For completeness, export process actually inherits some buffer local values. See `org-export--generate-copy-script', in particular ;; Copy specific buffer local variables and variables set ;; through BIND keywords. ,@(let ((bound-variables (org-export--list-bound-variables)) vars) (dolist (entry (buffer-local-variables (buffer-base-buffer)) vars) (when (consp entry) (let ((var (car entry)) (val (cdr entry))) (and (not (memq var org-export-ignored-local-variables)) (or (memq var '(default-directory buffer-file-name buffer-file-coding-system)) (assq var bound-variables) (string-match "^\\(org-\\|orgtbl-\\)" (symbol-name var))) ;; Skip unreadable values, as they cannot be ;; sent to external process. (or (not val) (ignore-errors (read (format "%S" val)))) (push `(set (make-local-variable (quote ,var)) (quote ,val)) vars)))))) So basically, it copies all Org related variables, default directory, buffer-file-name buffer-file-coding-system and any variable defined as a BIND keyword, provided their value is `read'-able (e.g., not a hash table). Regards, --=20 Nicolas Goaziou