/
cc-context-menu.el
237 lines (197 loc) · 9.98 KB
/
cc-context-menu.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
;; context-menu addons
(require 'cc-context-menu-macros)
(require 'cc-transform-text-menu)
(require 'cc-style-text-menu)
(require 'cc-region-operations-menu)
(require 'cc-insert-org-plot)
(require 'cc-find-menu)
(require 'cc-edit-text-menu)
(require 'cc-wgrep-mode)
(defun cc/context-menu-addons (menu click)
"CC context menu additions"
(save-excursion
(mouse-set-point click)
(easy-menu-add-item menu nil ["Journal"
status-report
:help "Go to current day journal"])
(cc/context-menu-item-separator menu buffer-navigation-separator)
(easy-menu-add-item menu nil ["List All Buffers"
list-buffers
:help "List all buffers"])
(when buffer-file-name
(cond ((use-region-p)
(cc/context-menu-item-separator menu narrow-separator)
(easy-menu-add-item menu nil
["Narrow Region" narrow-to-region
:label (cc/context-menu-label "Narrow Region")
:help "Restrict editing in this buffer \
to the current region"]))
((and (not (buffer-narrowed-p)) (derived-mode-p 'org-mode))
(cc/context-menu-item-separator menu narrow-separator)
(easy-menu-add-item menu nil
["Narrow to subtree" org-narrow-to-subtree
:help "Restrict editing in this buffer \
to the current subtree"]))
((and (not (buffer-narrowed-p)) (derived-mode-p 'markdown-mode))
(cc/context-menu-item-separator menu narrow-separator)
(easy-menu-add-item menu nil
["Narrow to subtree" markdown-narrow-to-subtree
:help "Restrict editing in this buffer \
to the current subtree"])))
(when (buffer-narrowed-p)
(cc/context-menu-item-separator menu widen-separator)
(easy-menu-add-item menu nil
["Widen buffer" widen
:help "Remove narrowing restrictions \
from current buffer"])))
(easy-menu-add-item menu nil "--")
(cc/context-menu-item-separator menu capture-flow-separator)
(easy-menu-add-item menu nil
["New Workflow…"
org-capture
:help "Create new task or workflow via org-capture"])
(cc/context-menu-item-separator menu open-in-separator)
(when buffer-file-name
(easy-menu-add-item menu nil
["Open in Finder"
reveal-in-folder-this-buffer
:help "Open file (buffer) in Finder"])
(when (not (derived-mode-p 'dired-mode))
(easy-menu-add-item menu nil
["Open in Dired"
dired-jump-other-window
:help "Open file in Dired"])))
(when (derived-mode-p 'dired-mode)
(easy-menu-add-item menu nil
["Duplicate"
cc/dired-duplicate-file
:label (concat "Duplicate"
" “"
(file-name-base (dired-get-filename))
"."
(file-name-extension (dired-get-filename))
"”")
:help "Duplicate selected item"]))
(when (use-region-p)
(cc/context-menu-item-separator menu dictionary-operations-separator)
(easy-menu-add-item menu nil ["Look Up"
osx-dictionary-search-word-at-point
:label (cc/context-menu-last-word-in-region "Look Up")
:help "Look up selected region in macOS dictionary"]))
(cc/context-menu-item-separator menu find-operations-separator)
(if (use-region-p)
(easy-menu-add-item menu nil
["Find word in buffer (occur)"
occur-word-at-mouse
:label (cc/context-menu-last-word-in-region
"Find word in buffer (occur)")
:help "Show all lines in the current buffer containing \
a match for selected word"])
(easy-menu-add-item menu nil
["Find in buffer (occur)"
occur
:help "Show all lines in the current buffer \
containing a match for regex"]))
(easy-menu-add-item menu nil cc/find-menu)
(when (and (bound-and-true-p buffer-file-name)
(vc-registered (buffer-file-name)))
(cc/context-menu-item-separator menu vc-separator)
(easy-menu-add-item menu nil
["Magit Status"
magit-status
:help "Show the status of the current Git repository \
in a buffer"])
(easy-menu-add-item menu nil ["Ediff revision…"
cc/ediff-revision-from-menu
:help "Ediff this file with revision"])
(easy-menu-add-item menu nil ["Git History"
magit-log-buffer-file
:help "Show log for the blob or file visited in \
the current buffer"]))
(when (use-region-p)
(cc/context-menu-item-separator menu transform-text-separator)
(easy-menu-add-item menu nil cc/transform-text-menu)
(cond
((derived-mode-p 'prog-mode)
(easy-menu-add-item menu nil
["Toggle Comment"
comment-region
:help "Toggle comment on selected region"]))
((derived-mode-p 'org-mode)
(easy-menu-add-item menu nil cc/emphasize-menu)
(easy-menu-add-item menu nil ["Copy as Slack"
org-slack-export-to-clipboard-as-slack
:help "Copy as Slack to clipboard"])
(easy-menu-add-item menu nil ["Copy as Slack"
org-slack-export-to-clipboard-as-slack
:help "Copy as Slack to clipboard"])
(easy-menu-add-item menu nil ["Copy as RTF"
dm/copy-as-rtf
:help "Copy as RTF to clipboard"]))
((derived-mode-p 'markdown-mode)
(easy-menu-add-item menu nil cc/emphasize-menu))))
(cond
((derived-mode-p 'org-mode)
(cc/context-menu-item-separator menu org-mode-operations-separator)
(easy-menu-add-item menu nil
["Toggle Reveal Markup"
visible-mode
:help "Toggle making all invisible text \
temporarily visible (Visible mode)"])
(easy-menu-add-item menu nil
["Paste Last Org Link"
org-insert-last-stored-link
:enable (cc/org-stored-links-p)
:help "Insert the last link stored in org-stored-links"]))
((derived-mode-p 'markdown-mode)
(cc/context-menu-item-separator menu markdown-mode-operations-separator)
(easy-menu-add-item menu nil
["Toggle Reveal Markup"
markdown-toggle-markup-hiding
:help "Toggle the display or hiding of markup"])))
(when (org-at-table-p)
(cc/context-menu-item-separator menu org-table-separator)
(easy-menu-add-item menu nil
["Table Cell Info"
cc/kill-org-table-reference
:label (format "@%d$%d"
(org-table-current-dline)
(org-table-current-column))
:help "Table field/cell information"])
(easy-menu-add-item menu nil cc/insert-org-plot-menu)
(easy-menu-add-item menu nil ["Run gnuplot"
org-plot/gnuplot
:help "Plot table using gnuplot"]))
(when (use-region-p)
(cc/context-menu-item-separator menu region-operations-separator)
(easy-menu-add-item menu nil cc/region-operations-menu))
(cc/context-menu-item-separator menu world-clock-separator)
(easy-menu-add-item menu nil
["Calendar"
calendar
:help "Display a three-month Gregorian calendar"])
(easy-menu-add-item menu nil
["World Clock"
world-clock
:help "Display times from around the world"])
(cc/context-menu-item-separator menu count-words-separator)
(when (derived-mode-p 'text-mode)
(if (use-region-p)
(easy-menu-add-item menu nil ["Count Words in Region"
count-words
:help "Count words in region"])
(easy-menu-add-item menu nil ["Count Words in Buffer"
count-words
:help "Count words in buffer"])))
(easy-menu-add-item menu nil cc/transpose-menu)
(easy-menu-add-item menu nil cc/move-text-menu)
(easy-menu-add-item menu nil cc/delete-space-menu)
(easy-menu-add-item menu nil cc/wgrep-menu)
menu))
(defun cc/kill-org-table-reference (e)
(interactive "e")
(kill-new (format "@%d$%d"
(org-table-current-dline)
(org-table-current-column))))
(add-hook 'context-menu-functions #'cc/context-menu-addons)
(provide 'cc-context-menu)