我编写了一个简单的emacs模块,该模块生成用于博客静态站点生成器的标准模板。
(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"))现在,这是可行的,但它可以做一点DRYing,但我不知道足够多的埃利什自己做它。
hakyll-new-post和hakyll-new-note非常相似,可以使用DRYing up,但我不确定如何将正确的参数传递给任何重构函数hakyll-site-location。我是否可以请求并将配置存储在emacs dotfile中?欢迎任何帮助或指向文档的指针。
发布于 2014-01-11 22:30:40
它看起来像是变化是在:
还请注意,如果format的格式规范(即他们被忽视了 )不需要额外的参数。
因此,您可以定义一个函数,其中包含3个参数:要调用以读取文件名的函数、要写入的文件名和格式规范字符串。
为了将命名函数传递给方法,您需要引用它,如示例中所示:
(mapcar '1+ '(1 2 3))如果您想将一个匿名函数传递给一个函数,您可以使用#'(lambda ...)定义它。例如:
(mapcar #'(lambda (x) (1+ x)) '(1 2 3))我建议将您的hakyll-site-location函数更改为变量。使用defvar来定义它,然后您可以在emacs中简单地将它定义为setq。
https://codereview.stackexchange.com/questions/39059
复制相似问题