I'm currently working with a lot of javascript in my org files.

Therefore I introduce a local buffer variable that will automatically insert javascript as language identifier in my file whenever I use <s TAB.

Here is how I've done it, it's inspired by the mailing list post here.

# -*- org-structure-template-alist: (("s" "#+BEGIN_SRC javascript\n?\n#+END_SRC")); -*-

When I put this as first line in my org file it will complete <s to the desired.

#+BEGIN_SRC javascript


Now when I look up the definition C-h v org-structure-template-alist the current value is just.


(("s" "#+BEGIN_SRC javascript\n?\n#+END_SRC"))

While the original value was:

(("s" "#+BEGIN_SRC ?\n\n#+END_SRC" "<src lang=\"?\">\n\n</src>")
 ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE" "<example>\n?\n</example>")
 ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE" "<quote>\n?\n</quote>")

So is it possible to access the global definition of org-structure-template-alist inside the local org defining block and just replace the default binding to <s with my definition?

This way I can use <s to get the javascript, but also use the other defined shortcuts like <e for Example block. Currently the buffer in which I define org-structure-template-alist will only complete <s and ignore all things.

I tried this but it doesn't seem to evaluate the add-to-list.

# -*- org-structure-template-alist: (add-to-list 'org-structure-template-alist (("s" "#+BEGIN_SRC javascript\n?\n#+END_SRC" "<src lang=\"javascript\">\n\n</src>"))); -*-


This is now my final solution based on the answer of Tyler. I include the following code as last statement in my org file. It is marked as a comment so it won't get exported, which was also a requirement. Loading the file now ask if I want to apply local variables, but this is not a problem right now.

### Local Variables:
### eval: (make-variable-buffer-local 'org-structure-template-alist)
### eval: (add-to-list 'org-structure-template-alist '("s" "#+BEGIN_SRC javascript :tangle yes\n?\n#+END_SRC" "<src lang=\"javascript\">\n\n</src>"))
### End:

2 Answers 2


Once you define a variable as buffer local, I don't think you can access the global value from a buffer where it has a new local value. However, you can change your local variable definition to include the global value. File-local variable definitions are not evaluated, so you have to use the special keyword eval: to do this:

## Local Variables:
## eval: (make-variable-buffer-local 'org-structure-template-alist)
## eval: (add-to-list 'org-structure-template-alist '("s" "#+BEGIN_SRC javascript\n?\n#+END_SRC" "<src lang=\"javascript\">\n\n</src>"))
## End:

You could include the first line in your .emacs, so you don't need it in every org buffer where you're doing this. It shouldn't make any difference when you don't use a local value for org-structure-template-alist - it will default to the global value in any buffer where you don't set it explicitly.


As @AndrewSwann points out, you can indeed lookup the default value of a local variable. In this case, I don't think that's actually what you want to do: better to define your local value to incorporate the default value in the first place.

  • Thanks very much! This helped me achieve what I needed. I'll updated my question with the final solution.
    – cb0
    Jan 20, 2017 at 11:03

The global value is the default value. It can be examined with default-value and set with setq-default. See the section on "Buffer-Local Variables" in the Elisp manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.