1

I've been reading this and this, trying to figure out how to have an org-mode in-buffer settings template such as this:

# # -*- mode: org -*-
# # -*- coding: utf-8 -*-
#+TITLE: $1
#+AUTHOR: `(user-full-name)`
#+DATE: `(format-time-string "%e %B %Y")`
...

actually evaluate the back-quoted expressions and the $ markup upon .org file creation. This is, BTW, my init code for auto-insert

(use-package autoinsert
  :ensure t
  :init
  ;; Don't want to be prompted before insertion:
  (setq auto-insert-query nil)

  (setq auto-insert-directory (locate-user-emacs-file "templates"))
  (add-hook 'find-file-hook 'auto-insert)
  (auto-insert-mode 1)

  :config
  (define-auto-insert "\\.org?$" "default-org.org"))

where default-org.org begins like the first code section. But again, when I call into existence a file with a .org none of the back-quoted expressions have been evaluated, the expressions are returned verbatim. What am I missing here?

1 Answer 1

0

I just ran across this question. Hopefully, you got your answer. If not (and for the almost 1000 people who have viewed this), I figured I could weigh in.

I don't believe that Auto Insert expands an Lisp code if you are just inserting a text file. In the second link you posted, you'll notice that it will, if you give it an s-expression of strings with code to evaluate.

This is why a number of us use YAS to expand stuff dynamically. For instance, if you create a helper function, like:

(defun my/autoinsert-yas-expand()
  "Replace text in yasnippet template."
  (yas/expand-snippet (buffer-string) (point-min) (point-max)))

Then set your auto-insert variables to call this function, e.g.

(custom-set-variables
 '(auto-insert 'other)
 '(auto-insert-directory "~/autoinsert/")
 '(auto-insert-alist '((("\\.org?$" . "Org Files") . ["default-org.org" org-mode my/autoinsert-yas-expand])
                       ;; ...
                       )))

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.