So this is the first time I’ve tried to make a “new file from template” type function. Pretty ugly. Couple the fact that I had to look up in info or apropos every elisp function other than “concat” with my unwillingness to experiment with newlines as data and you get a fairly unattractive text builder.

This really isn’t super necessary:

(defun new-post-read-args (prompt)
  (read-string prompt))

This and date-string build parts I want in file names, and in the yaml heading.

(defun new-post-today-string ()
   (format-time-string "%Y-%m-%d" (current-time)))

(defun new-post-date-string ()
  (concat "date: "
	  (format-time-string "%H:%M -0500" (current-time))))

Let’s make a spaces to dashes translation, and take on our date and extension:

(defun new-post-make-file-name (title)
   (replace-regexp-in-string " " "-" title)

Prompt for a name, create a file, fill in some blanks helpfully:

(defun new-post ()
  (let ((title (new-post-read-args "Post Title: ")))
    (concat "/home/djuber/src/myblog/_posts/"
	    (new-post-make-file-name title))))
  (insert "---")
  (insert "layout: post")
  (insert "date: " (new-post-date-string) 
  (insert "title: " title)
  (insert   "categories: ")
  (insert "---")))

It spits this out in the head of the file

layout: post
title:  testing the new-post function
date:  2016-06-25 14:08 -0500