diff options
author | Eli Zaretskii <eliz@gnu.org> | 2001-10-22 09:45:39 +0000 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2001-10-22 09:45:39 +0000 |
commit | 2840d65358dfe3488bcdacf08ca101ef41f85be5 (patch) | |
tree | 22f43ae190b84ce113ff2f0a18ee6b74d70eb11c /lisp/textmodes | |
parent | af0569548bc90f166de0499651cd82bf3fa67b52 (diff) | |
download | emacs-2840d65358dfe3488bcdacf08ca101ef41f85be5.tar.gz |
(sgml-mode-map): Bind 8-bit codes above 127 to sgml-maybe-name-self.
(sgml-name-8bit-mode): Doc fix.
(sgml-char-names-table): New variable.
(sgml-name-char): Support non-ASCII and mule-unicode-* characters. Doc fix.
(sgml-maybe-name-self): Convert unibyte characters to multibyte.
Diffstat (limited to 'lisp/textmodes')
-rw-r--r-- | lisp/textmodes/sgml-mode.el | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 612c3f36880..a97f0888b11 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -106,6 +106,10 @@ This takes effect when first loading the sgml-mode library.") (define-key map "'" 'sgml-name-self))) (define-key map (vector (make-char 'latin-iso8859-1)) 'sgml-maybe-name-self) + (let ((c 127) + (map (nth 1 map))) + (while (< (setq c (1+ c)) 256) + (aset map c 'sgml-maybe-name-self))) (define-key map [menu-bar sgml] (cons "SGML" menu-map)) (define-key menu-map [sgml-validate] '("Validate" . sgml-validate)) (define-key menu-map [sgml-name-8bit-mode] @@ -142,7 +146,7 @@ This takes effect when first loading the sgml-mode library.") (defcustom sgml-name-8bit-mode nil - "*When non-nil, insert 8 bit characters with their names." + "*When non-nil, insert non-ASCII characters as named entities." :type 'boolean :group 'sgml) @@ -181,6 +185,20 @@ This takes effect when first loading the sgml-mode library.") "oslash" "ugrave" "uacute" "ucirc" "uuml" "yacute" "thorn" "yuml"] "Vector of symbolic character names without `&' and `;'.") +(put 'sgml-table 'char-table-extra-slots 0) + +(defvar sgml-char-names-table + (let ((table (make-char-table 'sgml-table)) + (i 32) + elt) + (while (< i 256) + (setq elt (aref sgml-char-names i)) + (if elt (aset table (make-char 'latin-iso8859-1 i) elt)) + (setq i (1+ i))) + table) + "A table for mapping non-ASCII characters into SGML entity names. +Currently, only Latin-1 characters are supported.") + ;; nsgmls is a free SGML parser in the SP suite available from ;; ftp.jclark.com and otherwise packaged for GNU systems. @@ -448,8 +466,9 @@ start tag, and the second `/' is the corresponding null end tag." (defun sgml-name-char (&optional char) "Insert a symbolic character name according to `sgml-char-names'. -8 bit chars may be inserted with the meta key as in M-SPC for no break space, -or M-- for a soft hyphen." +Non-ASCII chars may be inserted either with the meta key, as in M-SPC for +no-break space or M-- for a soft hyphen; or via an input method or +encoded keyboard operation." (interactive "*") (insert ?&) (or char @@ -458,34 +477,42 @@ or M-- for a soft hyphen." (insert char) (undo-boundary) (delete-backward-char 1) - (insert ?& - (or (aref sgml-char-names char) - (format "#%d" char)) - ?\;)) - + (cond + ((< char 256) + (insert ?& + (or (aref sgml-char-names char) + (format "#%d" char)) + ?\;)) + ((aref sgml-char-names-table char) + (insert ?& (aref sgml-char-names-table char) ?\;)) + ((memq (char-charset char) '(mule-unicode-0100-24ff + mule-unicode-2500-33ff + mule-unicode-e000-ffff)) + (insert (format "&#%d;" (encode-char char 'ucs)))) + (t + (insert char)))) (defun sgml-name-self () "Insert a symbolic character name according to `sgml-char-names'." (interactive "*") (sgml-name-char last-command-char)) - (defun sgml-maybe-name-self () "Insert a symbolic character name according to `sgml-char-names'." (interactive "*") (if sgml-name-8bit-mode - (sgml-name-char - (if (eq (char-charset last-command-char) 'latin-iso8859-1) - (+ 128 (- last-command-char (make-char 'latin-iso8859-1))) - last-command-char)) + (let ((mc last-command-char)) + (if (< mc 256) + (setq mc (unibyte-char-to-multibyte mc))) + (or mc (setq mc last-command-char)) + (sgml-name-char mc)) (self-insert-command 1))) - (defun sgml-name-8bit-mode () - "Toggle insertion of 8 bit characters." + "Toggle whether to insert named entities instead of non-ASCII characters." (interactive) (setq sgml-name-8bit-mode (not sgml-name-8bit-mode)) - (message "sgml name 8 bit mode is now %s" + (message "sgml name entity mode is now %s" (if sgml-name-8bit-mode "ON" "OFF"))) |