我編寫了一個簡單的emacs模塊,它生成我用於博客的靜態站點生成器的標準模板。重構生成文件的elisp代碼
(defun hakyll-site-location()
"Return the location of the Hakyll files."
"~/Sites/hblog/")
(defun hakyll-new-post (title tags)
"Create a new Hakyll post for today with TITLE and TAGS."
(interactive "sTitle: \nsTags: ")
(let ((file-name (hakyll-post-title title)))
(set-buffer (get-buffer-create file-name))
(markdown-mode)
(insert
(format "---\ntitle: %s\ntags: %s\ndescription: \n---\n\n" title tags))
(write-file
(expand-file-name file-name (concat (hakyll-site-location) "posts")))
(switch-to-buffer file-name)))
(defun hakyll-new-note (title)
"Create a new Note with TITLE."
(interactive "sTitle: ")
(let ((file-name (hakyll-note-title title)))
(set-buffer (get-buffer-create file-name))
(markdown-mode)
(insert (format "---\ntitle: %s\ndescription: \n---\n\n" title))
(write-file
(expand-file-name file-name (concat (hakyll-site-location) "notes")))
(switch-to-buffer file-name)))
(defun hakyll-post-title (title)
"Return a file name based on TITLE for the post."
(concat
(format-time-string "%Y-%m-%d")
"-"
(replace-regexp-in-string " " "-" (downcase title))
".markdown"))
(defun hakyll-note-title (title)
"Return a file name based on TITLE for the note."
(concat
(replace-regexp-in-string " " "-" (downcase title))
".markdown"))
現在,這種方法可行,但它可以幹一點點,但我自己並不知道有足夠的elisp來做。
hakyll-new-post
和hakyll-new-note
非常相似,可以用乾燥起來做,但我不知道如何正確的參數傳遞給任何重構功能- 我硬編碼
hakyll-site-location
。有什麼方法可以請求並將配置存儲在我的emacs dotfiles中?
歡迎任何幫助或指向文檔的指針。
此問題似乎是脫離主題,因爲它是要求代碼審查。也許在Code Review(或程序員?)上更好。 – Drew