More Fun With Emacs
While working on this ikiwiki, I just added a fun little function to my init.el. It finds the next file that I am going to write for the blog and adds some meta stuff at the top.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bloggin
;; This should create a new file with the next numerical value
;; and add some boilerplate
(defun blog-insert-meta ()
(interactive)
(insert "[[!meta title=\"\"]]\n")
(insert "[[!tag ]]\n")
(insert "\n")
)
The blog-insert-meta function just inserts the title and tag stub so I remember to tag and add a title to my blog post.
(defun blog-find-next ()
(interactive)
(let ((wiki-dir "~/www/wiki/blog/"))
(find-file
(concat wiki-dir
(number-to-string (1+ (apply 'max (mapcar 'string-to-number
(mapcar '(lambda (a) (substring a 0 -5))
(directory-files wiki-dir nil "[0-9]*\\.mdwn" t))))))
".mdwn")))
)
The blog-find-next function finds all the numbered blog posts, and opens a new emacs buffer with the next numbered file.
(defun blog-next ()
(interactive)
(blog-find-next)
(end-of-buffer)
(blog-insert-meta)
)
;;
The blog-next function just puts these all together and gives it a nice short name for me to run.
You can find more of my emacs shenanigans in my config repo.
Posted at lunch time on Wednesday, May 21st, 2008