Initial Commit
[packages] / xemacs-packages / hm--html-menus / hm--html-mode.el
1 ;;; hm--html-mode --- Major mode for editing HTML documents for the WWW
2
3 ;; Copyright (C) 1996 - 1998 Heiko Muenkel
4
5 ;; Author: Heiko Muenkel <muenkel@tnt.uni-hannover.de>
6 ;; Keywords: hypermedia languages help docs wp
7
8 ;; $Id: hm--html-mode.el,v 6.20 1998-12-03 17:18:29 muenkel Exp $
9
10 ;; This file is part of XEmacs.
11
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your
15 ;; option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; See the file COPYING. if not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA
26
27 ;;; Synched up with: Not part of Emacs.
28
29 ;;; Commentary:
30
31 ;; Description:
32
33 ;;      This file defines the hm--html-mode, a mode for editing html
34 ;;      files. It is the main file of the package hm--html-menus.
35 ;;      Previous releases had used the file html-mode.el from Marc
36 ;;      Andreessen. In that times the mode was called html-mode. I've
37 ;;      changed the name of the mode to distinquish it from other
38 ;;      html modes. But feel free to set a 
39 ;;              (defalias 'hm--html-mode 'html-mode)
40 ;;      to get back the old name of the mode.
41
42 ;;      In the earlier releases of the package the main file was
43 ;;      hm--html-menu.el. This has been changed to hm--html-mode.el.
44
45
46 ;; Installation: 
47
48 ;;      Put this file and all the other files of the package
49 ;;      in one of your load path directories and the
50 ;;      following lines in your .emacs:
51
52 ;;      (autoload 'hm--html-mode "hm--html-mode" "HTML major mode." t)
53
54 ;;      (or (assoc "\\.html$" auto-mode-alist)
55 ;;         (setq auto-mode-alist (cons '("\\.html$" . hm--html-mode) 
56 ;;                                      auto-mode-alist)))
57 ;;      If there is already another html-mode (like psgml in the XEmacs
58 ;;      19.14, then you must put the following instead of the last form
59 ;;      in your .emacs:
60 ;;      (setq auto-mode-alist (cons '("\\.html$" . hm--html-mode) 
61 ;;                                      auto-mode-alist))
62
63 ;;      But you can also use the hm--html-minor-mode as an addition to
64 ;;      the psgml html modes. For that you've to put the following line in
65 ;;      your .emacs:
66 ;;      (add-hook 'html-mode-hook 'hm--html-minor-mode)
67
68 ;;      Note: This works only in an XEmacs version greater than 19.14 and
69 ;;      also not in the XEmacs 20.0.
70
71 ;;      Look at the file hm--html-configuration for further installation
72 ;;      points.
73
74 ;;; Code:
75
76 (require 'font-lock)
77 (require 'cl)
78 (require 'adapt)
79 (require 'hm--date)
80 (require 'hm--html)
81 ;(require 'hm--html-not-standard)
82
83 (eval-when-compile
84   (require 'hm--html-configuration))
85
86 (hm--html-load-config-files)
87 (require 'hm--html-indentation)
88
89 (defvar hm--html-minor-mode nil
90   "Non-nil, if the `hm--html-minor-mode' is active.")
91
92 (require 'hm--html-menu)
93
94 (require 'hm--html-keys)
95
96 ;(defvar hm--html-minor-mode nil
97 ;  "Non-nil, if the `hm--html-minor-mode' is active.")
98 ;
99 ;(require 'hm--html-menu)
100 (require 'hm--html-drag-and-drop)
101
102
103 ;;; The package version
104 (defconst hm--html-menus-package-maintainer "muenkel@tnt.uni-hannover.de")
105
106 (defconst hm--html-menus-package-name "hm--html-menus")
107
108 (defconst hm--html-menus-package-version "5.9")
109   
110
111 ;;; Generate the help buffer faces
112 (hm--html-generate-help-buffer-faces)
113
114 ;;; syntax table
115
116 (defvar hm--html-mode-syntax-table nil
117   "Syntax table used while in html mode.")
118
119 (if hm--html-mode-syntax-table
120     ()
121   (setq hm--html-mode-syntax-table (make-syntax-table))
122 ;  (modify-syntax-entry ?\" ".   " hm--html-mode-syntax-table)
123 ;  (modify-syntax-entry ?\\ ".   " hm--html-mode-syntax-table)
124 ;  (modify-syntax-entry ?'  "w   " hm--html-mode-syntax-table)
125   (modify-syntax-entry ?\\ "." hm--html-mode-syntax-table)
126   (modify-syntax-entry ?'  "w" hm--html-mode-syntax-table)
127   (modify-syntax-entry ?<  "(>" hm--html-mode-syntax-table)
128   (modify-syntax-entry ?>  ")<" hm--html-mode-syntax-table)
129   (modify-syntax-entry ?\" "\"" hm--html-mode-syntax-table)
130   (modify-syntax-entry ?=  "."  hm--html-mode-syntax-table))
131
132
133 ;;; abbreviation table
134
135 (defvar hm--html-mode-abbrev-table nil
136   "Abbrev table used while in html mode.")
137
138 (define-abbrev-table 'hm--html-mode-abbrev-table ())
139
140 ;;; the hm--html-mode
141
142 (defvar hm--html-mode-name-string "HTML"
143   "The hm--html-mode name string.")
144
145 ;;;###autoload
146 (defun hm--html-mode ()
147   "Major mode for editing HTML hypertext documents.  
148 Special commands:\\{hm--html-mode-map}
149 Turning on hm--html-mode calls the value of the variable hm--html-mode-hook,
150 if that value is non-nil."
151   (interactive)
152   (kill-all-local-variables)
153   (use-local-map hm--html-mode-map)
154   (setq mode-name hm--html-mode-name-string)
155   (setq major-mode 'hm--html-mode)
156   (setq local-abbrev-table hm--html-mode-abbrev-table)
157   (set-syntax-table hm--html-mode-syntax-table)
158   (make-local-variable 'comment-start)
159   (make-local-variable 'comment-end)
160   (setq comment-start "<!--" comment-end "-->")
161   (make-local-variable 'sentence-end)
162   (setq sentence-end "[<>.?!][]\"')}]*\\($\\| $\\|\t\\|  \\)[ \t\n]*")
163   (make-local-variable 'indent-line-function)
164   (setq indent-line-function 'hm--html-indent-line)
165   (setq idd-actions hm--html-idd-actions)
166   (hm--install-html-menu hm--html-mode-pulldown-menu-name)
167   (make-variable-buffer-local 'write-file-hooks)
168   (add-hook 'write-file-hooks 'hm--html-maybe-new-date-and-changed-comment)
169   (if (adapt-xemacsp)
170       (put major-mode 'font-lock-defaults '((hm--html-font-lock-keywords
171                                              hm--html-font-lock-keywords-1
172                                              hm--html-font-lock-keywords-2)
173                                             t
174                                             t
175                                             nil
176                                             nil))
177     (make-local-variable 'font-lock-defaults)
178     (setq font-lock-defaults '((hm--html-font-lock-keywords
179                                 hm--html-font-lock-keywords-1
180                                 hm--html-font-lock-keywords-2)
181                                t
182                                t
183                                nil
184                                nil)))
185   (run-hooks 'hm--html-mode-hook))
186
187 ;;;; Minor Modes
188
189 ;;; hm--html-region-mode 
190
191 (defvar hm--html-region-mode nil
192   "T, if the region is active in the `hm--html-mode'.")
193
194 (make-variable-buffer-local 'hm--html-region-mode)
195
196 (add-minor-mode 'hm--html-region-mode " Region" hm--html-region-mode-map)
197
198 (if (adapt-xemacsp)
199
200     (defun hm--html-region-mode (&optional arg)
201       "Toggle 'hm--html-region-mode'.
202 With ARG, turn hm--html-region-mode on iff ARG is positive.
203
204 If the `major-mode' isn't the `hm--html-mode' then the minor
205 mode is switched off, regardless of the ARG and the state
206 of `hm--html-region-mode'."
207       (interactive "P")
208       (setq zmacs-regions-stays t)
209       (setq hm--html-region-mode
210             (and (eq major-mode 'hm--html-mode)
211                  (if (null arg) (not hm--html-region-mode)
212                    (> (prefix-numeric-value arg) 0))))
213       (redraw-modeline)
214       )
215
216     (defun hm--html-region-mode (&optional arg)
217       "Toggle 'hm--html-region-mode'.
218 With ARG, turn hm--html-region-mode on iff ARG is positive.
219
220 If the `major-mode' isn't the `hm--html-mode' then the minor
221 mode is switched off, regardless of the ARG and the state
222 of `hm--html-region-mode'."
223       (interactive "P")
224       (setq hm--html-region-mode
225             (and (eq major-mode 'hm--html-mode)
226                  (if (null arg) (not hm--html-region-mode)
227                    (> (prefix-numeric-value arg) 0))))
228       (if hm--html-region-mode
229           (define-key hm--html-mode-map
230             hm--html-emacs19-popup-noregion-menu-button
231             nil)
232         (if hm--html-expert
233             (define-key hm--html-mode-map
234               hm--html-emacs19-popup-noregion-menu-button
235               hm--html-menu-noregion-expert-map)
236           (define-key hm--html-mode-map
237               hm--html-emacs19-popup-noregion-menu-button
238               hm--html-menu-noregion-novice-map)))
239       )
240     (redraw-modeline)
241     )
242
243
244 ;;; hm--html-minor-mode
245 (make-variable-buffer-local 'hm--html-minor-mode)
246
247 (add-minor-mode 'hm--html-minor-mode " HM-HTML" hm--html-minor-mode-map)
248
249 ;;;###autoload
250 (defun hm--html-minor-mode (&optional arg)
251   "Toggle hm--html-minor-mode.
252 With arg, turn hm--html-minor-mode on iff arg is positive."
253   (interactive "P")
254   (setq hm--html-minor-mode
255         (if (null arg) (not hm--html-minor-mode)
256           (> (prefix-numeric-value arg) 0)))
257   (if hm--html-minor-mode
258       (progn
259         (hm--install-html-menu hm--html-minor-mode-pulldown-menu-name)
260
261         ;; In the future it may be a good idea to merge the contents
262         ;; of the idd-actions of the major mode with the one of the
263         ;; minor mode.
264         (setq idd-actions hm--html-idd-actions)
265         (when (adapt-emacsp)
266           (hm--html-add-major-menu-to-minor-menus)))
267     (when (and (featurep 'menubar)
268                current-menubar 
269                (assoc hm--html-minor-mode-pulldown-menu-name
270                       current-menubar))
271       (delete-menu-item (list hm--html-minor-mode-pulldown-menu-name)))
272     (when (adapt-emacsp)
273       (hm--html-remove-major-menu-from-minor-menus)))
274   (redraw-modeline)
275   )
276   
277
278 ;;; hm--html-minor-region-mode
279
280 (defvar hm--html-minor-region-mode nil
281   "Non-nil, if the `hm--html-minor-region-mode' is active.")
282
283 (make-variable-buffer-local 'hm--html-minor-region-mode)
284
285 (add-minor-mode 'hm--html-minor-region-mode 
286                 " Region" 
287                 hm--html-minor-region-mode-map)
288
289
290 (if (adapt-xemacsp)
291
292     (defun hm--html-minor-region-mode (&optional arg)
293       "Toggle `hm--html-minor-region-mode'.
294 With arg, turn `hm--html-minor-region-mode' on iff arg is positive.
295
296 But however, if the `hm--html-minor-mode' isn't active, then it
297 turns `hm--html-minor-region-mode' off."
298       (interactive "P")
299       (setq zmacs-regions-stays t)
300       (setq hm--html-minor-region-mode
301             (and hm--html-minor-mode
302                  (if (null arg) (not hm--html-minor-region-mode)
303                    (> (prefix-numeric-value arg) 0))))
304       (redraw-modeline)
305       )
306
307     (defun hm--html-minor-region-mode (&optional arg)
308       "Toggle `hm--html-minor-region-mode'.
309 With arg, turn `hm--html-minor-region-mode' on iff arg is positive.
310
311 But however, if the `hm--html-minor-mode' isn't active, then it
312 turns `hm--html-minor-region-mode' off."
313       (interactive "P")
314       (setq hm--html-minor-region-mode
315             (and hm--html-minor-mode
316                  (if (null arg) (not hm--html-minor-region-mode)
317                    (> (prefix-numeric-value arg) 0))))
318       (if hm--html-minor-region-mode
319           (define-key hm--html-minor-mode-map
320             hm--html-emacs19-popup-noregion-menu-button
321             nil)
322         (if hm--html-expert
323             (define-key hm--html-minor-mode-map
324               hm--html-emacs19-popup-noregion-menu-button
325               hm--html-menu-noregion-expert-map)
326           (define-key hm--html-minor-mode-map
327               hm--html-emacs19-popup-noregion-menu-button
328               hm--html-menu-noregion-novice-map)))
329       )
330     (redraw-modeline)
331     )
332
333   
334
335 ;;; Hook function for toggling the region minor modes
336 (defun hm--html-switch-region-modes-on ()
337   "Switches the region minor modes of the hm--html-menus package on.
338 This function should be only be used for the `zmacs-activate-region-hook'
339 or for the `activate-mark-hook'."
340   (hm--html-region-mode 1)
341   (hm--html-minor-region-mode 1))
342
343 (defun hm--html-switch-region-modes-off ()
344   "Switches the region minor modes of the hm--html-menus package on.
345 This function should be only be used for the `zmacs-deactivate-region-hook'
346 or for the `deactivate-mark-hook'."
347   (hm--html-region-mode -1)
348   (hm--html-minor-region-mode -1))
349     
350
351 ;;; Run the load hook
352 (run-hooks 'hm--html-load-hook)
353
354
355 ;;; Announce the feature hm--html-configuration
356 (provide 'hm--html-mode)
357
358
359 ;;; hm--html-mode.el ends here