先发出来 慢慢完善

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(defun hexo-deploy (dir)
"Deploy hexo site.
If called with a prefix argument, the user is asked for directory of
the site. Otherwise, the directory is guessed from
`default-directory'."
(interactive (list (if current-prefix-arg
(file-name-as-directory
(read-directory-name "Hexo site directory: "
default-directory))
default-directory)))
(let ((old-dir default-directory))
(if (file-exists-p (concat dir "db.json"))
(progn
(setq default-directory dir)
(start-process "hexo-deploy" "*Hexo Deploy Output*" "hexo" "d" "-g")
(setq default-directory old-dir))
(progn
(if (file-exists-p (expand-file-name
(concat old-dir "../../db.json")))
(progn
(setq default-directory (expand-file-name
(concat old-dir "../../")))
(start-process "hexo-deploy"
"*Hexo Deploy Output*" "hexo" "d" "-g")
(setq default-directory old-dir))
(error "Hexo deploy failed. Wrong directory?"))))))

(defun hexo-wait-and-visit (proc max)
"Use timer to wait hexo process finish then visit the created file."
(if (eq (process-status proc) 'exit)
;; Exit normally.
(let ((hexo-buffer (process-buffer proc)))
(set-buffer hexo-buffer)
(goto-char (point-min))
(if (search-forward "File created at " nil t 1)
(progn
(find-file (buffer-substring-no-properties (point) (line-end-position)))
(kill-buffer hexo-buffer))))
(when (< max 5)
(run-with-timer 1 nil `(lambda () (funcall 'hexo-wait-and-visit ,proc ,(1+ max)))))))

(defun hexo-new (dir type title)
"Create an hexo draft/page/photo/post/.
If called with a prefix argument, the user is asked for type of the
created item. By default, `tpye' is post."
(interactive
(list (file-name-as-directory
(read-directory-name "Hexo site directory: "
default-directory))
(if current-prefix-arg
(read-string "Type to create: " "post" nil "post")
"post")
(read-string "title: ")))
(let ((old-dir default-directory))
(if (and (file-exists-p (concat dir "db.json"))
title)
(progn
(setq default-directory dir)
(hexo-wait-and-visit (start-process "hexo-new" "*Hexo New Output*" "hexo" "n" type title) 0)
(setq default-directory old-dir)
)
(error "Input directory is wrong."))))

Update:

最新的版本可以看我的配置文件 在网站的顶端有链接 在.init\some-functions.el

Update 2:

现在单独放到GitHub上了 地址是

https://github.com/zklhp/some-utils