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