1 |
;;; sgml-mode.el --- SGML- and HTML-editing modes |
;;; sgml-mode.el --- SGML- and HTML-editing modes |
2 |
|
|
3 |
;; Copyright (C) 1992,95,96,98,2001 Free Software Foundation, Inc. |
;; Copyright (C) 1992,95,96,98,2001,2002 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: James Clark <jjc@jclark.com> |
;; Author: James Clark <jjc@jclark.com> |
6 |
|
;; Maintainer: FSF |
7 |
;; Adapted-By: ESR, Daniel Pfeiffer <occitan@esperanto.org>, |
;; Adapted-By: ESR, Daniel Pfeiffer <occitan@esperanto.org>, |
8 |
;; F.Potorti@cnuce.cnr.it |
;; F.Potorti@cnuce.cnr.it |
9 |
;; Keywords: wp, hypermedia, comm, languages |
;; Keywords: wp, hypermedia, comm, languages |
226 |
:group 'sgml) |
:group 'sgml) |
227 |
|
|
228 |
(defconst sgml-start-tag-regex |
(defconst sgml-start-tag-regex |
229 |
"<[A-Za-z]\\([-.A-Za-z0-9= \n\t]\\|\"[^\"]*\"\\|'[^']*'\\)*" |
"<[[:alpha:]]\\([-_.:[:alnum:]= \n\t]\\|\"[^\"]*\"\\|'[^']*'\\)*" |
230 |
"Regular expression that matches a non-empty start tag. |
"Regular expression that matches a non-empty start tag. |
231 |
Any terminating `>' or `/' is not matched.") |
Any terminating `>' or `/' is not matched.") |
232 |
|
|
233 |
|
|
234 |
;; internal |
;; internal |
235 |
(defconst sgml-font-lock-keywords-1 |
(defconst sgml-font-lock-keywords-1 |
236 |
'(("<\\([!?][a-z][-.a-z0-9]*\\)" 1 font-lock-keyword-face) |
'(("<\\([!?][[:alpha:]][-_.:[:alnum:]]*\\)" 1 font-lock-keyword-face) |
237 |
("<\\(/?[a-z][-.a-z0-9]*\\)" 1 font-lock-function-name-face) |
("<\\(/?[[:alpha:]][-_.:[:alnum:]]*\\)" 1 font-lock-function-name-face) |
238 |
("[&%][a-z][-.a-z0-9]*;?" . font-lock-variable-name-face))) |
;; FIXME: this doesn't cover the variable using a default value. |
239 |
|
("\\([[:alpha:]][-_.:[:alnum:]]*\\)=[\"']" 1 font-lock-variable-name-face) |
240 |
|
("[&%][[:alpha:]][-_.:[:alnum:]]*;?" . font-lock-variable-name-face))) |
241 |
|
|
242 |
(defconst sgml-font-lock-keywords-2 |
(defconst sgml-font-lock-keywords-2 |
243 |
(append |
(append |
367 |
;; This is desirable because SGML discards a newline that appears |
;; This is desirable because SGML discards a newline that appears |
368 |
;; immediately after a start tag or immediately before an end tag. |
;; immediately after a start tag or immediately before an end tag. |
369 |
(set (make-local-variable 'paragraph-separate) "[ \t]*$\\|\ |
(set (make-local-variable 'paragraph-separate) "[ \t]*$\\|\ |
370 |
\[ \t]*</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$") |
\[ \t]*</?\\([[:alpha:]]\\([-_.:[:alnum:]= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$") |
371 |
(set (make-local-variable 'paragraph-start) "[ \t]*$\\|\ |
(set (make-local-variable 'paragraph-start) "[ \t]*$\\|\ |
372 |
\[ \t]*</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>") |
\[ \t]*</?\\([[:alpha:]]\\([-_.:[:alnum:]= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>") |
373 |
(set (make-local-variable 'adaptive-fill-regexp) "[ \t]*") |
(set (make-local-variable 'adaptive-fill-regexp) "[ \t]*") |
374 |
(set (make-local-variable 'comment-start) "<!-- ") |
(set (make-local-variable 'comment-start) "<!-- ") |
375 |
(set (make-local-variable 'comment-end) " -->") |
(set (make-local-variable 'comment-end) " -->") |
432 |
;; Set `imenu-generic-expression' here, rather than in `sgml-mode-common', |
;; Set `imenu-generic-expression' here, rather than in `sgml-mode-common', |
433 |
;; because this definition probably is not useful in HTML mode. |
;; because this definition probably is not useful in HTML mode. |
434 |
(set (make-local-variable 'imenu-generic-expression) |
(set (make-local-variable 'imenu-generic-expression) |
435 |
"<!\\(element\\|entity\\)[ \t\n]+%?[ \t\n]*\\([A-Za-z][-A-Za-z.0-9]*\\)")) |
"<!\\(element\\|entity\\)[ \t\n]+%?[ \t\n]*\\([[:alpha:]][-_.:[:alnum:]]*\\)")) |
436 |
|
|
437 |
|
|
438 |
(defun sgml-comment-indent () |
(defun sgml-comment-indent () |
481 |
(1+ blinkpos))))))))) |
(1+ blinkpos))))))))) |
482 |
|
|
483 |
|
|
484 |
|
;; Why doesn't this use the iso-cvt table or, preferably, generate the |
485 |
|
;; inverse of the extensive table in the SGML Quail input method? -- fx |
486 |
|
;; I guess that's moot since it only works with Latin-1 anyhow. |
487 |
(defun sgml-name-char (&optional char) |
(defun sgml-name-char (&optional char) |
488 |
"Insert a symbolic character name according to `sgml-char-names'. |
"Insert a symbolic character name according to `sgml-char-names'. |
489 |
Non-ASCII chars may be inserted either with the meta key, as in M-SPC for |
Non-ASCII chars may be inserted either with the meta key, as in M-SPC for |
505 |
?\;)) |
?\;)) |
506 |
((aref sgml-char-names-table char) |
((aref sgml-char-names-table char) |
507 |
(insert ?& (aref sgml-char-names-table char) ?\;)) |
(insert ?& (aref sgml-char-names-table char) ?\;)) |
508 |
((memq (char-charset char) '(mule-unicode-0100-24ff |
((let ((c (encode-char char 'ucs))) |
509 |
mule-unicode-2500-33ff |
(when c |
510 |
mule-unicode-e000-ffff)) |
(insert (format "&#%d;" c)) |
511 |
(insert (format "&#%d;" (encode-char char 'ucs)))) |
t))) |
512 |
(t |
(t ; should be an error? -- fx |
513 |
(insert char)))) |
(insert char)))) |
514 |
|
|
515 |
(defun sgml-name-self () |
(defun sgml-name-self () |
529 |
(self-insert-command 1))) |
(self-insert-command 1))) |
530 |
|
|
531 |
(defun sgml-name-8bit-mode () |
(defun sgml-name-8bit-mode () |
532 |
"Toggle whether to insert named entities instead of non-ASCII characters." |
"Toggle whether to insert named entities instead of non-ASCII characters. |
533 |
|
This only works for Latin-1 input." |
534 |
(interactive) |
(interactive) |
535 |
(setq sgml-name-8bit-mode (not sgml-name-8bit-mode)) |
(setq sgml-name-8bit-mode (not sgml-name-8bit-mode)) |
536 |
(message "sgml name entity mode is now %s" |
(message "sgml name entity mode is now %s" |
784 |
(if arg |
(if arg |
785 |
(>= (prefix-numeric-value arg) 0) |
(>= (prefix-numeric-value arg) 0) |
786 |
(not sgml-tags-invisible))) |
(not sgml-tags-invisible))) |
787 |
(while (re-search-forward "<\\([!/?A-Za-z][-A-Za-z0-9]*\\)" |
(while (re-search-forward "<\\([!/?]?[[:alpha:]][-_.:[:alnum:]]*\\)" |
788 |
nil t) |
nil t) |
789 |
(setq string |
(setq string |
790 |
(cdr (assq (intern-soft (downcase (match-string 1))) |
(cdr (assq (intern-soft (downcase (match-string 1))) |
857 |
(forward-list) |
(forward-list) |
858 |
(point)) |
(point)) |
859 |
0))) |
0))) |
860 |
(if (looking-at "<[!?/]?[[A-Za-z][A-Za-z0-9]*") |
(if (looking-at "<[!/?]?[[:alpha:]][-_.:[:alnum:]]*") |
861 |
(buffer-substring-no-properties |
(buffer-substring-no-properties |
862 |
(1+ (point)) |
(1+ (point)) |
863 |
(match-end 0)) |
(match-end 0)) |
1305 |
outline-regexp "^.*<[Hh][1-6]\\>" |
outline-regexp "^.*<[Hh][1-6]\\>" |
1306 |
outline-heading-end-regexp "</[Hh][1-6]>" |
outline-heading-end-regexp "</[Hh][1-6]>" |
1307 |
outline-level (lambda () |
outline-level (lambda () |
1308 |
(char-after (1- (match-end 0))))) |
(char-before (match-end 0)))) |
1309 |
(setq imenu-create-index-function 'html-imenu-index) |
(setq imenu-create-index-function 'html-imenu-index) |
1310 |
(when sgml-xml (setq mode-name "XHTML")) |
(when sgml-xml (setq mode-name "XHTML")) |
1311 |
(set (make-local-variable 'sgml-empty-tags) |
(set (make-local-variable 'sgml-empty-tags) |