emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: emacs-org list <emacs-orgmode@gnu.org>
Subject: Buffer local value lost when exporting? (was Evaluate all org tables in file before exporting)
Date: Thu, 12 May 2016 15:54:09 +0000	[thread overview]
Message-ID: <CAFyQvY3P4opuxgehnp610R3dmbdq=Yy3MEPAmy0f-Zy1gC0o2w@mail.gmail.com> (raw)
In-Reply-To: <CAFyQvY0CZNHzjB58Wy18Hc_HiSgnWcKe_9HygS5Tk9wdBXV2Bg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3388 bytes --]

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.

To demonstrate that, please evaluate the elisp code at the end of this
email and do C-c C-e h o on the below MWE of org file:

As the buffer local value of modi/org-table-enable-buffer-wide-recalculation
var is nil, that table does not get recalculated when saving. But it always
gets recalculated when exporting (e.g. using C-c C-e h o).

===== sample.org =====
| N |
|---|
|   |
|   |
|   |
|   |
#+TBLFM: $1=@#-1

# Local Variables:
# modi/org-table-enable-buffer-wide-recalculation: nil
# End:
=====

===== auto-recalculate-org-tables.el =====
;; Recalculate all org tables in the buffer when saving.
(defvar-local modi/org-table-enable-buffer-wide-recalculation t
  "When non-nil, all the org tables in the buffer will be recalculated when
saving the file or when exporting.
This variable is buffer local.")
;; Mark `modi/org-table-enable-buffer-wide-recalculation' as a safe local
;; variable as long as its value is t or nil. That way you are not prompted
;; to add that to `safe-local-variable-values' in custom.el.
(put 'modi/org-table-enable-buffer-wide-recalculation
     'safe-local-variable (lambda (val) (or (equal val nil) (equal val t))))

(defun modi/org-table-recalculate-buffer-tables (&rest args)
  "Wrapper function for `org-table-recalculate-buffer-tables' that runs
that function only if `modi/org-table-enable-buffer-wide-recalculation' is
non-nil.

Also, this function has ARGS as optional arguments that are needed for any
function that is added to the `org-export-before-processing-hook'."
  (message "modi/org-table-enable-buffer-wide-recalculation: %S"
           modi/org-table-enable-buffer-wide-recalculation)
  (when modi/org-table-enable-buffer-wide-recalculation
    (org-table-recalculate-buffer-tables)))

(defun modi/org-table-recalculate-before-save ()
  "Recalculate all org tables in the buffer before saving."
  (add-hook 'before-save-hook #'modi/org-table-recalculate-buffer-tables
nil :local))
(add-hook 'org-mode-hook #'modi/org-table-recalculate-before-save)
;; FIXME: The buffer local value of
`modi/org-table-enable-buffer-wide-recalculation'
;; does not seem to be respected at the moment at the time of running
;; `org-export-before-processing-hook'. Investigating this ..
;; For now, as the default value of that variable is t, all org tables
;; in the buffer will always be recalculated at the time of export even
;; if the buffer local value of that var is nil.
(add-hook 'org-export-before-processing-hook
#'modi/org-table-recalculate-buffer-tables)
=====

On Fri, May 6, 2016 at 10:58 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Hi folks,
>
> I am looking if anyone already has a solution (a function) that evaluates
> all the tables in the file/buffer. I should be then simply able to add that
> to local value of before-save-hook in org-mode, right?
>
> Currently, I need to remember to C-u C-c C-c on all the tables before
> exporting to ensure that all the calculated values are correct.
>
> Or am I missing some org variable, setting which should take care of this?
>
> Thanks.
> --
>
> --
> Kaushal Modi
>
-- 

-- 
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 4820 bytes --]

  reply	other threads:[~2016-05-12 15:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 14:58 Evaluate all org tables in file before exporting? Kaushal Modi
2016-05-12 15:54 ` Kaushal Modi [this message]
2016-05-12 16:58   ` Buffer local value lost when exporting? (was Evaluate all org tables in file before exporting) Kaushal Modi
     [not found] ` <1ce7789874d84d4d861eabf587693621@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-05-13  7:04   ` Eric S Fraga
2016-05-13 16:22     ` Kaushal Modi
2016-05-13 16:25     ` Nicolas Goaziou
2016-05-13 16:33       ` Kaushal Modi
2016-05-14  8:25         ` Nicolas Goaziou

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='CAFyQvY3P4opuxgehnp610R3dmbdq=Yy3MEPAmy0f-Zy1gC0o2w@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-orgmode@gnu.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).