]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/nxhtml/nxhtml-menu.el
09c7f4b691905a486a4887bed50f2db10d630692
[.emacs.d.git] / emacs / nxhtml / nxhtml / nxhtml-menu.el
1 ;;; nxhtml-menu.el --- Defines menus for nXhtml
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: Sat Apr 21 2007
5 ;; Moved version to autostart.el.
6 ;; Last-Updated: 2010-01-04 Mon
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;; Menus for nXhtml to be used in different major modes.
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;;; Change log:
24 ;;
25 ;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;
28 ;; This program is free software; you can redistribute it and/or
29 ;; modify it under the terms of the GNU General Public License as
30 ;; published by the Free Software Foundation; either version 2, or
31 ;; (at your option) any later version.
32 ;;
33 ;; This program is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36 ;; General Public License for more details.
37 ;;
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program; see the file COPYING.  If not, write to
40 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
41 ;; Floor, Boston, MA 02110-1301, USA.
42 ;;
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;
45 ;;; Code:
46
47 (eval-when-compile (require 'cl))
48 (eval-when-compile (require 'cus-edit))
49 (eval-when-compile (require 'dired))
50 (eval-when-compile (require 'gimpedit nil t))
51 (eval-when-compile (require 'html-site nil t))
52 (eval-when-compile (when (fboundp 'nxml-mode) (require 'nxhtml-mode nil t)))
53 (eval-when-compile (require 'css-color nil t))
54 (eval-when-compile (require 'flymake))
55 ;;(eval-when-compile (require 'flymake-php))
56 (eval-when-compile (require 'flymake-js nil t))
57 (eval-when-compile (require 'mumamo nil t))
58 (eval-when-compile (require 'nxhtml-base))
59 (eval-when-compile (require 'udev-ecb nil t))
60 ;;(eval-when-compile (require 'udev-cedet))
61 (eval-when-compile (require 'udev-rinari nil t))
62
63 (defun nxhtml-nxhtml-in-buffer ()
64   (or (derived-mode-p 'nxhtml-mode)
65       (when (and (boundp 'mumamo-multi-major-mode)
66                  mumamo-multi-major-mode)
67         (let ((major-mode (mumamo-main-major-mode)))
68           (derived-mode-p 'nxhtml-mode)))))
69
70 (defun nxhtml-nxml-in-buffer ()
71   (or (derived-mode-p 'nxml-mode)
72       (when (and (boundp 'mumamo-multi-major-mode)
73                  mumamo-multi-major-mode)
74         (let ((major-mode (mumamo-main-major-mode)))
75           (derived-mode-p 'nxml-mode)))))
76
77 (defun nxhtml-html-in-buffer ()
78   (or (derived-mode-p 'html-mode)
79       (when (and (boundp 'mumamo-multi-major-mode)
80                  mumamo-multi-major-mode)
81         (let ((major-mode (mumamo-main-major-mode)))
82           (derived-mode-p 'html-mode)))
83       (nxhtml-nxhtml-in-buffer)))
84
85 (defun nxhtml-nxml-html-in-buffer ()
86   (or (derived-mode-p 'html-mode)
87       (when (and (boundp 'mumamo-multi-major-mode)
88                  mumamo-multi-major-mode)
89         (let ((major-mode (mumamo-main-major-mode)))
90           (derived-mode-p 'html-mode)))
91       (nxhtml-nxml-in-buffer)))
92
93 (defun buffer-or-dired-file-name ()
94   "Return buffer file name or file pointed to in dired."
95   (if (derived-mode-p 'dired-mode)
96       (dired-get-file-for-visit)
97     buffer-file-name))
98
99 (defun nxhtml-this-file-can-have-toc (&optional file)
100   (unless file
101     (setq file (buffer-or-dired-file-name)))
102   (and (nxhtml-buffer-possibly-local-viewable file)
103        (html-site-current-merge-dir)
104        (html-site-current-ensure-file-in-site file)))
105
106 (defun nxhtml-buffer-possibly-local-viewable (&optional file)
107   (unless file
108     (setq file (buffer-or-dired-file-name)))
109   (or (and file
110            (member (file-name-extension file)
111                    '("html" "htm" "gif" "png")))))
112
113 (defun nxhtml-buffer-possibly-remote-viewable ()
114   ;; Fix-me
115   (let* ((fmt "nxhtml-buffer-possibly-remote-viewable.dgffv: %s")
116          (file (or buffer-file-name
117                    (and (derived-mode-p 'dired-mode)
118                         (condition-case err
119                             (dired-get-file-for-visit)
120                           (error
121                            (message fmt (error-message-string err))
122                            nil))))))
123     (and (featurep 'html-upl)
124          file
125          (member (downcase (file-name-extension file))
126                  '("html" "htm" "gif" "png" "pl" "php")))))
127
128 ;; (nxhtml-insert-menu-dynamically 'temp)
129 (defun nxhtml-insert-menu-dynamically (real-binding)
130   (or (and (symbolp real-binding)
131            (boundp real-binding)
132            (symbol-value real-binding))
133       (let ((map (make-sparse-keymap "Not loaded yet")))
134         (define-key map [dummy]
135           (list 'menu-item "Not loaded yet" 'ignore))
136         map)
137       ;; (easy-menu-filter-return
138       ;;  (easy-menu-create-menu
139       ;;   "Not ready"
140       ;;   '(["Not Loaded Yet" ignore t])))
141       ))
142
143 (defun nxhtml-menu-image-file ()
144   (or (get-char-property (point) 'image-file)
145       buffer-file-name))
146
147 (defun nxhtml-gimp-can-edit ()
148   (or (not (featurep 'gimp))
149       (gimpedit-can-edit (nxhtml-menu-image-file))))
150
151 ;;;###autoload
152 (defun nxhtml-edit-with-gimp ()
153   "Edit with GIMP buffer or file at point."
154   (interactive)
155   (gimpedit-edit-file (nxhtml-menu-image-file)))
156
157 ;;;###autoload
158 (defun nxhtml-browse-file (file)
159   "View file in web browser."
160   (interactive (list
161                 (or (buffer-or-dired-file-name)
162                     (read-file-name "File: "))))
163   (let* ((buf (if (buffer-file-name)
164                   (current-buffer)
165                 (find-buffer-visiting file)))
166          (use-temp (and (buffer-file-name)
167                         (or (and (boundp 'nxhtml-current-validation-header)
168                                  nxhtml-current-validation-header)
169                             (buffer-modified-p)
170                             (not buffer-file-name)
171                             (not (file-exists-p buffer-file-name)))))
172          (file-to-browse file))
173     (when use-temp
174       (setq file-to-browse (nxhtml-save-browseable-temp-file nil nil use-temp)))
175     ;; Fix-me: Workaround for Emacs bug on w32
176     ;; http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=4015
177     (if (eq system-type 'windows-nt)
178         (w32-shell-execute nil (concat "file:///" file-to-browse) nil 1)
179       (browse-url-of-file file-to-browse))
180     ))
181
182 ;;;###autoload
183 (defun nxhtml-browse-region ()
184   "View region in web browser."
185   (interactive)
186   (unless mark-active
187     (error "The region is not active"))
188   (browse-url (nxhtml-save-browseable-temp-file (region-beginning) (region-end))))
189
190 ;;(defvar nxhtml-browseable-buffer-name "*nXhtml Browsing Buffer*")
191 (defvar nxhtml-browseable-buffer-file "~/.temp-nxhtml-browse.htm")
192 ;; Fix-me: Handle base href here!
193 (defun nxhtml-save-browseable-temp-file (start end &optional doit-anyway)
194   "Return a temporary file for viewing in web browser."
195   ;; When using this either region should be active or there should be
196   ;; a validation header or both.
197   (or doit-anyway
198       (and start end) ;mark-active
199       (and (boundp 'nxhtml-validation-header-mode)
200            nxhtml-validation-header-mode
201            nxhtml-current-validation-header)
202       (error "Neither region nor validation header"))
203   (save-excursion
204     (let ((curbuf (current-buffer))
205           (view-buffer (find-file-noselect nxhtml-browseable-buffer-file))
206           header
207           content)
208       ;; Get header and content
209       (save-restriction
210         (widen)
211         (setq header
212               (if nxhtml-validation-header-mode
213                   (let* ((key nxhtml-current-validation-header)
214                          (rec (unless (listp key)
215                                 (assoc key nxhtml-validation-headers)))
216                          (header (cdr rec)))
217                     header)
218                 (if (and doit-anyway (not start))
219                     ""
220                   (goto-char (point-min))
221                   (save-match-data
222                     (let ((body (re-search-forward "<body[^>]*>")))
223                       (if body
224                           (buffer-substring-no-properties (point-min) (match-end 0))
225                         ""))))))
226         (setq content
227               (if start
228                   (buffer-substring-no-properties start end)
229                 (buffer-substring-no-properties (point-min) (point-max))))
230         )
231       ;; Switch to view buffer
232       (set-buffer view-buffer)
233       ;;       (unless buffer-file-name
234       ;;         (set-visited-file-name nxhtml-browseable-buffer-file)
235       ;;         (rename-buffer nxhtml-valhead-view-buffer-name))
236       (erase-buffer)
237       (insert header content)
238       ;;(when (fboundp 'emacsw32-eol-set) (emacsw32-eol-set nil))
239       (nxhtml-mode)
240       (save-buffer)
241       ;;(current-buffer)
242       (kill-buffer view-buffer)
243       (expand-file-name nxhtml-browseable-buffer-file)
244       )))
245
246
247
248 (defvar nxhtml-menu-mode-menu-map
249   (let ((map (make-sparse-keymap "nxhtml-menu-mode-menu")))
250
251     (let ((help-map (make-sparse-keymap)))
252       (define-key help-map [emacs-Q-nxhtml]
253         (list 'menu-item "Start 'emacs -Q' and load nXhtml" 'emacs-Q-nxhtml))
254       (define-key help-map [nxhtmltest-run]
255         (list 'menu-item "Run nXhtml Tests in Current Emacs" 'nxhtmltest-run))
256       (define-key help-map [nxhtmltest-run-Q]
257         (list 'menu-item "Run nXhtml Tests in a Fresh Emacs" 'nxhtmltest-run-Q))
258       (define-key help-map [nxhtml-report-bug]
259         (list 'menu-item "Report a Bug in nXhtml ..." 'nxhtml-report-bug))
260       (define-key help-map [nxhtml-help-separator2] (list 'menu-item "--"))
261       (define-key help-map [nxhtml-byte-compile-nxhtml]
262         (list 'menu-item "Byte Compile nXhtml" 'nxhtmlmaint-start-byte-compilation))
263       ;; Downloads
264       (let ((download-map (make-sparse-keymap)))
265         (define-key help-map [nxhtml-downloading]
266           (list 'menu-item "Download nXhtml Updates" download-map))
267         (define-key download-map [nxhtml-web-download-log]
268           (list 'menu-item "View Download Log" 'web-vcs-log-edit))
269         (define-key download-map [nxhtml-view-dl-log-separator]
270           (list 'menu-item "--" nil))
271         (define-key download-map [nxhtml-web-auto-download]
272           (list 'menu-item "Auto download from Devel Sources"
273                 'nxhtml-autoload-web
274                 :button '(:toggle . (and (boundp 'nxhtml-autoload-web)
275                                          nxhtml-autoload-web))))
276         (define-key download-map [nxhtml-web-download]
277           (list 'menu-item "Update nXhtml (from devel sources)" 'nxhtml-update-existing-files))
278         )
279       (define-key help-map [nxhtml-features-check]
280         (list 'menu-item "Check Optional Features" 'nxhtml-features-check))
281       (define-key help-map [nxhtml-list-multi-modes]
282         (list 'menu-item "List Available Multi Major Modes" 'mumamo-list-defined-multi-major-modes))
283       (define-key help-map [nxhtml-customize]
284         (list 'menu-item "Customize nXhtml ..." 'nxhtml-customize))
285 ;;;       (define-key help-map [nxhtml-quick-customize]
286 ;;;         (list 'menu-item "Quick Customize nXhtml ..." 'nxhtml-quick-customize))
287       (define-key help-map [nxhtml-help-separator3] (list 'menu-item "--"))
288 ;;;       (define-key help-map [nxhtml-help]
289 ;;;         (list 'menu-item "nXhtml Help" 'nxhtml-help))
290       (define-key help-map [nxhtml-tutorials]
291         (list 'menu-item "nXhtml Tutorials" 'nxhtml-tutorials))
292       (define-key help-map [nxhtml-overview]
293         (list 'menu-item (concat "nXhtml Version "
294                                  (if (boundp 'nxhtml-menu:version)
295                                      nxhtml-menu:version
296                                    "(unknown)")
297                                  " Overview")
298               'nxhtml-overview))
299       (define-key help-map [nxhtml-welcome]
300         (list 'menu-item "Welcome to nXhtml" 'nxhtml-welcome))
301       (define-key map [nxhtml-help-map]
302         (list 'menu-item "nXhtml Help and Setup" help-map))
303       (define-key map [nxhtml-info-separator] (list 'menu-item "--"))
304       )
305
306
307
308
309     (let ((tools-map (make-sparse-keymap)))
310       (define-key map [nxhtml-tools-map]
311         (list 'menu-item "Tools" tools-map))
312       (define-key tools-map [nxhtml-last-resort]
313         (list 'menu-item "Last Resort" 'n-back-game))
314       (define-key tools-map [nxhtml-pause]
315         (list 'menu-item "Life Reminder" 'pause-start-in-new-emacs))
316       (define-key tools-map [nxhtml-last-resort-separator]
317         (list 'menu-item "--" nil))
318       (define-key tools-map [nxhtml-viper-tut]
319         (list 'menu-item "Viper Try-Out Tutorial"
320               'viper-tutorial))
321       (define-key tools-map [nxhtml-viper-separator]
322         (list 'menu-item "--" nil))
323       ;;(define-key tools-map [nxhtml-frame-win-separator] (list 'menu-item "--" nil))
324       (define-key tools-map [nxhtml-resize-windows]
325         (list 'menu-item "Resize Windows"
326               'resize-windows))
327
328
329
330       (define-key tools-map [nxhtml-ecb-separator]
331         (list 'menu-item "--" nil))
332
333
334       (let ((ecb-map (make-sparse-keymap)))
335         (define-key tools-map [nxhtml-ecb-map]
336           (list 'menu-item "ECB" ecb-map))
337         (define-key ecb-map [nxhtml-custom-important-ecb]
338           (list 'menu-item "Customize important ECB things"
339                 (lambda ()
340                   "Customize group `ecb-most-important'."
341                   (interactive)
342                   (customize-group-other-window 'ecb-most-important))
343                 :enable '(featurep 'ecb)))
344         (define-key ecb-map [nxhtml-ecb-mode]
345           (list 'menu-item "ECB Minor Mode"
346                 'ecb-minor-mode
347                 :button '(:toggle . (and (boundp 'ecb-minor-mode)
348                                          ecb-minor-mode))
349                 :enable '(boundp 'ecb-minor-mode)))
350         (define-key ecb-map [nxhtml-ecb-show-help]
351           (list 'menu-item "ECB Help"
352                 'ecb-show-help
353                 :enable '(fboundp 'ecb-show-help)))
354         (define-key ecb-map [nxhtml-ecb-custom-separator]
355           (list 'menu-item "--" nil))
356         (define-key ecb-map [nxhtml-custom-ecb]
357           (list 'menu-item "Customize ECB dev startup from nXhtml"
358                 'udev-ecb-customize-startup))
359         (define-key ecb-map [nxhtml-update-ecb]
360           (list 'menu-item "Fetch/update ECB dev sources"
361                 'udev-ecb-update))
362         (define-key ecb-map [nxhtml-ecb-home-separator]
363           (list 'menu-item "--" nil))
364         (define-key ecb-map [nxhtml-rinari-homepage]
365           (list 'menu-item "ECB Home Page"
366                 (lambda ()
367                   "Open ECB home page in your web browser."
368                   (interactive)
369                   (browse-url "http://ecb.sourceforge.net/"))))
370         )
371
372
373       ;; (let ((cedet-map (make-sparse-keymap)))
374       ;;   (define-key tools-map [nxhtml-cedet-map]
375       ;;     (list 'menu-item "CEDET" cedet-map))
376       ;;   (define-key cedet-map [nxhtml-custom-cedet]
377       ;;     (list 'menu-item "Customize CEDET dev startup from nXhtml"
378       ;;           'udev-cedet-customize-startup))
379       ;;   (define-key cedet-map [nxhtml-cedet-utest]
380       ;;     (list 'menu-item "Run CEDET unit tests"
381       ;;           'udev-cedet-utest))
382       ;;   (define-key cedet-map [nxhtml-update-cedet]
383       ;;     (list 'menu-item "Fetch/update and install CEDET dev sources"
384       ;;           'udev-cedet-update))
385       ;;   (define-key cedet-map [nxhtml-cedet-home-separator]
386       ;;     (list 'menu-item "--" nil))
387       ;;   (define-key cedet-map [nxhtml-rinari-homepage]
388       ;;     (list 'menu-item "CEDET Home Page"
389       ;;           (lambda ()
390       ;;             "Open CEDET home page in your web browser."
391       ;;             (interactive)
392       ;;             (browse-url "http://cedet.sourceforge.net/"))))
393       ;;   )
394
395
396       (let ((rinari-map (make-sparse-keymap)))
397         (define-key tools-map [nxhtml-rinari-map]
398           (list 'menu-item "Rinari" rinari-map))
399         (define-key rinari-map [nxhtml-custom-rinari]
400           (list 'menu-item "Customize Rinari startup from nXhtml"
401                 (lambda ()
402                   "Customize Rinari dev nXhtml startup options."
403                   (interactive)
404                   (customize-group-other-window 'udev-rinari))))
405         (define-key rinari-map [nxhtml-update-rinari]
406           (list 'menu-item "Fetch/update Rinari dev sources"
407                 'udev-rinari-update))
408         (define-key rinari-map [nxhtml-rinari-home-separator]
409           (list 'menu-item "--" nil))
410         (define-key rinari-map [nxhtml-rinari-homepage]
411           (list 'menu-item "Rinari Home Page"
412                 (lambda ()
413                   "Open Rinari home page in your web browser."
414                   (interactive)
415                   (browse-url "http://rubyforge.org/projects/rinari/"))))
416         )
417       (let ((mozrepl-map (make-sparse-keymap)))
418         (define-key tools-map [nxhtml-mozrepl-map]
419           (list 'menu-item "MozRepl - control Firefox" mozrepl-map))
420
421         (let ((mozrepl-low-map (make-sparse-keymap)))
422           (define-key mozrepl-map [nxhtml-mozrepl-map]
423             (list 'menu-item "MozRepl Basic Functions" mozrepl-low-map))
424           (define-key mozrepl-low-map [nxhtml-mozrepl-run-mozilla]
425             (list 'menu-item "Display/Start MozRepl Process" 'run-mozilla
426                   :enable '(fboundp 'moz-minor-mode)))
427           (define-key mozrepl-low-map [nxhtml-mozrepl-separator1]
428             (list 'menu-item "--" nil))
429           (define-key mozrepl-low-map [nxhtml-mozrepl-save-and-send]
430             (list 'menu-item "Save Buffer and Send it" 'moz-save-buffer-and-send
431                   :enable '(or (not (boundp 'mumamo-multi-major-mode))
432                                (not mumamo-multi-major-mode))))
433           (define-key mozrepl-low-map [nxhtml-mozrepl-send-defun-and-go]
434             (list 'menu-item "Send Current Function, Go to MozRepl"
435                   'moz-send-defun-and-go
436                   :enable '(and (boundp 'moz-minor-mode) moz-minor-mode)))
437           (define-key mozrepl-low-map [nxhtml-mozrepl-send-defun]
438             (list 'menu-item "Send Current Function" 'moz-send-defun
439                   :enable '(and (boundp 'moz-minor-mode) moz-minor-mode)))
440           (define-key mozrepl-low-map [nxhtml-mozrepl-send-region]
441             (list 'menu-item "Send the Region" 'moz-send-region
442                   :enable '(and mark-active
443                                 (boundp 'moz-minor-mode) moz-minor-mode))))
444
445         (define-key mozrepl-map [nxhtml-mozrepl-separator2]
446           (list 'menu-item "--" nil))
447         (define-key mozrepl-map [nxhtml-mozrepl-refresh]
448           (list 'menu-item "Refresh Firefox on Save" 'mozadd-refresh-edited-on-save-mode
449                 :button '(:toggle . (and (boundp 'mozadd-refresh-edited-on-save-mode)
450                                          mozadd-refresh-edited-on-save-mode))))
451         (define-key mozrepl-map [nxhtml-mozrepl-mirror]
452           (list 'menu-item "Mirror Buffer in Firefox" 'mozadd-mirror-mode
453                 :button '(:toggle . (and (boundp 'mozadd-mirror-mode)
454                                          mozadd-mirror-mode))))
455         (define-key mozrepl-map [nxhtml-mozrepl-separator3]
456           (list 'menu-item "--" nil))
457         (define-key mozrepl-map [nxhtml-mozrepl-home-page]
458           (list 'menu-item "MozLab/MozRepl Home Page"
459                 (lambda ()
460                   "Open MozLab/MozRepl home page in your web browser."
461                   (interactive)
462                   (browse-url "http://hyperstruct.net/projects/mozlab"))))
463         )
464
465       (define-key tools-map [nxhtml-ediff-url]
466         (list 'menu-item "Compare download file" 'ediff-url))
467       (define-key tools-map [nxhtml-investigate-elisp]
468         (list 'menu-item "Investigate Elisp File" 'web-vcs-investigate-elisp-file))
469
470       (define-key tools-map [nxhtml-tidy-separator]
471         (list 'menu-item "--" nil))
472       (define-key tools-map [nxhtml-flymake]
473         (list 'menu-item "Flymake Mode" 'flymake-mode
474               :button '(:toggle . (and (boundp 'flymake-mode)
475                                        flymake-mode))
476               :enable '(and buffer-file-name
477                             (require 'flymake)
478                             (fboundp 'flymake-get-init-function)
479                             (flymake-get-init-function buffer-file-name)
480                             )))
481       (let ((flyspell-map (make-sparse-keymap)))
482         (define-key tools-map [nxhtml-flyspell-map]
483           (list 'menu-item "Flyspell" flyspell-map))
484         (define-key flyspell-map [nxhtml-flyspell-goto-next]
485           (list 'menu-item "Flyspell Go To Next Error" 'flyspell-goto-next-error
486                 :enable 'flyspell-mode))
487         (define-key flyspell-map [nxhtml-flyspell-region]
488           (list 'menu-item "Flyspell Region" 'flyspell-region
489                 :enable 'flyspell-mode))
490         (define-key flyspell-map [nxhtml-flyspell-div-1]
491           (list 'menu-item "--"))
492         (define-key flyspell-map [nxhtml-flyspell]
493           (list 'menu-item "Flyspell Mode" 'flyspell-mode
494                 :button '(:toggle . (and (boundp 'flyspell-mode)
495                                          flyspell-mode))))
496         )
497       (define-key tools-map [nxhtml-flyspell-separator]
498         (list 'menu-item "--"))
499       (let ((img-map (make-sparse-keymap)))
500         (define-key tools-map [nxhtml-img-map]
501           (list 'menu-item "Images" img-map))
502         (define-key img-map [nxhtml-chartg]
503           (list 'menu-item "Make Chart" 'chartg-make-chart))
504         (define-key img-map [nxhtml-chartg-separator] (list 'menu-item "--"))
505         (define-key img-map [nxhtml-gimp-edit]
506           (list 'menu-item "Edit with GIMP" 'nxhtml-edit-with-gimp
507                 :enable '(nxhtml-gimp-can-edit)))
508         (define-key img-map [nxhtml-gimp-separator] (list 'menu-item "--"))
509         (define-key img-map [nxhtml-inlimg-toggle-display]
510           (list 'menu-item "Toggle Display of Image" 'inlimg-toggle-display))
511         (define-key img-map [nxhtml-inlimg-toggle-slicing]
512           (list 'menu-item "Toggle Slicing of Image" 'inlimg-toggle-slicing))
513         (define-key img-map [nxhtml-inlimg-mode]
514           (list 'menu-item "Show <img ...> Images" 'inlimg-mode
515                 :button '(:toggle . (and (boundp 'inlimg-mode)
516                                          inlimg-mode)))))
517       (define-key tools-map [nxhtml-img-separator]
518         (list 'menu-item "--"))
519       (let ((some-help-map (make-sparse-keymap)))
520         (define-key tools-map [nxhtml-some-help-map]
521           (list 'menu-item "Help for Item at Point" some-help-map))
522         (define-key some-help-map [nxhtml-css-help]
523           (list 'menu-item "CSS Help" 'xhtml-help-show-css-ref))
524         (define-key some-help-map [nxhtml-tag-help]
525           (list 'menu-item "XHTML Tag Help" 'nxhtml-short-tag-help)))
526
527       (let ((cssclr-map (make-sparse-keymap)))
528         (define-key tools-map [nxhtml-css-color]
529           (list 'menu-item "Color Help" cssclr-map))
530         (define-key cssclr-map [nxhtml-css-color-mode]
531           (list 'menu-item "Css Color Mode" 'css-color-mode
532                 :enable '(and font-lock-mode
533                               ;; (or (not (boundp 'mumamo-multi-major-mode))
534                               ;;     (not mumamo-multi-major-mode))
535                               ;; (featurep 'css-color)
536                               )
537                 :button '(:toggle . (and (boundp 'css-color-mode)
538                                          css-color-mode))))
539         (define-key cssclr-map [nxhtml-css-color-test]
540           (list 'menu-item "Color Test" 'css-color-test
541                 ;; :enable '(featurep 'css-color)
542                 )))
543
544       (define-key tools-map [nxhtml-help-separator]
545         (list 'menu-item "--"))
546
547
548       (let ((html-link-map (make-sparse-keymap)))
549         (define-key tools-map [nxhtml-link-map]
550           (list 'menu-item "HTML Links" html-link-map
551                 :enable '(nxhtml-html-in-buffer)))
552
553         (define-key html-link-map [nxhtml-chklnk]
554           (list 'menu-item "Check Links" 'html-chklnk-check-site-links
555                 :enable '(featurep 'html-chklnk)))
556
557         (let ((move-map (make-sparse-keymap)))
558           (define-key html-link-map [move-map]
559             (list 'menu-item "Moving Files" move-map))
560           (define-key move-map [html-move-buffer-file]
561             (list 'menu-item "Move Buffer File" 'html-move-buffer-file
562                   :help "Move buffer file and update links"
563                   :enable '(and buffer-file-name
564                                 (featurep 'html-move))))
565           (define-key html-link-map [move-map-separator] (list 'menu-item "--"))
566           )
567
568
569         (define-key html-link-map [nxhtml-paste-link]
570           (list 'menu-item "Paste Saved Relative Link" 'nxhtml-paste-link
571                 :help "Paste link"
572                 :enable '(and (boundp 'nxhtml-saved-link-file)
573                               nxhtml-saved-link-file)))
574         (define-key html-link-map [nxhtml-paste-link-as-a-tag]
575           (list 'menu-item "Paste Saved Relative Link as <a href=...>" 'nxhtml-paste-link-as-a-tag
576                 :help "Paste link as <a ...> tag"
577                 :enable '(and (boundp 'nxhtml-saved-link-file)
578                               nxhtml-saved-link-file
579                               (nxhtml-nxml-html-in-buffer))))
580         (define-key html-link-map [nxhtml-save-link-to-here]
581           (list 'menu-item "Save Relative Link to Current File" 'nxhtml-save-link-to-here
582                 :help "Save link info for current file"
583                 :enable 'buffer-file-name))
584         )
585
586     (let ((quick-map (make-sparse-keymap)))
587       (define-key tools-map [nxhtml-quick-map]
588         (list 'menu-item "Quick Inserts etc" quick-map
589               :visible '(or (derived-mode-p 'html-mode)
590                             (nxhtml-nxhtml-in-buffer))))
591       (let ((sometoc-map (make-sparse-keymap)))
592         (let ((toc-map (make-sparse-keymap)))
593           (define-key sometoc-map [nxhtml-toc-map]
594             (list 'menu-item "For Site" toc-map
595                   :enable '(featurep 'html-toc)))
596           (define-key toc-map [nxhtml-html-wtoc]
597             (list 'menu-item "Merge Pages and TOC"
598                   'html-wtoc-write-pages-with-toc
599                   :enable '(or (not (featurep 'html-site))
600                                (html-site-current-page-list))))
601           (define-key toc-map [nxthml-html-toc]
602             (list 'menu-item "With Frames" 'html-toc-menu-map
603                   :filter 'nxhtml-insert-menu-dynamically)))
604         (define-key sometoc-map [nxhtml-html-pagetoc]
605           (list 'menu-item "For Page" 'html-pagetoc-menu-map
606                 :enable (boundp 'html-pagetoc-menu-map)
607                 :filter 'nxhtml-insert-menu-dynamically
608                 ))
609         (define-key quick-map [nxhtml-sometoc-map]
610           (list 'menu-item "Table of Contents" sometoc-map
611                 :visible '(or (derived-mode-p 'html-mode)
612                               (nxhtml-nxhtml-in-buffer)))))
613       (define-key quick-map [nxhtml-quick-sep-1]
614         (list 'menu-item "--"))
615       (define-key quick-map [nxhtml-spec-chars]
616         (list 'menu-item "Insert special character"
617               'nxml-insert-named-char))
618       (define-key quick-map [nxhtml-css-rollover]
619         (list 'menu-item "Insert CSS Rollover Images"
620               'nxhtml-rollover-insert-2v)))
621
622
623       (define-key tools-map [nxhtml-html-write-mode]
624         (list 'menu-item "HTML Write Mode"
625               'html-write-mode
626               :enable '(nxhtml-html-in-buffer)
627               :button '(:toggle . (and (boundp 'html-write-mode)
628                                          html-write-mode))))
629       (define-key tools-map [nxhtml-tidy-map]
630         (list 'menu-item "Tidy XHTML" 'tidy-menu-symbol
631               ;; Seems like :visible is called before :filter so we
632               ;; can compute things in :visible.
633               :filter 'nxhtml-insert-menu-dynamically
634               :visible '(or (and (or (derived-mode-p 'html-mode)
635                                      (nxhtml-nxhtml-in-buffer))
636                                  (fboundp 'tidy-build-menu) (tidy-build-menu))
637                             t)
638               :enable '(and (or (derived-mode-p 'html-mode)
639                                 (nxhtml-nxhtml-in-buffer))
640                             (fboundp 'tidy-build-menu) (tidy-build-menu))
641               ))
642       (define-key tools-map [zencoding]
643         (list 'menu-item "Zen coding for HTML/CSS" 'zencoding-mode
644               :button '(:toggle . (and (boundp 'zencoding-mode)
645                                        zencoding-mode))
646               :enable '(nxhtml-html-in-buffer)))
647
648       (let ((where-map (make-sparse-keymap)))
649         (define-key tools-map [nxml-where]
650           (list 'menu-item "XML Path" where-map
651                 :enable '(and (fboundp 'nxml-where-mode)
652                               (or (derived-mode-p 'nxml-mode)
653                                   (nxhtml-nxhtml-in-buffer)))))
654         (define-key where-map [nxhtml-nxml-where-cust]
655           (list 'menu-item "Customize display of XML Path"
656                 (lambda ()
657                   "Customize XML path, ie group `nxml-where'."
658                   (interactive)
659                   (customize-group-other-window 'nxml-where))))
660         (define-key where-map [where-separator-2] (list 'menu-item "--"))
661         (define-key where-map [nxml-where-inner]
662           (list 'menu-item "Show inly inner tag" 'nxml-where-only-inner-toggle
663                 :enable '(boundp 'nxml-where-only-inner)
664                 :button '(:toggle . (and (boundp 'nxml-where-only-inner)
665                                          nxml-where-only-inner))))
666         (define-key where-map [nxml-where-id]
667           (list 'menu-item "Show tag ids in path" 'nxml-where-tag+id-toggle
668                 :enable '(boundp 'nxml-where-tag+id)
669                 :button '(:toggle . (and (boundp 'nxml-where-tag+id)
670                                          nxml-where-tag+id))))
671         (define-key where-map [nxml-where-header]
672           (list 'menu-item "Show XML path in header" 'nxml-where-header-toggle
673                 :enable '(boundp 'nxml-where-header)
674                 :button '(:toggle . (and (boundp 'nxml-where-header)
675                                          'nxml-where-header))))
676         (define-key where-map [nxml-where-marks]
677           (list 'menu-item "Show XML path marks" 'nxml-where-marks-toggle
678                 :enable '(boundp 'nxml-where-marks)
679                 :button '(:toggle . (and (boundp 'nxml-where-marks)
680                                          nxml-where-marks))))
681         (define-key where-map [where-separator] (list 'menu-item "--"))
682         (define-key where-map [nxml-where-global-toggle]
683           (list 'menu-item "Show XML path" 'nxml-where-global-mode
684                 :button '(:toggle . (and (boundp 'nxml-where-global-mode)
685                                          nxml-where-global-mode))))
686         (define-key where-map [nxml-where-toggle]
687           (list 'menu-item "Show XML path in buffer" 'nxml-where-mode
688                 :button '(:toggle . (and (boundp 'nxml-where-mode)
689                                          nxml-where-mode))))
690         )
691
692
693       (let ((cmpl-map (make-sparse-keymap)))
694         (define-key tools-map [nxhtml-cmpl-map]
695           (list 'menu-item "XHTML Completion and Validation" cmpl-map
696                 ;; :enable '(or (derived-mode-p 'nxml-mode) (nxhtml-nxhtml-in-buffer))
697                 :visible `(not (derived-mode-p 'dired-mode))
698                 :enable ' (or (derived-mode-p 'nxml-mode)
699                                   (nxhtml-nxhtml-in-buffer))
700                 ))
701         (let ((val-map (make-sparse-keymap)))
702           (define-key cmpl-map [nxhtml-cmpl-val-map]
703             (list 'menu-item "Validation Helpers (for php etc)" val-map
704                   :enable '(nxhtml-nxhtml-in-buffer)
705                   :visible '(nxhtml-nxml-html-in-buffer)))
706 ;;;         (define-key val-map [nxhtml-strval-mode]
707 ;;;           (list 'menu-item "Allow attr=\"<?php...?>\" etc"
708 ;;;                 'nxhtml-strval-mode
709 ;;;                 :button '(:toggle . nxhtml-strval-mode)))
710           (define-key val-map [mumamo-alt-php-tags]
711             (list 'menu-item "Use <?php -> (?php"
712                   'mumamo-alt-php-tags-mode
713                   :button '(:toggle . (and (boundp 'mumamo-alt-php-tags-mode)
714                                            mumamo-alt-php-tags-mode))))
715           (define-key val-map [mumamo-alt-tags-separator] (list 'menu-item "--"))
716           (define-key val-map [nxhtml-toggle-warnings]
717             (list 'menu-item "Hide Validation Errors"
718                   'nxhtml-toggle-visible-warnings
719                   :button '(:toggle . (not (nxhtml-warnings-are-visible)))
720                   ))
721           (define-key val-map [nxhtml-error-separator] (list 'menu-item "--"))
722           (define-key val-map [nxhtml-remove-saved-validation-header]
723             (list 'menu-item "Remove File's Fictive XHTML Validation Header"
724                   'nxhtml-remove-saved-validation-header
725                   ;; Fix-me: maybe a better enable here?
726                   :enable 'nxhtml-validation-header-mode))
727           (define-key val-map [nxhtml-save-validation-header]
728             (list 'menu-item "Save File's Fictive XHTML Validation Header"
729                   'nxhtml-save-validation-header
730                   :enable 'nxhtml-validation-header-mode))
731           (define-key val-map [nxhtml-set-validation-header]
732             (list 'menu-item "Choose Fictive XHTML Validation Header for Buffer"
733                   'nxhtml-set-validation-header))
734           (define-key val-map [nxhtml-update-validation-header]
735             (list 'menu-item "Update Fictive XHTML Validation Header for Buffer"
736                   'nxhtml-update-validation-header))
737           (define-key val-map [nxhtml-use-saved-val-separator] (list 'menu-item "--"))
738 ;;;         (let ((afic-map (make-sparse-keymap)))
739 ;;;           (define-key val-map [nxhtml-afic-map]
740 ;;;             (list 'menu-item "Automatic Fictive XHTML Validation Header" afic-map))
741 ;;;           (define-key afic-map [nxhtml-validation-header-mumamo-set]
742 ;;;             (list 'menu-item "Customize Automatic XHTML Validation Turn On"
743 ;;;                   (lambda () (interactive) (customize-option 'nxhtml-validation-header-mumamo-modes))))
744 ;;;           (define-key afic-map [nxhtml-validation-header-mumamo]
745 ;;;             (list 'menu-item "Turn on Fictive XHTML Validation Header with MuMaMo"
746 ;;;                   'nxhtml-validation-header-if-mumamo-toggle
747 ;;;                   :button '(:toggle . nxhtml-validation-header-if-mumamo))))
748           (define-key val-map [nxhtml-show-validation-header]
749             (list 'menu-item "Display Fictive XHTML Validation Header"
750                   'rngalt-display-validation-header-toggle
751                   :help-echo "Displays the Fictive XHTML validation header (if any) at top of buffer"
752                   :button '(:toggle . (and (boundp 'rngalt-display-validation-header)
753                                            rngalt-display-validation-header))))
754           (define-key val-map [nxhtml-recheck-validation-header]
755             (list 'menu-item "Recheck Fictive XHTML Validation Header in Buffer"
756                   'nxhtml-recheck-validation-header
757                   :enable 'nxhtml-validation-header-mode))
758           (define-key val-map [nxhtml-validation-header-mode]
759             (list 'menu-item "Use Fictive XHTML Validation Header in Buffer"
760                   'nxhtml-validation-header-mode
761                   :button '(:toggle . (and (boundp 'nxhtml-validation-header-mode)
762                                            nxhtml-validation-header-mode))))
763           )
764         (define-key cmpl-map [nxhtml-validation-separator]
765           (list 'menu-item "--" nil
766                 :visible '(nxhtml-nxml-html-in-buffer)))
767         (let ((style-map (make-sparse-keymap)))
768           (define-key cmpl-map [nxhtml-cmpl-style-map]
769             (list 'menu-item "Completion Style" style-map
770                   :visible '(nxhtml-nxml-html-in-buffer)
771                   :enable '(nxhtml-nxhtml-in-buffer)))
772           (define-key style-map [popcmp-customize]
773             (list 'menu-item "Customize Completion Style"
774                   (lambda () (interactive) (customize-group-other-window 'popcmp))))
775           (define-key style-map [popcmp-style-div2]
776             (list 'menu-item "--"))
777           ;;(defun nxhtml-nxml-html-in-buffer ()
778           (define-key style-map [popcmp-with-help]
779             (list 'menu-item "Show Short Help Beside Alternatives"
780                   'popcmp-short-help-beside-alts-toggle
781                   :button '(:toggle . (and (boundp 'popcmp-short-help-beside-alts)
782                                            popcmp-short-help-beside-alts))))
783           (define-key style-map [nxhtml-tag-do-also]
784             (list 'menu-item "Complete Tag Extras"
785                   'nxhtml-tag-do-also-toggle
786                   :button '(:toggle . (and (boundp 'nxhtml-tag-do-also)
787                                            nxhtml-tag-do-also))))
788           (define-key style-map [popcmp-group-alternatives]
789             (list 'menu-item "Group Alternatives"
790                   'popcmp-group-alternatives-toggle
791                   :button '(:toggle . (and (boundp 'popcmp-group-alternatives)
792                                            popcmp-group-alternatives))))
793           (define-key style-map [popcmp-style-div1]
794             (list 'menu-item "--"))
795           (define-key style-map [popcmp-anything-completion]
796             (list 'menu-item "Anything Style Completion"
797                   (lambda () (interactive) (customize-set-variable 'popcmp-completion-style 'anything))
798                   :enable `(fboundp 'anything)
799                   :button `(:radio . (eq popcmp-completion-style 'anything))))
800           (define-key style-map [popcmp-company-completion]
801             (list 'menu-item "Company Mode Style Completion"
802                   (lambda () (interactive) (customize-set-variable 'popcmp-completion-style 'company-mode))
803                   :enable `(fboundp 'company-mode)
804                   :button `(:radio . (eq popcmp-completion-style 'company-mode))))
805           (define-key style-map [popcmp-emacs-completion]
806             (list 'menu-item "Emacs Default Style Completion"
807                   (lambda () (interactive) (customize-set-variable 'popcmp-completion-style 'emacs-default))
808                   :button `(:radio . (eq popcmp-completion-style 'emacs-default))))
809           (define-key style-map [popcmp-popup-completion]
810             (list 'menu-item "Popup Style Completion"
811                   (lambda () (interactive) (customize-set-variable 'popcmp-completion-style 'popcmp-popup))
812                   :button `(:radio . (eq popcmp-completion-style 'popcmp-popup))))
813           )
814         (define-key cmpl-map [nxhtml-cmpl-separator]
815           (list 'menu-item "--" nil
816                 :visible '(nxhtml-nxml-html-in-buffer)))
817         (define-key cmpl-map [nxhtml-untag-element]
818           (list 'menu-item "Untag Element" 'nxml-untag-element
819                 :enable '(nxhtml-nxhtml-in-buffer)
820                 :visible '(nxhtml-nxml-html-in-buffer)))
821         (define-key cmpl-map [rngalt-finish-element]
822           (list 'menu-item "Insert End Tag" 'rngalt-finish-element
823                 :enable '(nxhtml-nxhtml-in-buffer)
824                 :visible '(nxhtml-nxml-html-in-buffer)))
825         (define-key cmpl-map [nxhtml-complete]
826           (list 'menu-item "Complete tag, attribute etc" 'nxml-complete
827                 :enable '(nxhtml-nxml-in-buffer)
828                 :visible '(nxhtml-nxml-html-in-buffer)))
829         )
830
831
832       )
833
834     (let ((options-map (make-sparse-keymap)))
835       (define-key map [nxhtml-options-map]
836         (list 'menu-item "Options" options-map))
837
838       (define-key options-map [nxhtml-save-opt]
839         (list 'menu-item "Save All Changed Options" 'customize-save-customized))
840
841       (define-key options-map [nxhtml-save-sep] (list 'menu-item "--"))
842
843       (define-key options-map [nxhtml-load-flymake]
844         (list 'menu-item "Use nXhtml CSS/JS Flymake"
845               'nxhtml-flymake-setup
846               :button '(:toggle . (and (boundp 'nxhtml-flymake-setup)
847                                        nxhtml-flymake-setup))))
848
849       (define-key options-map [nxhtml-save-sep] (list 'menu-item "--"))
850
851       (define-key options-map [nxhtml-winsav-mode]
852         (list 'menu-item "Save/restore Frames and Windows"
853               'winsav-save-mode
854               :button '(:toggle . (and (boundp 'winsav-save-mode)
855                                        winsav-save-mode))))
856       (define-key options-map [nxhtml-win-sep] (list 'menu-item "--"))
857       (define-key options-map [nxhtml-images-global]
858         (list 'menu-item "Display Images Inline" 'inlimg-global-mode
859               :button '(:toggle . (and (boundp 'inlimg-global-mode)
860                                        inlimg-global-mode))))
861       (define-key options-map [nxhtml-opt-sep] (list 'menu-item "--"))
862       (define-key options-map [nxhtml-hl-needed-mode]
863         (list 'menu-item "Tell Me Where I Am" 'hl-needed-mode
864               :button '(:toggle . (and (boundp 'hl-needed-mode)
865                                        hl-needed-mode))))
866       (define-key options-map [nxhtml-mark-nonascii]
867         (list 'menu-item "Mark Special Chars (default non-IDN)" 'markchars-global-mode
868               :button '(:toggle . (and (boundp 'markchars-global-mode)
869                                        markchars-global-mode))))
870       (define-key options-map [nxhtml-sml-modeline-mode]
871         (list 'menu-item "Mode Line Scroll Indicator" 'sml-modeline-mode
872               :button '(:toggle . (and (boundp 'sml-modeline-mode)
873                                        sml-modeline-mode))))
874       (define-key options-map [rebind-keys]
875         (list 'menu-item "Rebind My Choosen Keys" 'rebind-keys-mode
876               :button '(:toggle . (and (boundp 'rebind-keys-mode)
877                                        rebind-keys-mode))))
878       (define-key options-map [nxhtml-appmenu]
879         (list 'menu-item "Context Sensitive AppMenu"
880               'appmenu-mode
881               :button '(:toggle . (and (boundp 'appmenu-mode)
882                                        appmenu-mode))))
883       (define-key options-map [nxhtml-menu-to-m-x]
884         (list 'menu-item "Add Menu Commands to M-x history"
885               'ourcomments-M-x-menu-mode
886               :button '(:toggle . (and (boundp 'ourcomments-M-x-menu-mode)
887                                        ourcomments-M-x-menu-mode))))
888       (define-key options-map [nxhtml-patch-converting]
889         (list 'menu-item "Paste with Convert"
890               'ourcomments-paste-with-convert-mode
891               :button '(:toggle . (and (boundp 'ourcomments-paste-with-convert-mode)
892                                        ourcomments-paste-with-convert-mode))))
893
894       (define-key options-map [nxhtml-tab-separator]
895         (list 'menu-item "--" nil))
896       (define-key options-map [nxhtml-ctrl-tab]
897         (list 'menu-item "Ctrl-TAB Buffer Switching"
898               'ourcomments-ido-ctrl-tab
899               :button '(:toggle . (and (boundp 'ourcomments-ido-ctrl-tab)
900                                        ourcomments-ido-ctrl-tab))))
901       (define-key options-map [nxhtml-tab-complete]
902         (list 'menu-item "Indent and then Complete (TabKey2 mode)" 'tabkey2-mode
903               :button '(:toggle . (and (boundp 'tabkey2-mode)
904                                        tabkey2-mode))))
905
906
907
908       (define-key options-map [nxhtml-majpri-separator]
909         (list 'menu-item "--" nil))
910       (define-key options-map [nxhtml-as-external]
911         (list 'menu-item "External Editor Setup"
912               'as-external-mode
913               :button '(:toggle . (and (boundp 'as-external-mode)
914                                        as-external-mode))))
915       (define-key options-map [nxhtml-sex-mode]
916         (list 'menu-item "Open Files in External Apps"
917               'sex-mode
918               :button '(:toggle . (and (boundp 'sex-mode)
919                                        sex-mode))))
920       (let ((majpri-map (make-sparse-keymap)))
921         (define-key options-map [nxhtml-majpri-map]
922           (list 'menu-item "Major Modes Priorities" majpri-map))
923         (define-key majpri-map [nxhtml-majpri-act]
924           (list 'menu-item "Apply Major Modes Priorities"
925                 'majmodpri-apply-priorities))
926         (define-key majpri-map [nxhtml-majpri-cust]
927           (list 'menu-item "Customize Major Mode Priorities"
928                 (lambda ()
929                   "Customize group Major Mode priorities."
930                   (interactive)
931                   (customize-group-other-window 'majmodpri))))
932         )
933       )
934
935     (let ((edit-map (make-sparse-keymap)))
936       (define-key map [nxhtml-edit-map]
937         (list 'menu-item "Edit" edit-map))
938
939       (let ((folding-map (make-sparse-keymap)))
940         (define-key edit-map [nxhtml-folding-map]
941           (list 'menu-item "Folding" folding-map))
942         (define-key folding-map [nxhtml-fold-unhide-all]
943           (list 'menu-item "Unhide Everything"
944                 'fold-dwim-unhide-hs-and-outline))
945         (define-key folding-map [nxhtml-fold-dwim]
946           (list 'menu-item "Maybe DWIM Folding"
947                 'fold-dwim-toggle))
948         (define-key folding-map [nxhtml-separator2] (list 'menu-item "--" nil))
949         (define-key folding-map [nxhtml-hs]
950           (list 'menu-item "Turn On Hide/Show and Hide"
951                 'fold-dwim-turn-on-hs-and-hide))
952         (define-key folding-map [nxhtml-outline]
953           (list 'menu-item "Turn On Outline and Hide All"
954                 'fold-dwim-turn-on-outline-and-hide-all))
955         (define-key folding-map [nxhtml-separator1] (list 'menu-item "--" nil))
956         (define-key folding-map [nxhtml-foldit-mode]
957           (list 'menu-item "Folding Markers in Buffer"
958                 'foldit-mode
959                 :button '(:toggle . (and (boundp 'foldit-mode)
960                                          foldit-mode))))
961         (define-key folding-map [nxhtml-foldit-global-mode]
962           (list 'menu-item "Folding Markers Everywhere"
963                 'foldit-global-mode
964                 :button '(:toggle . (and (boundp 'foldit-global-mode)
965                                          foldit-global-mode))))
966         )
967
968       (define-key edit-map [nxhtml-folding-sep] (list 'menu-item "--"))
969
970       (define-key edit-map [nxhtml-wrap-to-fill-column-mode]
971         (list 'menu-item "Wrap To Fill Column Mode"
972               'wrap-to-fill-column-mode
973               :button '(:toggle . (and (boundp 'wrap-to-fill-column-mode)
974                                          wrap-to-fill-column-mode))))
975       (define-key edit-map [nxhtml-fill-dwim]
976         (list 'menu-item "Fill DWIM" 'fill-dwim))
977
978       (define-key edit-map [nxhtml-fill-sep] (list 'menu-item "--"))
979
980
981       (let ((link-map (make-sparse-keymap)))
982         (define-key edit-map [nxhtml-link-map]
983           (list 'menu-item "Links" link-map
984                 :enable '(not (derived-mode-p 'dired-mode))
985                 ))
986
987         (define-key link-map [mlinks-goto-link-other-frame]
988           (list 'menu-item "Follow MLink Link in New Frame" 'mlinks-goto-other-frame
989                 :enable '(and (boundp 'mlinks-mode)
990                               mlinks-mode)
991                 :help "Follow MLinks Link in New Frame"))
992         (define-key link-map [mlinks-goto-link-other-window]
993           (list 'menu-item "Follow MLink Link in Other Window" 'mlinks-goto-other-window
994                 :enable '(and (boundp 'mlinks-mode)
995                               mlinks-mode)
996                 :help "Follow MLinks Link in Other Window"))
997         (define-key link-map [mlinks-goto-link]
998           (list 'menu-item "Follow MLink Link" 'mlinks-goto
999                 :enable '(and (boundp 'mlinks-mode)
1000                               mlinks-mode)
1001                 :help "Follow MLinks Link"))
1002         (define-key link-map [nxhtml-separator-follow-mlink] (list 'menu-item "--"))
1003         (define-key link-map [mlinks-next-link]
1004           (list 'menu-item "Next MLink Link" 'mlinks-forward-link
1005                 :enable '(and (boundp 'mlinks-mode)
1006                               mlinks-mode)
1007                 :help "Go to next MLinks link"))
1008         (define-key link-map [mlinks-prev-link]
1009           (list 'menu-item "Previous MLink Link" 'mlinks-backward-link
1010                 :enable '(and (boundp 'mlinks-mode)
1011                               mlinks-mode)
1012                 :help "Go to previous MLinks link"))
1013
1014         )
1015       (define-key edit-map [nxhtml-edit-sep1] (list 'menu-item "--"))
1016       (define-key edit-map [nxhtml-grep-replace]
1017         (list 'menu-item "Replace in Grepped Files" 'grep-query-replace))
1018       (define-key edit-map [nxhtml-rdir-replace]
1019         (list 'menu-item "Replace in Files in Tree" 'rdir-query-replace))
1020       (define-key edit-map [nxhtml-ldir-replace]
1021         (list 'menu-item "Replace in Files in Directory" 'ldir-query-replace))
1022
1023       (define-key edit-map [nxhtml-edit-sep2] (list 'menu-item "--"))
1024       (define-key edit-map [nxhtml-multi-occur]
1025         (list 'menu-item "Occur in File Buffers" 'multi-occur-in-matching-buffers))
1026       (define-key edit-map [nxhtml-occur]
1027         (list 'menu-item "Occur" 'occur))
1028       (define-key edit-map [nxhtml-edit-sep3] (list 'menu-item "--"))
1029       (define-key edit-map [nxhtml-re-builder]
1030         (list 'menu-item "Re-Builder" 're-builder))
1031       (define-key edit-map [nxhtml-edit-sep4] (list 'menu-item "--"))
1032       (let ((copy+paste-map (make-sparse-keymap "copy+paste")))
1033         (define-key edit-map [nxhtml-copy+paste-map]
1034           (list 'menu-item "Copy+Paste" copy+paste-map))
1035         (define-key copy+paste-map [nxhtml-copy+paste-do]
1036           (list 'menu-item "Do Copy+Paste" 'ourcomments-copy+paste
1037                 :enable '(and (boundp 'ourcomments-copy+paste-mode)
1038                               ourcomments-copy+paste-mode)))
1039         (define-key copy+paste-map [nxhtml-copy+paste-set]
1040           (list 'menu-item "Start Copy+Paste" 'ourcomments-copy+paste-set-point
1041                 :button '(:toggle . (and (boundp 'ourcomments-copy+paste-mode)
1042                                          ourcomments-copy+paste-mode))))
1043         )
1044       (define-key edit-map [nxhtml-anchored-transpose]
1045         (list 'menu-item "Transpose Regions" 'anchored-transpose
1046               :button '(:toggle . (and mouse-secondary-overlay
1047                                        (overlay-buffer mouse-secondary-overlay)))))
1048       )
1049
1050     (define-key map [nxhtml-help-tools-separator]
1051       ;; Notice that removing nil below gives an error that is quite
1052       ;; hard to catch:
1053       ;;
1054       ;; Wrong type argument: arrayp, not
1055       (list 'menu-item "--" nil
1056             :visible `(not (derived-mode-p 'dired-mode))
1057             ))
1058
1059
1060     (let ((upl-map (make-sparse-keymap "html-upl")))
1061       (define-key map [nxhtml-upl-map]
1062         (list 'menu-item "File Transfer" upl-map
1063               ;;:enable '(featurep 'html-upl)))
1064               :enable '(fboundp 'html-upl-upload-file)))
1065       (define-key upl-map [nxhtml-upl-remote-dired]
1066         (list 'menu-item "Remote Dired" 'html-upl-remote-dired))
1067       (define-key upl-map [nxhtml-upl-dired-sep] (list 'menu-item "--"))
1068       (define-key upl-map [nxhtml-upl-edit-remote-wtoc]
1069         (list 'menu-item "Edit Remote File With TOC" 'html-upl-edit-remote-file-with-toc
1070               :visible '(or (not (featurep 'html-site))
1071                             (nxhtml-this-file-can-have-toc))))
1072       (define-key upl-map [nxhtml-upl-edit-remote]
1073         (list 'menu-item "Edit Remote File" 'html-upl-edit-remote-file))
1074       (define-key upl-map [nxhtml-upl-ediff-file]
1075         (list 'menu-item "Ediff Remote/Local Files" 'html-upl-ediff-file))
1076       (define-key upl-map [nxhtml-upl-sep] (list 'menu-item "--"))
1077       (define-key upl-map [nxhtml-upl-upload-site-with-toc]
1078         (list 'menu-item "Upload Site with TOC" 'html-upl-upload-site-with-toc
1079               :visible '(or (not (featurep 'html-site))
1080                             (and (html-site-current-merge-dir)
1081                                  (html-site-current-ensure-file-in-site file)))))
1082       (define-key upl-map [nxhtml-upl-upload-site]
1083         (list 'menu-item "Upload Site" 'html-upl-upload-site))
1084       (define-key upl-map [nxhtml-upl-upload-file]
1085         (list 'menu-item "Upload Single File" 'html-upl-upload-file))
1086       )
1087
1088
1089     (let ((browse-map (make-sparse-keymap)))
1090       (define-key map [nxhtml-browse-map]
1091         (list 'menu-item "Browse" browse-map
1092               '(or buffer-file-name
1093                    (eq major-mode 'nxhtml-mode))
1094               :enable '(nxhtml-buffer-possibly-local-viewable)))
1095       (define-key browse-map [nxhtml-browse-region]
1096         (list 'menu-item "Browse the Region Only" 'nxhtml-browse-region
1097               :enable 'mark-active))
1098       (define-key browse-map [nxhtml-upl-sep3] (list 'menu-item "--"))
1099       (define-key browse-map [nxhtml-upl-browse-remote-wtoc]
1100         (list 'menu-item "Browse Uploaded File With TOC" 'html-upl-browse-remote-with-toc
1101               :visible '(and (nxhtml-buffer-possibly-local-viewable)
1102                              (featurep 'html-wtoc)
1103                              (html-site-current-merge-dir)
1104                              (html-site-current-ensure-file-in-site file)
1105                              (nxhtml-buffer-possibly-remote-viewable)
1106                              )))
1107       (define-key browse-map [nxhtml-upl-browse-remote-frame-file]
1108         (list 'menu-item "Browse Uploaded Frames File" 'html-upl-browse-remote-frames
1109               :enable '(nxhtml-buffer-possibly-remote-viewable)))
1110       (define-key browse-map [nxhtml-upl-browse-remote]
1111         (list 'menu-item "Browse Uploaded File" 'html-upl-browse-remote
1112               :enable '(nxhtml-buffer-possibly-remote-viewable)))
1113       (define-key browse-map [nxhtml-upl-sep2]
1114         (list 'menu-item "--"))
1115       (define-key browse-map [nxhtml-browse-merged-file]
1116         (list 'menu-item "Browse File With TOC" 'html-wtoc-browse-page-with-toc
1117               :visible '(and (nxhtml-buffer-possibly-local-viewable)
1118                              (featurep 'html-wtoc)
1119                              (html-site-current-merge-dir)
1120                              (html-site-current-ensure-file-in-site file)
1121                              )))
1122       (define-key browse-map [nxhtml-browse-frame-file]
1123         (list 'menu-item "Browse Frames File" 'html-toc-browse-frames-file
1124               :enable '(and (featurep 'html-toc)
1125                             (nxhtml-buffer-possibly-local-viewable))))
1126       (define-key browse-map [nxhtml-browse-file]
1127         (list 'menu-item "Browse File" 'nxhtml-browse-file
1128               :enable '(nxhtml-buffer-possibly-local-viewable)))
1129       )
1130
1131
1132
1133     (let ((site-map (make-sparse-keymap)))
1134       (define-key map [nxhtml-site-map]
1135         (list 'menu-item "Site" site-map))
1136       (define-key site-map [html-site-global-mode]
1137         (list 'menu-item "HTML Site Global Mode"
1138               'html-site-global-mode
1139               :button '(:toggle . (and (boundp 'html-site-global-mode)
1140                                        html-site-global-mode))))
1141       (define-key site-map [nxhtml-site-separator] (list 'menu-item "--"))
1142       (define-key site-map [nxhtml-customize-site-list]
1143         (list 'menu-item "Edit Sites" (lambda ()
1144                                         "Customize option `html-size-list'."
1145                                         (interactive)
1146                                         (customize-option-other-window 'html-site-list))))
1147       (define-key site-map [nxhtml-set-site]
1148         (list 'menu-item "Set Current Site" 'html-site-set-site))
1149       (define-key site-map [nxhtml-site-separator-1] (list 'menu-item "--"))
1150       (define-key site-map [nxhtml-dired-site-top]
1151         (list 'menu-item "Dired Site" 'html-site-dired-current))
1152       (define-key site-map [nxhtml-find-site-file]
1153         (list 'menu-item "Find File in Site" 'html-site-find-file))
1154       (define-key site-map [nxhtml-site-search-separator]
1155         (list 'menu-item "--" nil))
1156       (define-key site-map [nxhtml-replace-in-site]
1157         (list 'menu-item "Replace in Site Files" 'html-site-query-replace))
1158       (define-key site-map [nxhtml-rgrep-in-site]
1159         (list 'menu-item "Search Site Files" 'html-site-rgrep))
1160       )
1161
1162     (define-key map [nxhtml-insert-separator]
1163       (list 'menu-item "--" nil
1164             :visible `(not (derived-mode-p 'dired-mode))
1165             ))
1166     (let ((chunk-map (make-sparse-keymap)))
1167       (define-key map [nxhtml-chunk-map]
1168         (list 'menu-item "Multi Major Modes" chunk-map
1169               :visible `(not (derived-mode-p 'dired-mode))
1170               ))
1171       (define-key chunk-map [nxhtml-customize-mumamo]
1172         (list 'menu-item "Customize MuMaMo"
1173               (lambda () (interactive) (customize-group-other-window 'mumamo))))
1174       (define-key chunk-map [nxhtml-list-mumamo]
1175         (list 'menu-item "List defined Multi Major Modes"
1176               'mumamo-list-defined-multi-major-modes))
1177       (define-key chunk-map [nxhtml-chunks-separator2]
1178         (list 'menu-item "--" nil))
1179       (define-key chunk-map [nxhtml-chunk-no-colors]
1180         (list 'menu-item "Remove Chunk Colors Temporarily"
1181               'mumamo-no-chunk-coloring
1182               :button '(:toggle . (and (boundp 'mumamo-no-chunk-coloring)
1183                                        mumamo-no-chunk-coloring))))
1184       (define-key chunk-map [nxhtml-chunk-margin-info]
1185         (list 'menu-item "Display Chunk Info in Margin"
1186               'mumamo-margin-info-global-mode
1187               :button '(:toggle . (and (boundp 'mumamo-margin-info-global-mode)
1188                                        mumamo-margin-info-global-mode))))
1189       (define-key chunk-map [nxhtml-chunks-separator1]
1190         (list 'menu-item "--" nil))
1191       (let ((region-map (make-sparse-keymap)))
1192         (define-key chunk-map [nxhtml-region-map]
1193           (list 'menu-item "Temprary Region Chunks" region-map))
1194         (define-key region-map [mumamo-clear-all-regions]
1195           (list 'menu-item "Clear Region Chunks"
1196                 'mumamo-clear-all-regions
1197                 :enable '(and (boundp 'mumamo-multi-major-mode)
1198                               mumamo-multi-major-mode
1199                               (fboundp 'mumamo-clear-all-regions))))
1200         (define-key region-map [mumamo-clear-region]
1201           (list 'menu-item "Clear Region Chunk at Point"
1202                 'mumamo-clear-region
1203                 :enable '(fboundp 'mumamo-clear-region)))
1204         (define-key region-map [nxhtml-region-separator2]
1205           (list 'menu-item "--" nil))
1206         (define-key region-map [mumamo-region-major]
1207           (list 'menu-item "Set Region Chunk Major Mode"
1208                 'mumamo-region-set-major
1209                 :enable '(fboundp 'mumamo-region-set-major)))
1210         (define-key region-map [mumamo-add-region-from-string]
1211           (list 'menu-item "Add Region Chunk from String"
1212                 'mumamo-add-region-from-string))
1213         (define-key region-map [mumamo-add-region]
1214           (list 'menu-item "Add Region Chunk from Selection"
1215                 'mumamo-add-region)))
1216       (define-key chunk-map [nxhtml-region-separator]
1217         (list 'menu-item "--" nil))
1218       (define-key chunk-map [mumamo-mark-chunk]
1219         (list 'menu-item "Mark Chunk"
1220               'mumamo-mark-chunk
1221               :enable '(and (boundp 'mumamo-multi-major-mode)
1222                             mumamo-multi-major-mode)))
1223       (define-key chunk-map [nxhtml-separator-mark-chunk] (list 'menu-item "--"))
1224       (define-key chunk-map [mumamo-backward-chunk]
1225         (list 'menu-item "Backward Chunk"
1226               'mumamo-backward-chunk
1227               :enable '(and (boundp 'mumamo-multi-major-mode)
1228                             mumamo-multi-major-mode)))
1229       (define-key chunk-map [mumamo-forward-chunk]
1230         (list 'menu-item "Forward Chunk"
1231               'mumamo-forward-chunk
1232               :enable '(and (boundp 'mumamo-multi-major-mode)
1233                             mumamo-multi-major-mode))))
1234     (let ((tag-map (make-sparse-keymap)))
1235       (define-key map [nxhtml-tag-map]
1236         (list 'menu-item "Move by Tag" tag-map
1237               :visible '(or (derived-mode-p 'nxml-mode)
1238                             (derived-mode-p 'sgml-mode))
1239               :enable '(or (derived-mode-p 'nxml-mode)
1240                            (nxhtml-nxhtml-in-buffer))))
1241       (define-key tag-map [nxml-forward-par]
1242         (list 'menu-item "Forward Paragraph"
1243               'nxml-forward-paragraph))
1244       (define-key tag-map [nxml-backward-par]
1245         (list 'menu-item "Backward Paragraph"
1246               'nxml-backward-paragraph))
1247       (define-key tag-map [nxml-insert-separator-move2] (list 'menu-item "--"))
1248       (define-key tag-map [nxml-down]
1249         (list 'menu-item "Forward Into Tag"
1250               'nxml-down-element))
1251       (define-key tag-map [nxml-backward-up]
1252         (list 'menu-item "Backward Out of Tag"
1253               'nxml-backward-up-element))
1254       (define-key tag-map [nxml-insert-separator-move] (list 'menu-item "--"))
1255       (define-key tag-map [nxml-forward]
1256         (list 'menu-item "Forward Balanced Tag"
1257               'nxml-forward-element))
1258       (define-key tag-map [nxml-backward]
1259         (list 'menu-item "Backward Balanced Tag"
1260               'nxml-backward-element))
1261       )
1262
1263
1264     map))
1265
1266 (defvar nxhtml-menu-mode-map
1267   (let ((map (make-sparse-keymap)))
1268     (define-key map [(control ?c) ?? ?x] 'nxhtml-short-tag-help)
1269     (define-key map [(control ?c) ?? ?c] 'xhtml-help-show-css-ref)
1270     (define-key map [(control ?c) ?_] 'nxhtml-toggle-visible-warnings)
1271     (define-key map [menu-bar nxhtml-menu-mode]
1272       (list 'menu-item "nXhtml" nxhtml-menu-mode-menu-map))
1273     map))
1274
1275 ;;;###autoload
1276 (define-minor-mode nxhtml-menu-mode
1277   "Minor mode to turn on some key and menu bindings.
1278 See `nxhtml-mode' for more information.
1279
1280 This minor mode adds the entry 'nXhtml' to the menu bar.  This
1281 submenu gives easy access to most of the important features of
1282 nXhtml.
1283
1284 To see an \(incomplete) overview in html format do
1285 \\[nxhtml-overview].
1286
1287 * Note: Please observe that when loading nXhtml some file
1288   associations are done, see `nxhtml-setup-file-assoc'.
1289
1290 Here are some important features:
1291
1292 - multiple major modes, see `define-mumamo-multi-major-mode'
1293 - easy uploading and viewing of files, see for example
1294   `html-upl-upload-file'
1295
1296 - validation in XHTML part for php etc, see
1297   `nxhtml-validation-header-mode' (you probably also want to know
1298   about `nxhtml-toggle-visible-warnings' for this!)
1299
1300 - converting of html to xhtml, see `tidy-buffer'
1301
1302 Some smaller, useful, but easy-to-miss features:
1303
1304 * Following links. The href and src attribute names are
1305   underlined and a special keymap is bound to
1306   them:\\<mlinks-mode-map>
1307
1308     \\[mlinks-backward-link], \\[mlinks-forward-link] Move
1309         between underlined href/src attributes
1310
1311     \\[mlinks-goto], Mouse-1 Follow link inside Emacs
1312         (if possible)
1313
1314   It is even a little bit quicker when the links are in an active
1315   state (marked with the face `isearch'):\\<mlinks-active-hilight-keymap>
1316
1317     \\[mlinks-backward-link], \\[mlinks-forward-link] Move
1318         between underlined href/src attributes
1319     \\[mlinks-goto], Mouse-1  Follow link inside Emacs (if possible)
1320
1321   If the link is not into a file that you can edit (a mailto link
1322   for example) you will be prompted for an alternative action.
1323
1324 * Creating links. To make it easier to create links to id/name
1325   attribute in different files there are two special
1326   functions:\\<nxhtml-mode-map>
1327
1328     \\[nxhtml-save-link-to-here] copy link to id/name (you must
1329         be in the tag to get the link)
1330     \\[nxhtml-paste-link-as-a-tag] paste this as an a-tag.
1331
1332 This minor mode also adds some bindings:
1333
1334 \\{nxhtml-menu-mode-map}
1335
1336 ---------
1337 * Note: Some of the features supported are optional and available
1338   only if other Emacs modules are found.  Use
1339   \\[nxhtml-features-check] to get a list of these optional
1340   features and modules needed. You should however have no problem
1341   with this if you have followed the installation instructions
1342   for nXhtml."
1343   :keymap nxhtml-menu-mode-map
1344   :group 'nxhtml
1345   :global t
1346   )
1347
1348 (defalias 'nxhtml-minor-mode 'nxhtml-menu-mode)
1349 (defalias 'nxhtml-global-minor-mode 'nxhtml-menu-mode)
1350
1351 ;; (defcustom nxhtml-menu-mode-modes
1352 ;;   '(
1353 ;;     nxhtml-mode
1354 ;;     nxml-mode
1355 ;;     html-mode
1356 ;;     sgml-mode
1357 ;;     xml-mode
1358 ;;     php-mode
1359 ;;     css-mode
1360 ;;     javascript-mode
1361 ;;     java-mode ;; jsp
1362 ;;     groovy-mode ;; gsp
1363 ;;     image-mode
1364 ;;     ;;
1365 ;;     dired-mode
1366 ;;     )
1367 ;;   "List for turning on `nxhtml-menu-mode'.
1368 ;; If the buffer's major modes is any of those in this list then
1369 ;; `nxhtml-global-minor-mode' will turn on `nxhtml-menu-mode' in
1370 ;; the buffer."
1371 ;;   :type '(repeat (symbol :tag "Major mode"))
1372 ;;   :group 'nxhtml)
1373
1374 ;; (defun nxhtml-maybe-turn-on-minor-mode ()
1375 ;;   "Maybe turn on `nxhtml-menu-mode'.
1376 ;; See `nxhtml-menu-mode-modes'."
1377 ;;   (nxhtml-menu-mode 1))
1378 ;; (unless (or (minibufferp (current-buffer))
1379 ;;             (string= " " (substring (buffer-name) 0 1))
1380 ;;             (string= "*" (substring (buffer-name) 0 1))
1381 ;;             )
1382 ;;   (let ((on (and (boundp 'mumamo-multi-major-mode)
1383 ;;                  mumamo-multi-major-mode)))
1384 ;;     (dolist (major nxhtml-menu-mode-modes)
1385 ;;       (when (derived-mode-p major)
1386 ;;         (setq on t)))
1387 ;;     (when on
1388 ;;       (nxhtml-menu-mode 1)))))
1389
1390 ;; (define-globalized-minor-mode nxhtml-global-minor-mode
1391 ;;   nxhtml-menu-mode
1392 ;;   nxhtml-maybe-turn-on-minor-mode
1393 ;;   ;;:require 'nxhtml-menu
1394 ;;   :group 'nxhtml)
1395 ;;(message "nxhtml-menu:here A")
1396 ;;(custom-reevaluate-setting 'nxhtml-global-minor-mode)
1397 ;;(message "nxhtml-menu:here B")
1398 ;;(when nxhtml-global-minor-mode (nxhtml-global-minor-mode 1))
1399 ;;(message "nxhtml-menu:here C")
1400
1401
1402 ;; (file-exists-p (nxhtml-docfile))
1403 ;; (find-file (nxhtml-docfile))
1404 (defun nxhtml-docfile ()
1405   (expand-file-name "nxhtml/doc/nxhtml.html" nxhtml-install-dir))
1406
1407 (defun nxhtml-docfile-url ()
1408   (let ((local-docfile (concat "file://" (nxhtml-docfile))))
1409     (if (and nxhtml-autoload-web
1410              (not (file-exists-p local-docfile)))
1411         "http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html"
1412       local-docfile)))
1413
1414 ;;;###autoload
1415 (defun nxhtml-overview ()
1416   "Show a HTML page with an overview of nXhtml."
1417   (interactive)
1418   (browse-url (nxhtml-docfile-url)))
1419
1420 (defun nxhtml-tutorials ()
1421   "Show a HTML page with a list of tutorials for nXhtml'."
1422   (interactive)
1423   (browse-url "http://ourcomments.org/Emacs/nXhtml/tut/tutorials.html"))
1424
1425 (defun nxhtml-custom-valfaced (value &optional bgcolor)
1426   (let ((v (if (sequencep value)
1427                (copy-seq value)
1428              value))
1429         (bgcolor (if bgcolor bgcolor "RGB:FF/FF/AA")))
1430     (put-text-property 0 (length v)
1431                        'face (list
1432                               'bold
1433                               (cons 'background-color bgcolor)
1434                               )
1435                        v)
1436     v))
1437 (defun nxhtml-custom-insert-nxhtml-row (symbol nxhtml-value description)
1438   (let ((desc (if description
1439                   (format "%s (%s)" description symbol)
1440                 (format "%s" (custom-unlispify-tag-name symbol)))))
1441     (widget-insert "  " description " (")
1442     (nxhtml-custom-describe-defun symbol)
1443     (widget-insert "): "
1444                    (nxhtml-custom-valfaced
1445                     (format "%s" (symbol-value symbol))
1446                     (if (eq (symbol-value symbol)
1447                             nxhtml-value)
1448                         "GreenYellow"
1449                       "gainsboro"))
1450                    "\n")))
1451
1452 (defun nxhtml-custom-h1(title &optional divider top-newline)
1453   (let ((s title))
1454     (put-text-property 0 (length s)
1455                        'face '(:weight bold
1456                                        :height 1.4
1457                                        :foreground "DarkGreen"
1458                                        ;;:underline t
1459                                        )
1460                        s)
1461     (when top-newline (widget-insert "\n"))
1462     ;;(when divider (widget-insert (nxhtml-custom-divider (length s))))
1463     (widget-insert s)
1464     ))
1465
1466 (defun widget-button-notify (widget &rest ignore)
1467   (apply (widget-get widget 'function) (widget-get widget 'data)))
1468
1469 (defun widget-insert-link (txt function data)
1470   (widget-insert-button txt function data
1471                         :button-face 'link
1472                         :mouse-face 'highlight
1473                         :button-prefix ""
1474                         :button-suffix ""))
1475
1476 (defun widget-insert-button (txt function data &rest keywords)
1477   (let ((btn (apply 'widget-create
1478                     (append
1479                      '(push-button
1480                        :notify
1481                        widget-button-notify)
1482                      keywords
1483                      (list txt)))))
1484     (widget-put btn 'data data)
1485     (widget-put btn 'function function)))
1486
1487 (defun nxhtml-custom-url-link (txt url)
1488   (let ((plain-url (substring-no-properties url)))
1489     (unless (equal txt url)
1490       (put-text-property 0 (length txt) 'help-echo plain-url txt))
1491     (put-text-property 0 (length txt) 'mouse-face 'highlight txt)
1492     (widget-insert-link txt 'browse-url (list url))))
1493
1494 (defun nxhtml-custom-describe-defun (sym &optional help)
1495   (let ((txt (symbol-name sym)))
1496     (when help
1497       (put-text-property 0 (length txt) 'help-echo help txt))
1498     (put-text-property 0 (length txt) 'mouse-face 'highlight txt)
1499     (widget-insert-link txt 'describe-function (list sym))))
1500
1501 ;; (defun nxhtml-quick-customize (&optional same-window)
1502 ;;   "Show page for Quick Customize of nXhtml."
1503 ;;   (interactive)
1504 ;;   (require 'nxhtml)
1505 ;;   (require 'custom)
1506 ;;   (require 'cus-edit)
1507 ;;   (if same-window
1508 ;;       (switch-to-buffer "*Quick Customize nXhtml*")
1509 ;;     (switch-to-buffer-other-window "*Quick Customize nXhtml*"))
1510 ;;   (kill-all-local-variables)
1511 ;;   (custom-mode)
1512 ;;   (let ((inhibit-read-only t))
1513 ;;     (erase-buffer))
1514 ;;   (let ((sFound "found")
1515 ;;         (sError "error"))
1516 ;;     (put-text-property 0 (length sFound)
1517 ;;                        'face '(bold
1518 ;;                                (foreground-color . "green")) sFound)
1519 ;;     (put-text-property 0 (length sError)
1520 ;;                        'face '(bold
1521 ;;                                (foreground-color . "red")) sError)
1522 ;;     (let* (
1523 ;;            (default-used "(not set yet - default used)")
1524 ;;            )
1525 ;;       (nxhtml-custom-h1 "Quick Customize for nXhtml" t)
1526 ;;       (widget-insert "
1527
1528 ;; This page is for a quick and easy setup of some ")
1529 ;;       (nxhtml-custom-url-link "nXhtml" (nxhtml-docfile-url))
1530 ;;       (widget-insert " features
1531 ;; that I did not want to turn on by default since they alter what
1532 ;; happens when you open a file.  I suggest however that you turn
1533 ;; them on since they are quite useful if you just understands what
1534 ;; is happening.
1535
1536 ;; The values you set here are saved so that they will be used next
1537 ;; time you start Emacs too.")
1538 ;;       ;;(widget-insert-link "customize nXhtml" 'customize-group (list 'nxhtml))
1539 ;;       (widget-insert "\n\n")
1540
1541 ;;       (nxhtml-custom-insert-nxhtml-row 'nxhtml-global-minor-mode t "Show the nXhtml menu in all relevant buffers\n\t")
1542 ;;       ;;(nxhtml-custom-insert-nxhtml-row 'mumamo-global-mode t "Turn on Multiple Major Mode in all relevant buffers\n\t")
1543 ;;       ;;(nxhtml-custom-insert-nxhtml-row 'mlinks-global-mode t "Make link of lins, for example href=\"...\"\n\t")
1544 ;;       ;;(nxhtml-custom-insert-nxhtml-row 'indent-region-mode t "Use TAB to indent region when it is selected\n\t")
1545
1546 ;;       (widget-insert "\n")
1547 ;;       (widget-insert-button " Turn them all on "
1548 ;;                           (lambda ()
1549 ;;                             (nxhtml-quick-all t)
1550 ;;                             (nxhtml-quick-customize t))
1551 ;;                           nil)
1552 ;;       (widget-insert "  ")
1553 ;;       (widget-insert-button " Turn them all off "
1554 ;;                           (lambda ()
1555 ;;                             (nxhtml-quick-all nil)
1556 ;;                             (nxhtml-quick-customize t))
1557 ;;                           nil)
1558 ;;       (beginning-of-line)
1559 ;;       )))
1560
1561 ;; (defun nxhtml-quick-all (on)
1562 ;;   (custom-set-and-prepare-save 'nxhtml-global-minor-mode on)
1563 ;;   ;;(custom-set-and-prepare-save 'mumamo-global-mode on)
1564 ;;   (custom-set-and-prepare-save 'indent-region-mode on)
1565 ;;   (when custom-file
1566 ;;     (custom-save-all)))
1567
1568 (defun custom-set-and-prepare-save (symbol value)
1569   "Set SYMBOL to VALUE and add to customize.
1570 Both the current value and the value to save is set, but
1571 `custom-save-all' must be called to save customization."
1572   (customize-set-variable symbol value)
1573   (customize-set-value symbol value)
1574   (customize-mark-to-save symbol))
1575
1576
1577 ;;(nxhtml-quick-customize)
1578
1579 (defun nxhtml-welcome ()
1580   "Show welcome information."
1581   (interactive)
1582   (require 'cus-edit)
1583   (let* ((bufnam "*nXhtml Welcome*")
1584          (oldbuf (get-buffer bufnam))
1585          (curwin (selected-window)))
1586     (switch-to-buffer-other-window bufnam)
1587     (unless oldbuf
1588       (let ((inhibit-read-only t)
1589             (here (point)))
1590         (Custom-mode)
1591         (nxhtml-menu-mode 1)
1592         (setq cursor-in-non-selected-windows nil)
1593         (nxhtml-custom-h1 "Welcome to nXhtml - a package for web editing" t)
1594         (insert "\n\n")
1595         (setq here (point))
1596         (insert "If you have not done it already it might "
1597                 "be a good time to read at least The Quick Guide in the ")
1598         (nxhtml-custom-url-link "nXhtml overview" (nxhtml-docfile-url))
1599         (insert " now.\n\n")
1600         (fill-region here (point))
1601         (setq here (point))
1602         (insert "And oh, wait! If you are new to Emacs too you might want "
1603                 "to take a quick ")
1604         (nxhtml-custom-url-link
1605          "Emacs tour"
1606          "http://www.gnu.org/software/emacs/tour/")
1607         (insert ".  And then perhaps the Emacs tutorial "
1608                 "(which is in the Help menu above).\n\n")
1609         (fill-region here (point))
1610         (setq here (point))
1611
1612         (unless (nxhtml-skip-welcome)
1613           (insert "Click to ")
1614           (widget-insert-link "remove this message"
1615                               (lambda ()
1616                                 "Customize `nxhtml-skip-welcome'."
1617                                 (customize-option 'nxhtml-skip-welcome))
1618                               nil)
1619           (insert " at startup.  (This page is still "
1620                   "available in the nXhtml menu, at the bottom.)"))
1621         (fill-region here (point))
1622         (setq here (point))
1623         (goto-char (point-min))))
1624     (select-window curwin)))
1625
1626 (defcustom nxhtml-skip-welcome nil
1627   "Turn this on to always skip the nXhtml welcome message."
1628   :type 'boolean
1629   :group 'nxhtml)
1630
1631 (defun nxhtml-skip-welcome ()
1632   "Return t if nXhtml welcome message should be skipped.
1633 If nil then the message will be shown when you open the first
1634 file using nxhtml-mode."
1635   (or nxhtml-skip-welcome
1636       (and nxhtml-menu-mode
1637            ;;mumamo-global-mode
1638            ;;indent-region-mode
1639            )))
1640
1641 (defun nxhtml-say-welcome-unless-skip ()
1642   (condition-case err
1643       (unless (nxhtml-skip-welcome)
1644         (save-match-data
1645           (nxhtml-welcome)))
1646     (error (message "ERROR nxhtml-say-welcome-unless-skip: %s" err))))
1647
1648 ;; Show welcome screen once after loading nxhtml:
1649 ;;(unless (boundp 'bytecomp-filename)
1650 (eval-when '(load)
1651   (eval-after-load 'nxhtml
1652     ;; Use a short delay if something like desktop is used:
1653     '(run-with-idle-timer 0.5 nil 'nxhtml-say-welcome-unless-skip)))
1654
1655 (provide 'nxhtml-menu)
1656
1657 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1658 ;;; nxhtml-menu.el ends here