forked from masasam/emacs-easy-hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-hugo-transient.el
100 lines (92 loc) · 3.95 KB
/
easy-hugo-transient.el
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; easy-hugo-transient.el --- Trasnisent menu for easy-hugo -*- lexical-binding: t no-byte-compile: t -*-
;; Author: liuyinz <liuyinz@gmail.com>
;; Created: 2021-09-25 21:21:41
;;; Commentary:
;; Call `easy-hugo-enable-menu' after loading package to enable transient menu.
;; Call command like `easy-hugo' or `easy-hugo-list-draft' will open transient menu automaticlly.
;; Or call `easy-hugo-menu' to use menu directly.
;;; Code:
(require 'transient)
(require 'subr-x)
(defun easy-hugo-menu--header ()
"Header used in `easy-hugo-menu'."
(let ((dir (file-relative-name easy-hugo-postdir "content"))
(url (string-remove-suffix "/" easy-hugo-url)))
(format (propertize "[%s]: %s\t[%s]: %s\t[%s]: %s\t[%s]: %s%s\n" 'face 'bold)
(propertize "sort" 'face 'font-lock-doc-face)
(propertize
(if easy-hugo--sort-char-flg
"char "
(if easy-hugo--sort-time-flg
"time "
"publishday"))
'face
'font-lock-variable-name-face)
(propertize "draft" 'face 'font-lock-doc-face)
(if easy-hugo--draft-list
(propertize "on " 'face 'font-lock-variable-name-face)
(propertize "off" 'face 'font-lock-warning-face))
(propertize "delay" 'face 'font-lock-doc-face)
(if (nth easy-hugo--current-blog easy-hugo--publish-timer-list)
(propertize "on " 'face 'font-lock-variable-name-face)
(propertize "off" 'face 'font-lock-warning-face))
(propertize "url" 'face 'font-lock-doc-face)
(propertize url 'face 'font-lock-variable-name-face)
(propertize (if (string= dir ".") "" (concat "/" dir))
'face
'font-lock-warning-face))))
(transient-define-prefix easy-hugo-menu ()
"Invoke commands for easy-hugo-mode"
:man-page "hugo"
:transient-non-suffix 'transient--do-warn
[:description easy-hugo-menu--header
["Project"
("M" "Magit status" easy-hugo-magit)
("p" "Preview local" easy-hugo-preview)
("O" "Open basedir" easy-hugo-open-basedir)
("c" "Open config" easy-hugo-open-config)
("q" "Quit" easy-hugo-quit)]
["Post"
("f" "Select post" easy-hugo-select-filename)
("K" "List post" easy-hugo)
("D" "List draft" easy-hugo-list-draft)
("r" "Rg search" easy-hugo-rg)
("a" "Ag search" easy-hugo-ag)]
["Blog"
(";" "Select blog" easy-hugo-select-blog)
("<" "Prev blog" easy-hugo-previous-blog)
(">" "Next blog" easy-hugo-next-blog)]
["Postdir"
("/" "Select postdir" easy-hugo-select-postdir)
("." "Next postdir" easy-hugo-next-postdir)
("," "Prev postdir" easy-hugo-previous-postdir)]
["Publish"
("P" "Publish now" easy-hugo-publish-clever)
("T" "Publish delay" easy-hugo-publish-timer)
("t" "Publish cancel" easy-hugo-cancel-publish-timer)]
]
[:if-mode easy-hugo-mode
["Move"
("j" "Next post" easy-hugo-next-line :transient t)
("k" "Prev post" easy-hugo-previous-line :transient t)
("h" "Backward char" easy-hugo-backward-char :transient t)
("l" "Forward char" easy-hugo-forward-char :transient t)]
["Sort"
("s" "By time" easy-hugo-sort-time :transient t)
("S" "By char" easy-hugo-sort-char :transient t)
("u" "By publishD" easy-hugo-sort-publishday :transient t)]
["Edit"
("n" "New post" easy-hugo-newpost :transient t)
("R" "Rename post" easy-hugo-rename :transient t)
("d" "Delete post" easy-hugo-delete :transient t)
("g" "Refresh post" easy-hugo-refresh :transient t)]
["View"
("v" "View post" easy-hugo-view)
("V" "View post in other window" easy-hugo-view-other-window)
("e" "Open post" easy-hugo-open)
("o" "Open post in other window" easy-hugo-open-other-window)]]
)
(advice-add 'easy-hugo :after #'easy-hugo-menu)
(advice-add 'easy-hugo-list-draft :after #'easy-hugo-menu)
(provide 'easy-hugo-transient)
;;; easy-hugo-transient.el ends here