Mercurial > emacs
annotate lisp/nxml/nxml-enc.el @ 110305:b10051866f51
New syntax-propertize functionality.
* lisp/font-lock.el (font-lock-syntactic-keywords): Make obsolete.
(font-lock-fontify-syntactic-keywords-region): Move handling of
font-lock-syntactically-fontified to...
(font-lock-default-fontify-region): ...here.
Let syntax-propertize-function take precedence.
(font-lock-fontify-syntactically-region): Cal syntax-propertize.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt-depth): Skip named groups.
* lisp/emacs-lisp/syntax.el (syntax-propertize-function)
(syntax-propertize-chunk-size, syntax-propertize--done)
(syntax-propertize-extend-region-functions): New vars.
(syntax-propertize-wholelines, syntax-propertize-multiline)
(syntax-propertize--shift-groups, syntax-propertize-via-font-lock)
(syntax-propertize): New functions.
(syntax-propertize-rules): New macro.
(syntax-ppss-flush-cache): Set syntax-propertize--done.
(syntax-ppss): Call syntax-propertize.
* lisp/progmodes/ada-mode.el (ada-set-syntax-table-properties)
(ada-after-change-function, ada-initialize-syntax-table-properties)
(ada-handle-syntax-table-properties): Only define when
syntax-propertize is not available.
(ada-mode): Use syntax-propertize-function.
* lisp/progmodes/autoconf.el (autoconf-mode):
Use syntax-propertize-function.
(autoconf-font-lock-syntactic-keywords): Remove.
* lisp/progmodes/cfengine.el (cfengine-mode):
Use syntax-propertize-function.
(cfengine-font-lock-syntactic-keywords): Remove.
* lisp/progmodes/cperl-mode.el (cperl-mode): Use syntax-propertize-function.
* lisp/progmodes/fortran.el (fortran-mode): Use syntax-propertize-function.
(fortran--font-lock-syntactic-keywords): New var.
(fortran-line-length): Update syntax-propertize-function and
fortran--font-lock-syntactic-keywords.
* lisp/progmodes/gud.el (gdb-script-syntax-propertize-function): New var;
replaces gdb-script-font-lock-syntactic-keywords.
(gdb-script-mode): Use it.
* lisp/progmodes/js.el (js--regexp-literal): Define while compiling.
(js-syntax-propertize-function): New var; replaces
js-font-lock-syntactic-keywords.
(js-mode): Use it.
* lisp/progmodes/make-mode.el (makefile-syntax-propertize-function):
New var; replaces makefile-font-lock-syntactic-keywords.
(makefile-mode): Use it.
(makefile-imake-mode): Adjust.
* lisp/progmodes/mixal-mode.el (mixal-syntax-propertize-function): New var;
replaces mixal-font-lock-syntactic-keywords.
(mixal-mode): Use it.
* lisp/progmodes/octave-mod.el (octave-syntax-propertize-sqs): New function
to replace octave-font-lock-close-quotes.
(octave-syntax-propertize-function): New function to replace
octave-font-lock-syntactic-keywords.
(octave-mode): Use it.
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function): New fun to
replace perl-font-lock-syntactic-keywords.
(perl-syntax-propertize-special-constructs): New fun to replace
perl-font-lock-special-syntactic-constructs.
(perl-font-lock-syntactic-face-function): New fun.
(perl-mode): Use it.
* lisp/progmodes/python.el (python-syntax-propertize-function): New var to
replace python-font-lock-syntactic-keywords.
(python-mode): Use it.
(python-quote-syntax): Simplify and adjust to new use.
* lisp/progmodes/ruby-mode.el (ruby-here-doc-beg-re):
Define while compiling.
(ruby-here-doc-end-re, ruby-here-doc-beg-match)
(ruby-font-lock-syntactic-keywords, ruby-comment-beg-syntax)
(syntax-ppss, ruby-in-ppss-context-p, ruby-in-here-doc-p)
(ruby-here-doc-find-end, ruby-here-doc-beg-syntax)
(ruby-here-doc-end-syntax): Only define when
syntax-propertize is not available.
(ruby-syntax-propertize-function, ruby-syntax-propertize-heredoc):
New functions.
(ruby-in-ppss-context-p): Update to new syntax of heredocs.
(electric-indent-chars): Silence bytecompiler.
(ruby-mode): Use prog-mode, syntax-propertize-function, and
electric-indent-chars.
* lisp/progmodes/sh-script.el (sh-st-symbol): Remove.
(sh-font-lock-close-heredoc, sh-font-lock-open-heredoc): Add eol arg.
(sh-font-lock-flush-syntax-ppss-cache, sh-font-lock-here-doc): Remove.
(sh-font-lock-quoted-subshell): Assume we've already matched $(.
(sh-font-lock-paren): Set syntax-multiline.
(sh-font-lock-syntactic-keywords): Remove.
(sh-syntax-propertize-function): New function to replace it.
(sh-mode): Use it.
* lisp/progmodes/simula.el (simula-syntax-propertize-function): New var to
replace simula-font-lock-syntactic-keywords.
(simula-mode): Use it.
* lisp/progmodes/tcl.el (tcl-syntax-propertize-function): New var to
replace tcl-font-lock-syntactic-keywords.
(tcl-mode): Use it.
* lisp/progmodes/vhdl-mode.el (vhdl-mode): Use syntax-propertize-function
if available.
(vhdl-fontify-buffer): Adjust.
* lisp/textmodes/bibtex.el (bibtex-mode): Use syntax-propertize-function.
* lisp/textmodes/reftex.el (font-lock-syntactic-keywords): Don't declare
since we don't use it.
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-function): New var to
replace sgml-font-lock-syntactic-keywords.
(sgml-mode): Use it.
* lisp/textmodes/tex-mode.el (tex-common-initialization, doctex-mode):
Use syntax-propertize-function.
* lisp/textmodes/texinfo.el (texinfo-syntax-propertize-function): New fun
to replace texinfo-font-lock-syntactic-keywords.
(texinfo-mode): Use it.
* test/indent/octave.m: Remove some `fixindent' not needed any more.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 11 Sep 2010 01:13:42 +0200 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
rev | line source |
---|---|
86361 | 1 ;;; nxml-enc.el --- XML encoding auto-detection |
2 | |
106815 | 3 ;; Copyright (C) 2003, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
86361 | 4 |
5 ;; Author: James Clark | |
6 ;; Keywords: XML | |
7 | |
86535 | 8 ;; This file is part of GNU Emacs. |
9 | |
94666
d495d4d5452f
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87665
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
86535 | 11 ;; it under the terms of the GNU General Public License as published by |
94666
d495d4d5452f
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87665
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
d495d4d5452f
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87665
diff
changeset
|
13 ;; (at your option) any later version. |
86361 | 14 |
86535 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
86361 | 19 |
86535 | 20 ;; You should have received a copy of the GNU General Public License |
94666
d495d4d5452f
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
87665
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
86361 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; User entry points are nxml-start-auto-coding and | |
26 ;; nxml-stop-auto-coding. This is separate from nxml-mode, because | |
27 ;; this cannot be autoloaded. It may use | |
28 ;; `xmltok-get-declared-encoding-position' which can be autoloaded. | |
29 ;; It's separate from rng-auto.el so it can be byte-compiled, and | |
30 ;; because it provides independent, useful functionality. | |
31 | |
32 ;;; Code: | |
33 | |
34 (defvar nxml-file-name-ignore-case | |
97142 | 35 (memq system-type '(windows-nt))) |
86361 | 36 |
37 (defvar nxml-cached-file-name-auto-coding-regexp nil) | |
38 (defvar nxml-cached-auto-mode-alist nil) | |
39 | |
40 (defun nxml-file-name-auto-coding-regexp () | |
41 "Return regexp for filenames for which XML auto-coding should be done." | |
42 (if (eq auto-mode-alist nxml-cached-auto-mode-alist) | |
43 nxml-cached-file-name-auto-coding-regexp | |
44 (let ((alist auto-mode-alist) | |
45 (case-fold-search nxml-file-name-ignore-case) | |
46 regexps) | |
47 (setq nxml-cached-auto-mode-alist alist) | |
48 (while alist | |
49 (when (eq (cdar alist) 'nxml-mode) | |
50 (setq regexps (cons (caar alist) regexps))) | |
51 (setq alist (cdr alist))) | |
52 (setq nxml-cached-file-name-auto-coding-regexp | |
53 (if (null (cdr regexps)) | |
54 (car regexps) | |
55 (mapconcat (lambda (r) | |
56 (concat "\\(?:" r "\\)")) | |
57 regexps | |
58 "\\|")))))) | |
59 | |
60 (defvar nxml-non-xml-set-auto-coding-function nil | |
61 "The function that `set-auto-coding-function' should call for non-XML files.") | |
62 (defun nxml-set-auto-coding (file-name size) | |
63 (if (let ((case-fold-search nxml-file-name-ignore-case) | |
64 (regexp (nxml-file-name-auto-coding-regexp))) | |
65 (and regexp | |
66 (string-match regexp file-name))) | |
67 (nxml-set-xml-coding file-name size) | |
68 (and nxml-non-xml-set-auto-coding-function | |
69 (funcall nxml-non-xml-set-auto-coding-function file-name size)))) | |
70 | |
71 (defun nxml-set-xml-coding (file-name size) | |
72 "Function to use as `set-auto-coding-function' when file is known to be XML." | |
73 (nxml-detect-coding-system (+ (point) (min size 1024)))) | |
74 | |
86535 | 75 (declare-function xmltok-get-declared-encoding-position "xmltok" |
76 (&optional limit)) ; autoloaded | |
77 | |
86361 | 78 (defun nxml-detect-coding-system (limit) |
79 (if (< limit (+ (point) 2)) | |
80 (if (eq (char-after) 0) 'no-conversion 'utf-8) | |
81 (let ((first-two-chars (list (char-after) | |
82 (char-after (1+ (point)))))) | |
83 (cond ((equal first-two-chars '(#xFE #xFF)) | |
84 (and (coding-system-p 'utf-16-be) 'utf-16-be)) | |
85 ((equal first-two-chars '(#xFF #xFE)) | |
86 (and (coding-system-p 'utf-16-le) 'utf-16-le)) | |
87 ((memq 0 first-two-chars) | |
88 ;; Certainly not well-formed XML; | |
89 ;; perhaps UTF-16 without BOM. | |
90 ;; In any case, we can't handle it. | |
91 ;; no-conversion gives the user a chance to fix it. | |
92 'no-conversion) | |
93 ;; There are other things we might try here in the future | |
94 ;; eg UTF-8 BOM, UTF-16 with no BOM | |
95 ;; translate to EBCDIC | |
96 (t | |
97 (let ((enc-pos (xmltok-get-declared-encoding-position limit))) | |
98 (cond ((consp enc-pos) | |
99 (or (nxml-mime-charset-coding-system | |
100 (buffer-substring-no-properties (car enc-pos) | |
101 (cdr enc-pos))) | |
102 ;; We have an encoding whose name we don't recognize. | |
103 ;; What to do? | |
104 ;; raw-text seems the best bet: since we got | |
105 ;; the XML decl it must be a superset of ASCII, | |
106 ;; so we don't need to go to no-conversion | |
107 'raw-text)) | |
108 (enc-pos 'utf-8) | |
109 ;; invalid XML declaration | |
110 (t nil)))))))) | |
111 | |
112 (defun nxml-mime-charset-coding-system (charset) | |
113 (let ((charset-sym (intern (downcase charset))) | |
114 (coding-systems (coding-system-list t)) | |
115 coding-system ret) | |
116 (while (and coding-systems (not ret)) | |
117 (setq coding-system (car coding-systems)) | |
118 (if (eq (coding-system-get coding-system 'mime-charset) | |
119 charset-sym) | |
120 (setq ret coding-system) | |
121 (setq coding-systems (cdr coding-systems)))) | |
122 ret)) | |
123 | |
124 (defun nxml-start-auto-coding () | |
125 "Do encoding auto-detection as specified in the XML standard. | |
126 Applied to any files that `auto-mode-alist' says should be handled by | |
127 `nxml-mode'." | |
128 (interactive) | |
129 (unless (eq set-auto-coding-function 'nxml-set-auto-coding) | |
130 (let ((inhibit-quit t)) | |
131 (setq nxml-non-xml-set-auto-coding-function set-auto-coding-function) | |
132 (setq set-auto-coding-function 'nxml-set-auto-coding)))) | |
133 | |
134 (defun nxml-stop-auto-coding () | |
135 "Stop doing encoding auto-detection as specified in the XML standard." | |
136 (interactive) | |
137 (when (eq set-auto-coding-function 'nxml-set-auto-coding) | |
138 (let ((inhibit-quit t)) | |
139 (setq set-auto-coding-function nxml-non-xml-set-auto-coding-function) | |
140 (setq nxml-non-xml-set-auto-coding-function nil)))) | |
141 | |
99524
b8e68a14e5c2
Remove some charset code not needed since Emacs 22.
Glenn Morris <rgm@gnu.org>
parents:
97142
diff
changeset
|
142 ;; Emacs 22 makes us-ascii an alias for iso-safe without |
86361 | 143 ;; giving it a mime-charset property. |
144 (unless (coding-system-get 'us-ascii 'mime-charset) | |
145 (coding-system-put 'us-ascii 'mime-charset 'us-ascii)) | |
146 | |
147 (provide 'nxml-enc) | |
148 | |
86379 | 149 ;; arch-tag: c2436247-78f3-418c-8069-85dc5335d083 |
86361 | 150 ;;; nxml-enc.el ends here |