Mercurial > emacs
annotate lisp/nxml/nxml-util.el @ 109906:4083ea4ca585
xdisp.c: Fix typo in a comment in note_tool_bar_highlight.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 21 Aug 2010 16:25:03 +0300 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
rev | line source |
---|---|
86361 | 1 ;;; nxml-util.el --- utility functions for nxml-*.el |
2 | |
106815 | 3 ;; Copyright (C) 2003, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
86361 | 4 |
5 ;; Author: James Clark | |
6 ;; Keywords: XML | |
7 | |
86544 | 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 |
86544 | 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 |
86544 | 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 |
86544 | 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 ;;; Code: | |
26 | |
95598 | 27 (defconst nxml-debug nil |
96496
e374c747704b
Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents:
95599
diff
changeset
|
28 "Enable nxml debugging. Effective only at compile time.") |
95598 | 29 |
30 (defsubst nxml-debug (format &rest args) | |
31 (when nxml-debug | |
32 (apply #'message format args))) | |
33 | |
34 (defmacro nxml-debug-change (name start end) | |
35 (when nxml-debug | |
36 `(nxml-debug "%s: %S" ,name | |
37 (buffer-substring-no-properties ,start ,end)))) | |
38 | |
39 (defmacro nxml-debug-set-inside (start end) | |
40 (when nxml-debug | |
41 `(let ((overlay (make-overlay ,start ,end))) | |
42 (overlay-put overlay 'face '(:background "red")) | |
43 (overlay-put overlay 'nxml-inside-debug t) | |
44 (nxml-debug-change "nxml-set-inside" ,start ,end)))) | |
45 | |
46 (defmacro nxml-debug-clear-inside (start end) | |
47 (when nxml-debug | |
48 `(loop for overlay in (overlays-in ,start ,end) | |
49 if (overlay-get overlay 'nxml-inside-debug) | |
50 do (delete-overlay overlay) | |
51 finally (nxml-debug-change "nxml-clear-inside" ,start ,end)))) | |
52 | |
86361 | 53 (defun nxml-make-namespace (str) |
54 "Return a symbol for the namespace URI STR. | |
96496
e374c747704b
Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents:
95599
diff
changeset
|
55 STR must be a string. If STR is the empty string, return nil. |
86361 | 56 Otherwise, return the symbol whose name is STR prefixed with a colon." |
57 (if (string-equal str "") | |
58 nil | |
59 (intern (concat ":" str)))) | |
60 | |
61 (defun nxml-namespace-name (ns) | |
62 "Return the namespace URI corresponding to the symbol NS. | |
63 This is the inverse of `nxml-make-namespace'." | |
64 (and ns (substring (symbol-name ns) 1))) | |
65 | |
95598 | 66 (defconst nxml-xml-namespace-uri |
86361 | 67 (nxml-make-namespace "http://www.w3.org/XML/1998/namespace")) |
68 | |
69 (defconst nxml-xmlns-namespace-uri | |
70 (nxml-make-namespace "http://www.w3.org/2000/xmlns/")) | |
71 | |
95598 | 72 (defmacro nxml-with-degradation-on-error (context &rest body) |
73 (if (not nxml-debug) | |
74 (let ((error-symbol (make-symbol "err"))) | |
75 `(condition-case ,error-symbol | |
76 (progn ,@body) | |
77 (error | |
78 (nxml-degrade ,context ,error-symbol)))) | |
79 `(progn ,@body))) | |
80 | |
86361 | 81 (defmacro nxml-with-unmodifying-text-property-changes (&rest body) |
82 "Evaluate BODY without any text property changes modifying the buffer. | |
83 Any text properties changes happen as usual but the changes are not treated as | |
84 modifications to the buffer." | |
85 (let ((modified (make-symbol "modified"))) | |
86 `(let ((,modified (buffer-modified-p)) | |
87 (inhibit-read-only t) | |
88 (inhibit-modification-hooks t) | |
89 (buffer-undo-list t) | |
90 (deactivate-mark nil) | |
91 ;; Apparently these avoid file locking problems. | |
92 (buffer-file-name nil) | |
93 (buffer-file-truename nil)) | |
94 (unwind-protect | |
95 (progn ,@body) | |
96 (unless ,modified | |
97 (restore-buffer-modified-p nil)))))) | |
98 | |
99 (put 'nxml-with-unmodifying-text-property-changes 'lisp-indent-function 0) | |
100 (def-edebug-spec nxml-with-unmodifying-text-property-changes t) | |
101 | |
102 (defmacro nxml-with-invisible-motion (&rest body) | |
103 "Evaluate body without calling any point motion hooks." | |
104 `(let ((inhibit-point-motion-hooks t)) | |
105 ,@body)) | |
106 | |
107 (put 'nxml-with-invisible-motion 'lisp-indent-function 0) | |
108 (def-edebug-spec nxml-with-invisible-motion t) | |
109 | |
110 (defun nxml-display-file-parse-error (err) | |
111 (let* ((filename (nth 1 err)) | |
112 (buffer (find-file-noselect filename)) | |
113 (pos (nth 2 err)) | |
114 (message (nth 3 err))) | |
115 (pop-to-buffer buffer) | |
116 ;; What's the right thing to do if the buffer's modified? | |
117 ;; The position in the saved file could be completely different. | |
118 (goto-char (if (buffer-modified-p) 1 pos)) | |
119 (error "%s" message))) | |
120 | |
121 (defun nxml-signal-file-parse-error (file pos message &optional error-symbol) | |
122 (signal (or error-symbol 'nxml-file-parse-error) | |
123 (list file pos message))) | |
124 | |
125 (put 'nxml-file-parse-error | |
126 'error-conditions | |
127 '(error nxml-file-parse-error)) | |
128 | |
129 (put 'nxml-parse-file-error | |
130 'error-message | |
131 "Error parsing file") | |
132 | |
133 (provide 'nxml-util) | |
134 | |
86379 | 135 ;; arch-tag: 7d3b3af4-de2b-4410-bf67-94d64824324b |
86361 | 136 ;;; nxml-util.el ends here |