[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Buffer local value lost when exporting? (was Evaluate all org ta
From: |
Nicolas Goaziou |
Subject: |
Re: [O] Buffer local value lost when exporting? (was Evaluate all org tables in file before exporting) |
Date: |
Fri, 13 May 2016 18:25:31 +0200 |
Hello,
Eric S Fraga <address@hidden> 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 ‘org-export-allow-bind-keywords’ is non-‘nil’, Emacs variables can
> become buffer-local during export by using the BIND keyword. Its
> syntax is ‘#+BIND: variable value’. This is particularly 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,
--
Nicolas Goaziou