【发布时间】:2014-03-19 02:26:07
【问题描述】:
我正在使用 Emacs。
有什么方法可以在函数上添加钩子吗?
假设有一个markdown-export函数。
它旨在将 HTML 文件导出到当前工作的“markdown 文件”所在的当前目录。
但是,我想将 HTML 文件导出到另一个目录。如何在不修改 Emacs markdown 插件 (markdown-mode.el) 的情况下做到这一点?
这是markdown-mode.el的导出函数:
(defun markdown-export (&optional output-file)
"Run Markdown on the current buffer, save to file, and return the filename.
If OUTPUT-FILE is given, use that as the filename. Otherwise, use the filename
generated by `markdown-export-file-name', which will be constructed using the
current filename, but with the extension removed and replaced with .html."
(interactive)
(unless output-file
(setq output-file (markdown-export-file-name ".html")))
(when output-file
(let* ((init-buf (current-buffer))
(init-point (point))
(init-buf-string (buffer-string))
(output-buffer (find-file-noselect output-file))
(output-buffer-name (buffer-name output-buffer)))
(run-hooks 'markdown-before-export-hook)
(markdown-standalone output-buffer-name)
(with-current-buffer output-buffer
(run-hooks 'markdown-after-export-hook)
(save-buffer))
;; if modified, restore initial buffer
(when (buffer-modified-p init-buf)
(erase-buffer)
(insert init-buf-string)
(save-buffer)
(goto-char init-point))
output-file)))
================================================ =======================
我已建议将导出的 HTML 保存在临时目录中 这是代码。
(defadvice markdown-export (around set-temp-path-for-exported-file activate)
(ad-set-arg 0 (format "%s/%s" "~/.emacs.d/temp-dir" (file-name-nondirectory buffer-file-name)))
ad-do-it)
谢谢!!!!!!!!!!!!!!!
【问题讨论】: