You may want to check out this example wherein the author suggests this define-skeleton
:
(define-skeleton org-skeleton
"In-buffer settings info for a emacs-org file."
"Title: "
"#+TITLE:" str " \n"
"#+AUTHOR: Your Name\n"
"#+email: [email protected]\n"
"#+INFOJS_OPT: \n"
"#+BABEL: :session *R* :cache yes :results output graphics :exports both :tangle yes \n"
"-----"
)
(global-set-key [C-S-f4] 'org-skeleton)
Customize to please. But like so many things in the Emacs world, I don't know if this is "best practice."
There is also autoinsert
which will insert lines whenever you create a new file. Here's what I have in my init:
(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"))
Note the last line (define-auto-insert "\\.org?$" "default-org.org")
So the file default-org.org
(in my .emacs.d
directory) contains my customized in-buffer settings, which will be automatically inserted at the top whenever I create a file with an org
ending.
Unfortunately, I could not figure out how to plant variables and expanding things in this template, as is supposedly possible. (See this cry for help.)