hyperbole / 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
;;!emacs
;;
;; FILE:         hui-menu.el
;; SUMMARY:      InfoDock/Emacs menubar menu of Hyperbole commands.
;; USAGE:        GNU Emacs Lisp Library
;; KEYWORDS:     hypermedia, mouse
;;
;; AUTHOR:       Bob Weiner
;; ORG:          BeOpen.com
;;
;; ORIG-DATE:    28-Oct-94 at 10:59:44
;; LAST-MOD:     24-Jun-99 at 05:43:08 by Bob Weiner
;;
;; Copyright (C) 1994, 1995, 1996, 1997  BeOpen.com and the Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of Hyperbole.
;;
;; DESCRIPTION:  
;; DESCRIP-END.

;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************

(require 'hpath)
(require 'wrolo-menu)
(require 'browse-url)

(if hyperb:emacs19-p (require 'lmenu))

;;; ************************************************************************
;;; Public functions
;;; ************************************************************************

;; Add Hyperbole menu to menubar.
(defun hyperbole-menubar-menu ()
  "Add the Hyperbole menu to the global 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.  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)))
	 (set-menubar-dirty-flag))
	((and (boundp 'current-menubar)
	      (or hyperb:emacs19-p current-menubar)
	      (not (car (find-menu-item current-menubar '("Hyperbole")))))
	 (let ((add-before (if (and (boundp 'infodock-menubar-type)
				    (eq infodock-menubar-type 'menubar-infodock))
			       "Key" nil)))
	   (if (fboundp 'add-submenu)
	       (add-submenu nil (infodock-hyperbole-menu) add-before)
	     (add-menu nil (car (infodock-hyperbole-menu))
		       (cdr (infodock-hyperbole-menu)) add-before))
	   ;; The next line forces a menubar refresh in some versions of XEmacs
	   ;; which have an event handler bug that prevents display of the
	   ;; Hyperbole menu on the menubar until the next user event occurs.
	   (sit-for 0.001)))))

;;; ************************************************************************
;;; Public variables
;;; ************************************************************************

;; Ensure that this variable is defined to avert any error within
;; the Customization menu.
(defvar highlight-headers-follow-url-netscape-new-window nil
  "*Whether to make Netscape create a new window when a URL is sent to it.")

(defconst hui-menu-url-options
  '("Display-URLs-in"
    "----"
    "----"
    ["Any-Netscape-Window"
     (setq browse-url-browser-function 'browse-url-netscape
	   browse-url-new-window-p nil)
     :style radio
     :selected
     (and (eq browse-url-browser-function 'browse-url-netscape)
	  (null browse-url-new-window-p))]
    ["Grail"
     (setq browse-url-browser-function 'browse-url-grail)
     :style radio
     :selected (eq browse-url-browser-function 'browse-url-grail)]
    ["Lynx"
     (setq browse-url-browser-function 'browse-url-lynx-xterm)
     :style radio
     :selected (eq browse-url-browser-function 'browse-url-lynx-xterm)]
    ["New-Netscape-Window"
     (setq browse-url-browser-function 'browse-url-netscape
	   browse-url-new-window-p t)
     :style radio
     :selected
     (and (eq browse-url-browser-function 'browse-url-netscape)
	  browse-url-new-window-p)]
    ["W3"
     (setq browse-url-browser-function 'browse-url-w3)
     :style radio
     :selected (eq browse-url-browser-function 'browse-url-w3)]
    )
  "Menu of Hyperbole URL display options.")

(defconst hui-menu-options
  (append '(["Customize Hyperbole..." hyperb:customize 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))
		   ((car (find-menu-item current-menubar '("Hyperbole")))
		    ;; Already on the menubar, remove it.
		    (hui-menu-remove))
		   (t;; Add it.
		    (hyperb:init-menubar)))
	     :style toggle
	     :selected
	      (if (boundp 'menubar-configuration)
		  (memq 'Hyperbole menubar-configuration)
		(and (boundp 'current-menubar)
		     (or hyperb:emacs19-p current-menubar)
		     (car (find-menu-item current-menubar '("Hyperbole")))))]
	    "----"
	    ["Find-File-Accepts-URLs"
	     hyperb:find-file-urls-mode
	     :style toggle
	     :selected hyperb:find-file-urls-mode]
	    "----"
	    "Display-Referents-in"
	    "----"
	    "----")
	  (mapcar (function (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-url-options
	  '("----"
	    "Smart-Key-Press-at-Eol"
	    "----"
	    "----"
	    ;; This menu may be loaded by InfoDock before hsite.el has
	    ;; defined `smart-scroll-proportional'.  Handle that case
	    ;; with a conditional.
	    ["Scrolls-a-Windowful"
	     (setq smart-scroll-proportional nil)
	     :style radio :selected (if (boundp 'smart-scroll-proportional)
					(null smart-scroll-proportional))]
	    ["Scrolls-Proportionally"
	     (setq smart-scroll-proportional t)
             :style radio :selected (if (boundp 'smart-scroll-proportional)
					smart-scroll-proportional)]
	    )
	  '("----"
	    ["Toggle-Rolo-Dates" rolo-toggle-datestamps
	     :style toggle :selected (and (boundp 'wrolo-add-hook)
					  (listp wrolo-add-hook)
					  (memq 'rolo-set-date wrolo-add-hook))]
	    ))
  "Untitled menu of Hyperbole options.")

;; Force reinitialization whenever this file is reloaded.
(defconst infodock-hyperbole-menu nil)
;;; Don't change this name; doing so will break the way InfoDock
;;; initializes the Hyperbole menu.
(defun infodock-hyperbole-menu ()
  "Hyperbole menu for the global InfoDock menubar"
  (or infodock-hyperbole-menu
      (setq infodock-hyperbole-menu
	    (delq nil
		  (list
		   "Hyperbole"
		   :config 'Hyperbole
		   '["About" (hypb:display-file-with-logo
			      (expand-file-name "HY-ABOUT" hyperb:dir)) t]
		   (if (and (boundp 'infodock-version) infodock-version)
		       '["Manual"      (id-info "(infodock.info)Hyperbole Menu") t]
		     '["Manual"      (id-info "(hyperbole.info)Top") t])
		   '["What-is-New?"  (hypb:display-file-with-logo
				      (expand-file-name "HY-NEWS" hyperb:dir)) t]
		   "----"
		   '["Remove-This-Menu"
		     (progn
		       ;; Delete Hyperbole menu item from all menubars.
		       (hui-menu-remove)
		       ;;
		       ;; Remove Hyperbole button comment from future
		       ;; outgoing mail.
		       (if (boundp 'smail:comment)
			   (setq smail:comment "")))
		     t]
		   "----"
		   '["Activate-Button-at-Point" hui:hbut-current-act
		     (hbut:is-p (hbut:at-p))]
		   '["Back-to-Prior-Location" (hhist:remove current-prefix-arg)
		     (and (boundp '*hhist*) *hhist*)]
		   '("Button-File"
		     ["Manual"  (id-info "(hyperbole.info)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 "Customization" hui-menu-options)
		   '("Documentation"
		     ["Manual"      (id-info "(hyperbole.info)Top") t]
		     "----"
		     ["Copyright"   (id-info "(hyperbole.info)Top") t]
		     ["Demonstration"  (hypb:display-file-with-logo
					(expand-file-name "DEMO" hyperb:dir)) t]
		     ["Glossary"    (id-info "(hyperbole.info)Glossary") t]
		     ["Manifest"    (find-file-read-only
				     (expand-file-name "MANIFEST" hyperb:dir)) t]
		     ["Msg-Forums"  (id-info "(hyperbole.info)Discussion Forums") t]
		     ["Smart-Key-Summary" (id-browse-file (hypb:mouse-help-file)) t]
		     )
		   '("Explicit-Button"
		     :filter hui-menu-explicit-buttons
		     ["Activate" hui:hbut-act t]
		     ["Create" hui:ebut-create t]
		     ["Delete" hui:ebut-delete t]
		     ["Edit"   hui:ebut-modify t]
		     ("Help"  
		      ["Manual"   (id-info "(hyperbole.info)Location") t]
		      "----"
		      ["Buffer-Buttons"   (hui:hbut-report -1) t]
		      ["Current-Button"   (hui:hbut-report)    t]
		      ["Ordered-Buttons"  (hui:hbut-report 1)  t]
		      )
		     ["Modify" hui:ebut-modify t]
		     ["Rename" hui:ebut-rename t]
		     ["Search" hui:ebut-search t]
		     )
		   '("Global-Button"
		     :filter hui-menu-global-buttons
		     ["Create" hui:gbut-create t]
		     ["Edit"   hui:gbut-modify t]
		     ["Help"   gbut:help t]
		     ["Modify" hui:gbut-modify t]
		     )
		   '("Implicit-Button"
		     ["Manual"   (id-info "(hyperbole.info)Implicit Buttons") t]
		     "----"
		     ["Activate-at-Point"    hui:hbut-current-act t]
		     ["Delete-Type"         (hui:htype-delete 'ibtypes) t]
		     ["Help"   hui:hbut-help t]
		     ["Types"  (hui:htype-help 'ibtypes 'no-sort) t]
		     )
		   '("Mail-Lists"
		     ["Manual" (id-info "(hyperbole.info)Suggestion or Bug Reporting")
		      t]
		     "----"
;		     ["Change-Hyperbole-Address"
;		      (hmail:compose "hyperbole-request@beopen.com"
;				     '(hact 'hyp-request)) t]
;		     ["Change-Hyperbole-Announce-Address"
;		      (hmail:compose "hyperbole-request@beopen.com"
;				     '(hact 'hyp-request)) t]
		     ["Mail-to-Hyperbole-List"
		      (hmail:compose "hyperbole-discuss@xemacs.org" '(hact 'hyp-config)) t]
		     )
		   (if hyperb:kotl-p
		       '("Outline"
			 ["Manual" (id-info "(hyperbole.info)Outliner") 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)]
			 ))
		   infodock-wrolo-menu
		   '("Types"
		     ["Action-Types-Manual"
		      (id-info "(hyperbole.info)Action Types") t]
		     ["Implicit-Button-Types-Manual"
		      (id-info "(hyperbole.info)Implicit Buttons") t]
		     "----"
		     ["Action-Types"      (hui:htype-help 'actypes) t]
		     ["Implicit-Button-Types" (hui:htype-help 'ibtypes 'no-sort) t]
		     )
		   '("Window-Configuration"
		     ["Manual" (id-info "(hyperbole.info)Window Configurations") t]
		     "----"
		     ["Name-Configuration" wconfig-add-by-name     t]
		     ["Delete-Name"        wconfig-delete-by-name
		      (if (boundp 'wconfig-names) wconfig-names)]
		     ["Restore-Name"       wconfig-restore-by-name
		      (if (boundp 'wconfig-names) wconfig-names)]
		     "----"
		     ["Pop-from-Ring"      wconfig-delete-pop
		      (if (boundp 'wconfig-ring) wconfig-ring)]
		     ["Save-to-Ring"       wconfig-ring-save       t]
		     ["Yank-from-Ring"     wconfig-yank-pop
		      (if (boundp 'wconfig-ring) wconfig-ring)]
		     ))))))

;;; ************************************************************************
;;; Public functions
;;; ************************************************************************

(defun hui-menu-remove ()
  "Remove \"Hyperbole\" menu from all menubars."
  (if (boundp 'menubar-configuration)
      (if (memq 'Hyperbole menubar-configuration)
	  (if (fboundp 'customize-set-variable)
	      (customize-set-variable 'menubar-configuration
				      (delq 'Hyperbole menubar-configuration))
	    (setq menubar-configuration 
		  (delq 'Hyperbole menubar-configuration))))
    (mapcar (function
	     (lambda (buf)
	       (set-buffer buf)
	       (if (assoc "Hyperbole" current-menubar)
		   (delete-menu-item '("Hyperbole")))))
	    (buffer-list))))

;;; ************************************************************************
;;; Private functions
;;; ************************************************************************

(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.")

;; 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.info)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 (function (lambda (label)
					    (vector label `(ebut:act ,label) t)))
				(if hui-menu-order-explicit-buttons
				    (sort labels 'string-lessp)
				  labels))
			(if cutoff '(". . ."))
			'("----" "----"))))))
	 rest-of-menu)))

;; List existing global buttons for menu activation.
(defun hui-menu-global-buttons (rest-of-menu)
  (delq nil
	(append
	 '(["Manual" (id-info "(hyperbole.info)Global Buttons") t]
	   "----")
	 (let ((labels (gbut:label-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
			'("----" "Activate:")
			(mapcar (function (lambda (label)
					    (vector label `(gbut:act ,label) t)))
				(sort labels 'string-lessp))
			(if cutoff '(". . ."))
			'("----" "----"))))))
	 rest-of-menu)))

;;; ************************************************************************
;;; Private variables
;;; ************************************************************************

(provide 'hui-menu)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.