When I open a fresh file for coding, I like to insert a header like this:
#####################################################################
# Purpose:
# Author: me (me@someplace.com)
# Date:
#####################################################################
I keep this text in a file called header
in ~/.emacs.d/
and I insert it like so:
;; Insert header to file
(defun header()
"Insert header into file"
(interactive)
(insert-file "~/.emacs.d/header"))
which I call with M+x header
. Very cool! I also have a function for adding the date:
;; Insert today's date
(defun today ()
"Insert today's date"
(interactive)
(insert (format-time-string "%Y-%m-%d")))
which I invoke with M+x today
after inserting my header text in order to populate the Date:
field.
Q: Is there a way that I can merge these functions such that the date is automatically inserted after Date:
when I insert my header text? For example, can I add (format-time-string "%Y-%m-%d")
after Date:
in my header
file and evaluate it somehow when it is inserted?