forked from rswgnu/hyperbole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hui-menu.el
483 lines (457 loc) · 18.4 KB
/
hui-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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
;;; hui-menu.el --- Menubar menu of GNU Hyperbole commands -*- lexical-binding: t; -*-
;;
;; Author: Bob Weiner
;;
;; Orig-Date: 28-Oct-94 at 10:59:44
;; Last-Mod: 6-Nov-22 at 12:23:29 by Bob Weiner
;;
;; Copyright (C) 1994-2021 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
;;; Commentary:
;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************
(eval-and-compile (mapc #'require '(hpath hui-jmenu hyrolo-menu browse-url easymenu)))
;;; ************************************************************************
;;; Private functions
;;; ************************************************************************
(defmacro hui-menu-browser (title browser-option)
`(list
(list ,title
["Chrome (Google)"
(setq ,browser-option #'browse-url-chrome)
:style radio
:selected (eq ,browser-option #'browse-url-chrome)]
["Chromium"
(setq ,browser-option #'browse-url-chromium)
:style radio
:selected (eq ,browser-option #'browse-url-chromium)]
["Default (System wide)"
(setq ,browser-option #'browse-url-default-browser)
:style radio
:selected (eq ,browser-option #'browse-url-default-browser)]
["EWW (Emacs)"
(setq ,browser-option #'eww-browse-url)
:style radio
:selected (eq ,browser-option #'eww-browse-url)]
;; Whatever browse-url-text-browser is set to, default is Lynx
["Emacs Text Browser"
(setq ,browser-option #'browse-url-text-emacs)
:style radio
:selected (eq ,browser-option #'browse-url-text-emacs)]
["Firefox"
(setq ,browser-option #'browse-url-firefox)
:style radio
:selected (eq ,browser-option #'browse-url-firefox)]
["KDE"
(setq ,browser-option #'browse-url-kde)
:style radio
:selected (eq ,browser-option #'browse-url-kde)]
["XTerm Text Browser"
(setq ,browser-option #'browse-url-text-xterm)
:style radio
:selected (eq ,browser-option #'browse-text-xterm)]
"----"
["Toggle-URLs-in-New-Window"
(setq browse-url-new-window-flag (not browse-url-new-window-flag))
:style toggle
:selected browse-url-new-window-flag])))
;; List explicit buttons in the current buffer for menu activation.
(defun hui-menu-explicit-buttons (rest-of-menu)
(delq nil
(append
'(["Manual" (id-info "(hyperbole)Explicit Buttons") t]
"----")
(let ((labels (ebut:list))
(cutoff))
(if labels
(progn
;; Cutoff list if too long.
(if (setq cutoff (nthcdr (1- hui-menu-max-list-length) labels))
(setcdr cutoff nil))
(delq nil
(append
'("----"
["Alphabetize-List"
(setq hui-menu-order-explicit-buttons
(not hui-menu-order-explicit-buttons))
:style toggle :selected hui-menu-order-explicit-buttons]
"Activate:")
(mapcar (lambda (label) (vector label `(ebut:act ,label) t))
(if hui-menu-order-explicit-buttons
(sort labels #'string-lessp)
labels))
(if cutoff '(". . ."))
'("----" "----"))))))
rest-of-menu)))
(defun hui-menu-cutoff-list (lst)
"If list LST is longer than, `hui-menu-max-list-length', then cut it off there.
Return t if cutoff, else nil."
(let ((cutoff))
(if (setq cutoff (nthcdr (1- hui-menu-max-list-length) lst))
(setcdr cutoff nil))
(if cutoff t)))
;; List existing global buttons for menu activation.
(defun hui-menu-global-buttons (rest-of-menu)
(delq nil
(append
'(["Manual" (id-info "(hyperbole)Global Buttons") t]
"----")
(let ((labels (gbut:label-list))
(cutoff))
(when labels
;; Cutoff list if too long.
(setq cutoff (hui-menu-cutoff-list labels))
(delq nil (append
'("----" "Activate:")
(mapcar (lambda (label) (vector label `(gbut:act ,label) t))
(sort labels 'string-lessp))
(if cutoff '(". . ."))
'("----" "----")))))
rest-of-menu)))
(defun hui-menu-key-binding-item (item-name command)
"Return a key binding menu item string built from ITEM-NAME and COMMAND."
(concat item-name (when (where-is-internal command nil t)
(format "(%s)" (key-description (where-is-internal command nil t))))))
(defun hui-menu-key-bindings (rest-of-menu)
(nconc
(list
(vector (hui-menu-key-binding-item "Action-Key \t\t\t" 'hkey-either) '(hui:bind-key #'hkey-either) t) ;; {M-RET}
(vector (hui-menu-key-binding-item "Button-Rename-Key \t" 'hui:ebut-rename) '(hui:bind-key #'hui:ebut-rename) t) ;; None
(vector (hui-menu-key-binding-item "Drag-Emulation-Key \t\t" 'hkey-operate) '(hui:bind-key #'hkey-operate) t) ;; {M-o}
(vector (hui-menu-key-binding-item "Find-Web-Key \t\t" 'hui-search-web) '(hui:bind-key #'hui-search-web) t) ;; {C-c /}
(vector (hui-menu-key-binding-item "Grid-of-Windows-Key \t" 'hycontrol-windows-grid) '(hui:bind-key #'hycontrol-windows-grid) t) ;; {C-c @}
(vector (hui-menu-key-binding-item "Hyperbole-Menu-Key \t" 'hyperbole) '(hui:global-bind-key #'hyperbole) t) ;; {C-h h}
(vector (hui-menu-key-binding-item "Jump-Thing-Key \t\t" 'hui-select-goto-matching-delimiter) '(hui:bind-key #'hui-select-thing) t) ;; {C-c .}
(vector (hui-menu-key-binding-item "Mark-Thing-Key \t\t" 'hui-select-thing) '(hui:bind-key #'hui-select-thing) t) ;; {C-c RET}
(vector (hui-menu-key-binding-item "Smart-Help-Key \t\t" 'hkey-help) '(hui:bind-key #'hkey-help) t) ;; {C-h A}
(vector (hui-menu-key-binding-item "Windows-Control-Key\t" 'hycontrol-enable-windows-mode) '(hui:bind-key #'hycontrol-enable-windows-mode) t)) ;; {C-C \}
rest-of-menu))
;; Dynamically compute submenus for Screen menu
(defun hui-menu-screen (_ignored)
(list
["Manual" (id-info "(hyperbole)HyControl") t]
"----"
["Control-Frames" hycontrol-enable-frames-mode t]
["Control-Windows" hycontrol-enable-windows-mode t]
"----"
(hui-menu-of-buffers)
(hui-menu-of-frames)
(hui-menu-of-windows)))
(defun hui-menu-web-search ()
;; Pulldown menu
(let* (service
action)
(mapcar (lambda (service-and-action)
(setq service (car service-and-action)
action (cdr service-and-action))
(if (stringp action)
(vector service
(list #'hyperbole-web-search service nil)
t)
(vector service
;; a command symbol
action
t)))
hyperbole-web-search-alist)))
;;; ************************************************************************
;;; Public variables
;;; ************************************************************************
(defconst hui-menu-about
(vector (concat "About-Hyperbole-"
(if (= (aref hyperb:version 0) ?0)
(substring hyperb:version 1)
hyperb:version))
#'(hypb:display-file-with-logo "HY-ABOUT")
t))
(defconst hui-menu-options
(append '(["All-Hyperbole-Options" (customize-browse 'hyperbole) t]
"----"
["Hyperbole-on-Menubar"
(cond ((and (boundp 'menubar-configuration)
(not (memq 'Hyperbole menubar-configuration)))
;; Hyperbole may be included as part of the menubar but
;; may be invisible due to a menubar configuration
;; setting. Invoking this item should then make it
;; visible.
(hyperb:init-menubar))
((global-key-binding [menu-bar Hyperbole])
;; Already on the menubar, remove it.
(hui-menu-remove Hyperbole))
(t;; Add it.
(hyperb:init-menubar)))
:style toggle
:selected
(cond ((boundp 'menubar-configuration)
(memq 'Hyperbole menubar-configuration))
(t
(and (global-key-binding [menu-bar Hyperbole]) t)))]
"----"
["Find-File-Accepts-URLs"
hpath:find-file-urls-mode
:style toggle
:selected hpath:find-file-urls-mode]
"----")
'(("Change-Key-Bindings" :filter hui-menu-key-bindings))
'("----")
(list (cons "Display-Referents-in"
(mapcar (lambda (sym)
(vector
(capitalize (symbol-name sym))
`(setq hpath:display-where ',sym)
:style 'radio
:selected `(eq hpath:display-where ',sym)))
(mapcar #'car hpath:display-where-alist))))
'("----")
(hui-menu-browser "Display-URLs-in" browse-url-browser-function)
'("----")
(hui-menu-browser "Display-Web-Searches-in" hyperbole-web-search-browser-function)
'("----")
'(("Org-M-RETURN"
"----"
"----"
["All-Programmed-Contexts"
(customize-save-variable 'hsys-org-enable-smart-keys t)
:style radio :selected (when (boundp 'hsys-org-enable-smart-keys)
(eq hsys-org-enable-smart-keys t))]
["Hypb-Buttons-Only"
(customize-save-variable 'hsys-org-enable-smart-keys 'buttons)
:style radio :selected (when (boundp 'hsys-org-enable-smart-keys)
(eq hsys-org-enable-smart-keys 'buttons))]
["Ignore"
(customize-save-variable 'hsys-org-enable-smart-keys nil)
:style radio :selected (when (boundp 'hsys-org-enable-smart-keys)
(eq hsys-org-enable-smart-keys nil))]))
'("----")
'(("Smart-Key-Press-at-Eol"
"----"
"----"
;; This menu may be loaded by InfoDock before hsettings.el has
;; defined `smart-scroll-proportional'. Handle that case
;; with a conditional.
["Scrolls-a-Windowful"
(setq smart-scroll-proportional nil)
:style radio :selected (when (boundp 'smart-scroll-proportional)
(null smart-scroll-proportional))]
["Scrolls-Proportionally"
(setq smart-scroll-proportional t)
:style radio :selected (when (boundp 'smart-scroll-proportional)
smart-scroll-proportional)]))
'("----"
["Toggle-Isearch-Invisible-Text" hypb:toggle-isearch-invisible
:visible (boundp 'isearch-invisible)
:style toggle :selected (when (boundp 'isearch-invisible)
isearch-invisible)]
["Toggle-Messaging-Explicit-Buttons" hyperbole-toggle-messaging
:style toggle :selected (not inhibit-hyperbole-messaging)]
["Toggle-Rolo-Dates" hyrolo-toggle-datestamps
:style toggle :selected (and (boundp 'hyrolo-add-hook)
(listp hyrolo-add-hook)
(memq 'hyrolo-set-date hyrolo-add-hook))]
["Toggle-Smart-Key-Debug (HyDebug)" hkey-toggle-debug
:style toggle :selected hkey-debug]))
"Untitled menu of Hyperbole options.")
(defvar infodock-hyperbole-menu nil)
;;; ************************************************************************
;;; Public functions
;;; ************************************************************************
;; Add Hyperbole menu to menubar.
(defun hyperbole-menubar-menu ()
"Add to or update the Hyperbole menu on the global menubar."
(cond ((boundp 'menubar-configuration)
(unless (memq 'Hyperbole menubar-configuration)
;; Hyperbole may be included as part of the menubar but
;; may be invisible due to a menubar configuration
;; setting. Make it visible here.
(if (fboundp 'customize-set-variable)
(customize-set-variable 'menubar-configuration
(cons 'Hyperbole menubar-configuration))
(setq menubar-configuration
(cons 'Hyperbole menubar-configuration)))))
(t (let ((add-before (cond ((and (boundp 'infodock-menubar-type)
(eq infodock-menubar-type 'menubar-infodock))
"Key")
((global-key-binding [menu-bar Koutline])
"Koutline")
((global-key-binding [menu-bar OO-Browser])
"OO-Browser"))))
(easy-menu-add-item (current-global-map) '("menu-bar") (infodock-hyperbole-menu t) add-before))))
;; Force a menu-bar update.
(force-mode-line-update))
(defun hyperbole-popup-menu (&optional rebuild-flag)
"Popup the Hyperbole menubar menu."
(interactive "P")
(popup-menu (infodock-hyperbole-menu rebuild-flag)))
;;; Don't change this name; doing so will break the way InfoDock
;;; initializes the Hyperbole menu.
(defun infodock-hyperbole-menu (&optional rebuild-flag)
"Return the Hyperbole menu for the global InfoDock menubar.
Uses any non-nil existing value of the menu unless optional
REBUILD-FLAG is non-nil, in which case the menu is rebuilt."
(when (or rebuild-flag (null infodock-hyperbole-menu))
(setq infodock-hyperbole-menu
(delq nil
(list
"Hyperbole"
:config 'Hyperbole
hui-menu-about
["Demonstration" hyperbole-demo t]
;; Comment InfoDock manual reference out until
;; InfoDock is modernized for Emacs 25.
;; (if (and (boundp 'infodock-version) infodock-version)
;; ["Manual" (id-info "(infodock)Hyperbole Menu") t]
;; ["Manual" (id-info "(hyperbole)Top") t])
["Manual" (id-info "(hyperbole)Top") t]
["What-is-New?" (hypb:display-file-with-logo "HY-NEWS") t]
["Why-Use?" (find-file
(expand-file-name "HY-WHY.kotl" hyperb:dir)) t]
"----"
["Remove-This-Menu"
(progn
;; Delete Hyperbole menu from all menubars.
(hui-menu-remove Hyperbole)
;;
;; Remove Hyperbole button comment from future outgoing mail.
(when (boundp 'smail:comment) (setq smail:comment nil)))
t]
"----"
["Activate-Button-in-Buffer" hui:hbut-act t]
["Back-to-Prior-Location" hhist:pop
(and (boundp '*hhist*) *hhist*)]
'("Button-File"
["Manual" (id-info "(hyperbole)Button Files") t]
"----"
["Edit-Per-Directory-File" (find-file hbmap:filename) t]
["Edit-Personal-File" (find-file
(expand-file-name
hbmap:filename hbmap:dir-user)) t])
(cons "Customize" hui-menu-options)
'("Documentation"
["Manual" (id-info "(hyperbole)Top") t]
"----"
["Demonstration" hyperbole-demo t]
["Glossary" (id-info "(hyperbole)Glossary") t]
["Manifest" (hypb:display-file-with-logo "MANIFEST") t]
["Smart-Key-Summary" (id-browse-file (hypb:hkey-help-file)) t]
("Types"
["Action-Types-Manual"
(id-info "(hyperbole)Action Types") t]
["Implicit-Button-Types-Manual"
(id-info "(hyperbole)Implicit Buttons") t]
"----"
["Show-Action-Types"
(hui:htype-help-current-window 'actypes) t]
["Show-Implicit-Button-Types"
(hui:htype-help-current-window 'ibtypes 'no-sort) t]))
'("Explicit-Button"
:filter hui-menu-explicit-buttons
["Activate" hui:ebut-act t]
["Create" hui:ebut-create t]
["Delete" hui:ebut-delete t]
["Edit" hui:ebut-edit t]
("Help"
["Manual" (id-info "(hyperbole)Location") t]
"----"
["Buffer-Buttons" (hui:hbut-report -1) t]
["Current-Button" (hui:hbut-report) t]
["Ordered-Buttons" (hui:hbut-report 1) t])
["Rename" hui:ebut-rename t]
["Search" hui:ebut-search t]
["Types"
(hui:htype-help-current-window 'actypes) t])
(append
'("Find"
["Manual" (id-info-item "menu, Find") t]
"----"
;; Show numbered line matches in all specified files.
["Grep-Files" hypb:rgrep t]
;; Show numbered line matches for regexp in all file-based buffers.
["Locate-Files" locate t]
;; Show numbered line matches for regexp in all file-based buffers.
["Match-File-Buffers" moccur t]
;; Show numbered line matches for regexp from this buffer.
["Occur-Here" occur t]
;; Following point, remove all lines that match regexp.
["Remove-Lines-Here" hypb:remove-lines t]
;; Following point, keep only lines that match regexp.
["Save-Lines-Here" hypb:save-lines t]
"----"
"Web-Search:")
(hui-menu-web-search))
'("Global-Button"
:filter hui-menu-global-buttons
["Create" hui:gbut-create t]
["Delete" hui:gbut-delete t]
["Edit" hui:gbut-edit t]
["Help" gbut:help t]
["Rename" hui:gbut-rename t])
'("Implicit-Button"
["Manual" (id-info "(hyperbole)Implicit Buttons") t]
"----"
["Activate" hui:ibut-act t]
["Delete-Type" (hui:htype-delete 'ibtypes) t]
["Edit" hui:ibut-edit t]
["Help" hui:hbut-help t]
["Label" hui:ibut-label-create t]
["Rename" hui:ibut-rename t]
["Types" (hui:htype-help 'ibtypes 'no-sort) t])
'("Koutliner"
["Manual" (id-info "(hyperbole)Koutliner") t]
["Example" kotl-mode:example t]
"----"
["Create-File" kfile:find t]
["View-File" kfile:view t]
"----"
["Collapse-Tree" (progn (kotl-mode:is-p)
(kotl-mode:hide-tree
(kcell-view:label)))
(eq major-mode 'kotl-mode)]
["Create-Link" klink:create
(eq major-mode 'kotl-mode)]
["Expand-All-Trees" kotl-mode:show-all
(eq major-mode 'kotl-mode)]
["Expand-Tree" (progn (kotl-mode:is-p)
(kotl-mode:show-tree
(kcell-view:label)))
(eq major-mode 'kotl-mode)]
["Show-Top-Level-Only" kotl-mode:hide-body
(eq major-mode 'kotl-mode)])
'("Mail-Lists"
["Manual" (id-info "(hyperbole)Suggestion or Bug Reporting")
t]
"----"
["Mail-to-Hyperbole-Users-List"
(hmail:compose "[email protected]" '(hact 'hyp-config)) t]
["Mail-to-Hyperbole-Bug-Report-List"
(hmail:compose "[email protected]" '(hact 'hyp-config)) t]
"----"
["Join-Hyperbole-Users-List"
(hmail:compose "[email protected]" nil
"Just send the message; subject and body are ignored.") t]
["Join-Hyperbole-Bug-Report-List"
(hmail:compose "[email protected]" nil
"Just send the message; subject and body are ignored.") t]
"----"
["Leave-Hyperbole-Users-List"
(hmail:compose "[email protected]" nil
"Just send the message; subject and body are ignored.") t]
["Leave-Hyperbole-Bug-Report-List"
(hmail:compose "[email protected]" nil
"Just send the message; subject and body are ignored.") t])
infodock-hyrolo-menu
'("Screen (HyControl)" :filter hui-menu-screen)
hui-menu-hywconfig)))))
;;; ************************************************************************
;;; Private variables
;;; ************************************************************************
(defvar hui-menu-max-list-length 24
"Positive integer that caps the length of a Hyperbole dynamic menu lists.")
(defvar hui-menu-order-explicit-buttons t
"When non-nil (default), explicit button menu list is lexicographically ordered.
Otherwise, explicit buttons are listed in their order of appearance within
the current buffer.")
(provide 'hui-menu)
;;; hui-menu.el ends here