Learn basic Elisp

I have been using Emacs for about 2 years until now, yet I have never looked insight to elisp seriously. I know that understanding elisp could make my life in Emacs much easier. Though I tried to read the first several chapters of An Introduction to Programming in Emacs Lisp within Emacs, but soon found out that I totally forgot what I just read without the practice of applying them in my real life. Recently I found this excellent Learn Emacs Lisp in 15 minutes blog, and was able to write some piece of useful elisp function to help me to create a blog template for my Pelican blog using org_reader.

The idea is when I call the fpk-pelican-new-blog function, a prompt will ask me to specify part of the name of the new blog file. With combination of current date and directory when I called the function, a meaningful file name is given to the blog template. The metadata information of org_reader is inserted at the beginning of the new blog template.

And here is the function. Yummy:)

(defun fpk-pelican-new-blog ()
  "Create a new pelican blog template"
  (interactive)
  (let ((cur-date (format-time-string "%Y-%m-%d"))
    (file-name (read-from-minibuffer "File Name: "))
    file-path
    my-buffer
    )
    (setq file-path (concat default-directory cur-date "-" file-name ".org"))
    (setq my-buffer (find-file file-path))
    (goto-char 1)
    (insert "#+TITLE: \n")
    (insert (format "#+DATE: %s\n" cur-date))
    (insert "#+CATEGORY: \n")
    (insert (format "#+AUTHOR: %s\n" user-full-name))
    (insert "#+PROPERTY: LANGUAGE en\n")
    (insert "#+PROPERTY: SUMMARY \n")
    (insert (format "#+PROPERTY: SLUG %s\n" file-name))
    (insert "#+PROPERTY: MODIFIED \n")
    (insert "#+PROPERTY: TAGS \n")
    (insert "#+PROPERTY: SAVE_AS \n\n")
    (insert "#+PROPERTY: eval never\n")
    (insert "#+OPTIONS: toc:nil num:nil ^:nil\n\n")
    (goto-char (point-min))
    (end-of-line)
    ))

Related