How can I insert the current git commit into an org-mode buffer to be evaluated on export?
elisp, export, git, org-mode
Solution
If you add a name to the code block, then you can call that block code from somewhere else:
#+NAME: commit
#+BEGIN_SRC emacs-lisp :exports none :tangle no
(substring (shell-command-to-string "git rev-parse --short HEAD") 0 -1)
#+END_SRC
This corresponds to git commit call_commit().
The output I get when exporting:
This corresponds to git commit `2464d0a'.
This is documented in the org-mode manual for source code block evaluation.
Problem
``` #+Author: A. U. Thor #+Date: [2014-01-06 Mon] #+MACRO: version 2.1 #+BEGIN_SRC emacs-lisp :exports none :tangle no (substring (shell-command-to-string "git rev-parse --short HEAD") 0 -1) #+END_SRC This document interacts with version {{{version}}} of the StackExchange API and is maintained by {{{author}}}. It was last modified at {{{modification-time(%Y-%m-%dT%T%z)}}} (commit ??). This copy was exported on {{{time(%Y-%m-%dT%T%z)}}}. ``` produces ``` ____________ TEST A. U. Thor ____________ [2014-01-06 Mon] Table of Contents _________________ This document interacts with version 2.1 of the StackExchange API and is maintained by A. U. Thor. It was last modified at 2014-01-06T20:32:14-0500 (commit ??). This copy was exported on 2014-01-06T20:32:16-0500. ``` How can I insert the current commit (as returned by the tiny bit of elisp) into the `??`? I supposedly discovered a way to do it, but it is ineffective in normal export and probably only works during tangling.