Commit | Line | Data |
---|---|---|
8cd39fb3 MH |
1 | ;;; nxml-util.el --- utility functions for nxml-*.el |
2 | ||
dcb8ac09 | 3 | ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc. |
8cd39fb3 MH |
4 | |
5 | ;; Author: James Clark | |
6 | ;; Keywords: XML | |
7 | ||
09aa73e6 | 8 | ;; This file is part of GNU Emacs. |
8cd39fb3 | 9 | |
4936186e | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
09aa73e6 | 11 | ;; it under the terms of the GNU General Public License as published by |
4936186e GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
8cd39fb3 | 14 | |
09aa73e6 GM |
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. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
4936186e | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8cd39fb3 MH |
22 | |
23 | ;;; Commentary: | |
24 | ||
25 | ;;; Code: | |
26 | ||
27 | (defun nxml-make-namespace (str) | |
28 | "Return a symbol for the namespace URI STR. | |
29 | STR must be a string. If STR is the empty string, return nil. | |
30 | Otherwise, return the symbol whose name is STR prefixed with a colon." | |
31 | (if (string-equal str "") | |
32 | nil | |
33 | (intern (concat ":" str)))) | |
34 | ||
35 | (defun nxml-namespace-name (ns) | |
36 | "Return the namespace URI corresponding to the symbol NS. | |
37 | This is the inverse of `nxml-make-namespace'." | |
38 | (and ns (substring (symbol-name ns) 1))) | |
39 | ||
40 | (defconst nxml-xml-namespace-uri | |
41 | (nxml-make-namespace "http://www.w3.org/XML/1998/namespace")) | |
42 | ||
43 | (defconst nxml-xmlns-namespace-uri | |
44 | (nxml-make-namespace "http://www.w3.org/2000/xmlns/")) | |
45 | ||
46 | (defmacro nxml-with-unmodifying-text-property-changes (&rest body) | |
47 | "Evaluate BODY without any text property changes modifying the buffer. | |
48 | Any text properties changes happen as usual but the changes are not treated as | |
49 | modifications to the buffer." | |
50 | (let ((modified (make-symbol "modified"))) | |
51 | `(let ((,modified (buffer-modified-p)) | |
52 | (inhibit-read-only t) | |
53 | (inhibit-modification-hooks t) | |
54 | (buffer-undo-list t) | |
55 | (deactivate-mark nil) | |
56 | ;; Apparently these avoid file locking problems. | |
57 | (buffer-file-name nil) | |
58 | (buffer-file-truename nil)) | |
59 | (unwind-protect | |
60 | (progn ,@body) | |
61 | (unless ,modified | |
62 | (restore-buffer-modified-p nil)))))) | |
63 | ||
64 | (put 'nxml-with-unmodifying-text-property-changes 'lisp-indent-function 0) | |
65 | (def-edebug-spec nxml-with-unmodifying-text-property-changes t) | |
66 | ||
67 | (defmacro nxml-with-invisible-motion (&rest body) | |
68 | "Evaluate body without calling any point motion hooks." | |
69 | `(let ((inhibit-point-motion-hooks t)) | |
70 | ,@body)) | |
71 | ||
72 | (put 'nxml-with-invisible-motion 'lisp-indent-function 0) | |
73 | (def-edebug-spec nxml-with-invisible-motion t) | |
74 | ||
75 | (defun nxml-display-file-parse-error (err) | |
76 | (let* ((filename (nth 1 err)) | |
77 | (buffer (find-file-noselect filename)) | |
78 | (pos (nth 2 err)) | |
79 | (message (nth 3 err))) | |
80 | (pop-to-buffer buffer) | |
81 | ;; What's the right thing to do if the buffer's modified? | |
82 | ;; The position in the saved file could be completely different. | |
83 | (goto-char (if (buffer-modified-p) 1 pos)) | |
84 | (error "%s" message))) | |
85 | ||
86 | (defun nxml-signal-file-parse-error (file pos message &optional error-symbol) | |
87 | (signal (or error-symbol 'nxml-file-parse-error) | |
88 | (list file pos message))) | |
89 | ||
90 | (put 'nxml-file-parse-error | |
91 | 'error-conditions | |
92 | '(error nxml-file-parse-error)) | |
93 | ||
94 | (put 'nxml-parse-file-error | |
95 | 'error-message | |
96 | "Error parsing file") | |
97 | ||
98 | (provide 'nxml-util) | |
99 | ||
ab4c34c6 | 100 | ;; arch-tag: 7d3b3af4-de2b-4410-bf67-94d64824324b |
8cd39fb3 | 101 | ;;; nxml-util.el ends here |