-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlon-dispatch.el
351 lines (321 loc) · 15.9 KB
/
tlon-dispatch.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
;;; tlon-dispatch.el --- Transient dispatchers -*- lexical-binding: t -*-
;; Copyright (C) 2024
;; Author: Pablo Stafforini
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Transient dispatchers.
;;; Code:
(require 'tlon)
(require 'tlon-core)
(require 'transient)
;;;; Functions
;;;;; Main menu
;; TODO: add flag to set translation language, similar to Magit dispatch
;;;###autoload (autoload 'tlon-dispatch "tlon-dispatch" nil t)
(transient-define-prefix tlon-dispatch ()
"Dispatch a `tlon' command."
:info-manual "(tlon) Main menu"
[["Main menu"
"Submenus"
("a" "AI" tlon-ai-menu)
("c" "clock" tlon-clock-menu)
("H-d" "dict" tlon-dict-menu)
("f" "files" tlon-files-menu)
("g" "glossary" tlon-glossary-menu)
("i" "images" tlon-images-menu)
("j" "jobs" tlon-jobs-menu)
("k" "markdown" tlon-md-menu)
("l" "DeepL" tlon-deepl-menu)
("H-l" "color" tlon-color-menu)]
[""""
("H-m" "meet" tlon-meet-menu)
("o" "count" tlon-count-menu)
("p" "api" tlon-api-menu)
("r" "repos" tlon-repos-menu)
("s" "search" tlon-search-menu)
("S" "split" tlon-split-menu)
("t" "contacts" tlon-contacts-menu)
("u" "counterpart" tlon-counterpart-menu)
("y" "forg" tlon-forg-menu)
("x" "tex" tlon-tex-menu)
("z" "tts" tlon-tts-menu)]
[""
"Browse repo"
("d" "in Dired" tlon-dired-repo-menu)
("m" "in Magit" tlon-magit-repo-menu)
""
("." "notifications" forge-list-notifications)
""]
[""
"Package"
("H-u" "update & reload" tlon-update-package-and-reload)
("H-o" "open" tlon-open-package-files)
("H-c" "copy info" tlon-copy-package-info)
""""""""""
("!" "report bug" tlon-report-bug)
""
(:info* (lambda () (concat "Package version: " (propertize tlon-version 'face 'bold))))
(:info* (lambda () (format "Latest commit: %s" (propertize (tlon-get-latest-commit) 'face 'bold))))]])
;;;;;; Common elements
(transient-define-infix tlon-menu-infix-toggle-debug ()
"Toggle the value of `tlon-debug' in `ai' menu."
:class 'transient-lisp-variable
:variable 'tlon-debug
:reader (lambda (_ _ _) (tlon-transient-toggle-variable-value 'tlon-debug)))
;;;;; Browse repo in Magit
(defmacro tlon-generate-magit-browse-commands (name dir)
"Generate commands for browsing repo named NAME in Magit.
DIR is the directory where the repo is stored."
`(defun ,(intern (format "tlon-magit-browse-%s" name)) ()
,(format "Browse the %s repository in Magit." name)
(interactive)
(magit-status ,dir)))
(dolist (repo tlon-repos)
(eval `(tlon-generate-magit-browse-commands
,(plist-get repo :abbrev)
,(plist-get repo :dir))))
;;;###autoload (autoload 'tlon-magit-repo-menu "tlon-dispatch" nil t)
(transient-define-prefix tlon-magit-repo-menu ()
"Browse a Tlön repo in Magit."
[["Tlon"
("t c" "tlon-content" tlon-magit-browse-tlon-content)
("t f" "tlon-front" tlon-magit-browse-tlon-front)
("t d" "tlon-docs" tlon-magit-browse-docs)
("t e" "tlon.el" tlon-magit-browse-tlon.el)]
["Babel"
("b c" "babel-core" tlon-magit-browse-babel-core)
("b f" "babel-refs" tlon-magit-browse-babel-refs)
("b i" "babel-issues" tlon-magit-browse-babel-issues)
""
("b d" "babel-de" tlon-magit-browse-babel-de)
("b s" "babel-es" tlon-magit-browse-babel-es)
("b r" "babel-fr" tlon-magit-browse-babel-fr)
("b t" "babel-it" tlon-magit-browse-babel-it)]
["Uqbar"
("q q" "uqbar" tlon-magit-browse-uqbar)
("q d" "uqbar-audio" tlon-magit-browse-uqbar-audio)
""
("q a" "uqbar-ar" tlon-magit-browse-uqbar-ar)
("q n" "uqbar-en" tlon-magit-browse-uqbar-en)
("q s" "uqbar-es" tlon-magit-browse-uqbar-es)
("q r" "uqbar-fr" tlon-magit-browse-uqbar-fr)
("q t" "uqbar-it" tlon-magit-browse-uqbar-it)
("q j" "uqbar-ja" tlon-magit-browse-uqbar-ja)
("q k" "uqbar-ko" tlon-magit-browse-uqbar-ko)]
["utilitarianism"
("u n" "utilitarianism-en" tlon-magit-browse-utilitarianism-en)
("u s" "utilitarianism-es" tlon-magit-browse-utilitarianism-es)
""
"Essays on Longtermism"
("e n" "essays-en" tlon-magit-browse-essays-en)
("e s" "essays-es" tlon-magit-browse-essays-es)
""
"EA International"
("i i" "ea.international" tlon-magit-browse-ea-international)]
["La Bisagra"
("s a" "bisagra-api" tlon-magit-browse-bisagra-api)
("s f" "bisagra-front" tlon-magit-browse-bisagra-front)
("s c" "bisagra-content" tlon-magit-browse-bisagra-content)
""
"Boletín"
("a a" "boletin" tlon-magit-browse-boletin)]
["EA News"
("n i" "ean-issues" tlon-magit-browse-ean-issues)
("n f" "ean-front" tlon-magit-browse-ean-front)
("n a" "ean-api" tlon-magit-browse-ean-api)]
["Meetings"
("m l p" "Leo-Pablo" tlon-magit-browse-meetings-leo-pablo)
("m f p" "Fede-Pablo" tlon-magit-browse-meetings-fede-pablo)
("m f l" "Fede-Leo" tlon-magit-browse-meetings-fede-leo)
("m g" "group" tlon-magit-browse-meetings-group)
""
"Clock"
("c l" "Leo" tlon-magit-browse-clock-leo)
("c f" "Fede" tlon-magit-browse-clock-fede)
("c p" "Pablo" tlon-magit-browse-clock-pablo)]])
;;;;; Browse repo in Dired
(defmacro tlon-generate-dired-browse-commands (name dir)
"Generate commands for browsing repo named NAME.
DIR is the directory where the repo is stored."
`(defun ,(intern (format "tlon-dired-browse-%s" name)) ()
,(format "Browse the %s repository in Dired." name)
(interactive)
(dired ,dir)))
(dolist (repo tlon-repos)
(eval `(tlon-generate-dired-browse-commands
,(plist-get repo :abbrev)
,(plist-get repo :dir))))
;;;###autoload (autoload 'tlon-dired-repo-menu "tlon-dispatch" nil t)
(transient-define-prefix tlon-dired-repo-menu ()
"Browse a Tlön repo in Dired."
[["Tlon"
("t c" "tlon-content" tlon-dired-browse-tlon-content)
("t f" "tlon-front" tlon-dired-browse-tlon-front)
("t d" "tlon-docs" tlon-dired-browse-docs)
("t e" "tlon.el" tlon-dired-browse-tlon.el)]
["Babel"
("b c" "babel-core" tlon-dired-browse-babel-core)
("b i" "babel-issues" tlon-dired-browse-babel-issues)
("b f" "babel-refs" tlon-dired-browse-babel-refs)
""
("b d" "babel-de" tlon-dired-browse-babel-de)
("b s" "babel-es" tlon-dired-browse-babel-es)
("b r" "babel-fr" tlon-dired-browse-babel-fr)
("b t" "babel-it" tlon-dired-browse-babel-it)]
["Uqbar"
("q q" "uqbar" tlon-dired-browse-uqbar)
("q d" "uqbar-audio" tlon-dired-browse-uqbar-audio)
""
("q a" "uqbar-ar" tlon-dired-browse-uqbar-ar)
("q n" "uqbar-en" tlon-dired-browse-uqbar-en)
("q s" "uqbar-es" tlon-dired-browse-uqbar-es)
("q r" "uqbar-fr" tlon-dired-browse-uqbar-fr)
("q t" "uqbar-it" tlon-dired-browse-uqbar-it)
("q j" "uqbar-ja" tlon-dired-browse-uqbar-ja)
("q k" "uqbar-ko" tlon-dired-browse-uqbar-ko)]
["utilitarianism"
("u n" "utilitarianism-en" tlon-dired-browse-utilitarianism-en)
("u s" "utilitarianism-es" tlon-dired-browse-utilitarianism-es)
""
"Essays on Longtermism"
("e n" "essays-en" tlon-dired-browse-essays-en)
("e s" "essays-es" tlon-dired-browse-essays-es)
""
"EA International"
("i i" "ea-international" tlon-dired-browse-ea-international)]
["La Bisagra"
("s a" "bisagra-api" tlon-dired-browse-bisagra-api)
("s f" "bisagra-front" tlon-dired-browse-bisagra-front)
("s c" "bisagra-content" tlon-dired-browse-bisagra-content)
""
"Boletín"
("a a" "boletin" tlon-dired-browse-boletin)]
["EA News"
("n i" "ean-issues" tlon-dired-browse-ean-issues)
("n f" "ean-front" tlon-dired-browse-ean-front)
("n a" "ean-api" tlon-dired-browse-ean-api)]
["Meetings"
("m l p" "Leo-Pablo" tlon-dired-browse-meetings-leo-pablo)
("m f p" "Fede-Pablo" tlon-dired-browse-meetings-fede-pablo)
("m f l" "Fede-Leo" tlon-dired-browse-meetings-fede-leo)
("m g" "group" tlon-dired-browse-meetings-group)
""
"Clock"
("c l" "Leo" tlon-dired-browse-clock-leo)
("c f" "Fede" tlon-dired-browse-clock-fede)
("c p" "Pablo" tlon-dired-browse-clock-pablo)]])
;;;;; Open file in repo
(defmacro tlon-generate-open-file-in-repo-commands (repo)
"Generate commands to open file in REPO."
(let* ((repo-name (tlon-repo-lookup :abbrev :dir repo))
(command-name (intern (concat "tlon-open-file-in-" repo-name))))
`(defun ,command-name ()
,(format "Interactively open a file from a list of all files in `%s'" repo-name)
(interactive)
(tlon-find-file-in-repo ,repo))))
(dolist (repo (tlon-repo-lookup-all :dir))
(eval `(tlon-generate-open-file-in-repo-commands ,repo)))
;;;###autoload (autoload 'tlon-find-file-in-repo-menu "tlon-dispatch" nil t)
(transient-define-prefix tlon-find-file-in-repo-menu ()
"Interactively open a file from a Tlön repo."
[["Tlon"
("t c" "tlon-content" tlon-open-file-in-tlon-content)
("t f" "tlon-front" tlon-open-file-in-tlon-front)
("t d" "tlon-docs" tlon-open-file-in-docs)
("t e" "tlon.el" tlon-open-file-in-tlon.el)]
["Babel"
("b c" "babel-core" tlon-open-file-in-babel-core)
("b f" "babel-refs" tlon-open-file-in-babel-refs)
("b i" "babel-issues" tlon-open-file-in-babel-issues)
""
("b d" "babel-de" tlon-open-file-in-babel-de)
("b s" "babel-es" tlon-open-file-in-babel-es)
("b r" "babel-fr" tlon-open-file-in-babel-fr)
("b t" "babel-it" tlon-open-file-in-babel-it)]
["Uqbar"
("q q" "uqbar" tlon-open-file-in-uqbar)
("q d" "uqbar" tlon-open-file-in-uqbar-audio)
""
("q a" "uqbar-ar" tlon-open-file-in-uqbar-ar)
("q n" "uqbar-en" tlon-open-file-in-uqbar-en)
("q s" "uqbar-es" tlon-open-file-in-uqbar-es)
("q r" "uqbar-fr" tlon-open-file-in-uqbar-fr)
("q t" "uqbar-it" tlon-open-file-in-uqbar-it)
("q j" "uqbar-ja" tlon-open-file-in-uqbar-ja)
("q k" "uqbar-ko" tlon-open-file-in-uqbar-ko)]
["utilitarianism"
("u n" "utilitarianism-en" tlon-open-file-in-utilitarianism-en)
("u s" "utilitarianism-es" tlon-open-file-in-utilitarianism-es)
""
"Essays on Longtermism"
("e n" "essays-en" tlon-open-file-in-essays-en)
("e s" "essays-es" tlon-open-file-in-essays-es)
""
"EA International"
("i " "ea-international" tlon-open-file-in-ea-international)]
["La Bisagra"
("s a" "bisagra-dev" tlon-open-file-in-bisagra-api)
("s f" "bisagra-front" tlon-open-file-in-bisagra-front)
("s c" "bisagra-content" tlon-open-file-in-bisagra-content)
""
"Boletín"
("a a" "boletin" tlon-open-file-in-boletin)]
["EA News"
("n i" "ean-issues" tlon-open-file-in-ean-issues)
("n f" "ean-front" tlon-open-file-in-ean-front)
("n a" "ean-api" tlon-open-file-in-ean-api)]
["Meetings"
("m l p" "Leo-Pablo" tlon-open-file-in-meetings-leo-pablo)
("m f p" "Fede-Pablo" tlon-open-file-in-meetings-fede-pablo)
("m f l" "Fede-Leo" tlon-open-file-in-meetings-fede-leo)
("m g" "group" tlon-open-file-in-meetings-group)
""
"Clock"
("c l" "Leo" tlon-open-file-in-clock-leo)
("c f" "Fede" tlon-open-file-in-clock-fede)
("c p" "Pablo" tlon-open-file-in-clock-pablo)]])
;;;;; Files menu
;;;###autoload (autoload 'tlon-files-menu "tlon-dispatch" nil t)
(transient-define-prefix tlon-files-menu ()
"Files menu."
:info-manual "(tlon) Files"
[["Find"
("c" "in current repo" tlon-find-file-in-repo)
("o" "in another repo" tlon-find-file-in-repo-menu)
("a" "across repos" tlon-open-file-across-repos)]
["Open counterpart"
("f" "current window" tlon-open-counterpart-dwim)
("H-f" "other window" tlon-open-counterpart-in-other-window-dwim)]
["URL<>File"
("u" "Open URL of file" tlon-browse-file)
("H-u" "Open file of URL" tlon-find-file-of-url)]
["Issue"
("i" "file" tlon-open-forge-file)
("H-i" "counterpart" tlon-open-forge-counterpart)]
["Version control"
("l" "log" magit-log-buffer-file)
("d" "diffs since last user change" tlon-log-buffer-latest-user-commit)
("e" "ediff with last user change" tlon-log-buffer-latest-user-commit-ediff)]])
;;;;; Search menu
;;;###autoload (autoload 'tlon-search-menu "tlon-dispatch" nil t)
(transient-define-prefix tlon-search-menu ()
"Search menu."
["Search"
("c" "commits" tlon-search-commits)
("d" "commit-diffs" tlon-search-commit-diffs)
("f" "files" tlon-search-files)
("t" "translation" tlon-search-for-translation)])
(provide 'tlon-dispatch)
;;; tlon-dispatch.el ends here