Closed lujun9972 closed 8 years ago
比如我在find-file-not-found-hooks中加了一个函数用于插入自己的模板
然后使用ego/new-post生成新post时,会发现两个模板都插入了。
你不妨试试?
(require 'subr-x) (defun get-category-from-path (path) "根据路径生成类别" (let* ((dir (file-relative-name (file-name-directory path) MY-NOTE-PATH))) (if (file-in-directory-p (file-name-directory path) MY-NOTE-PATH) (string-join (remove "" (split-string dir "[/\\]")) ", ") (if (string-match ".+[/\\]\\([^/\\]+\\)[/\\]$" dir) ;若不在"我的笔记目录下",则取其所在的目录名称为类别 (match-string 1 dir) dir) ))) (defun new-org-file-init () "init new org file template" (interactive) (when (equal "org" (file-name-extension buffer-file-name)) (insert (concat "#+TITLE: "(file-name-base buffer-file-name)) "\n") (insert "#+AUTHOR: " user-login-name "\n") (insert "#+CATEGORY: " (get-category-from-path buffer-file-name)"\n") (insert "#+DATE: " (format-time-string "[%Y-%m-%d %a %H:%M]" (current-time)) "\n") (insert "#+OPTIONS: ^:{}"))) (add-to-list 'find-file-not-found-hooks 'new-org-file-init)
这个漏洞不明显比较难发现,黑日大侠辛苦了
问题在 ego.el 的 424 行,那里用了 find-file , 后面接的参数是一个不存在的路径,所以一定会触发 find-file-not-found-hooks 。
清空 buffer 是办法之一。 能不能不触发 find-file-not-found-hooks 就解决问题?暂时没找到好办法。
比如我在find-file-not-found-hooks中加了一个函数用于插入自己的模板
然后使用ego/new-post生成新post时,会发现两个模板都插入了。
你不妨试试?