Redo the whole window offsets and coordinate translation for X.
[emacs.git] / lisp / nxml / nxml-util.el
blob27b438243120288b56deaa3d66b3def37cde5e53
1 ;;; nxml-util.el --- utility functions for nxml-*.el -*- lexical-binding:t -*-
3 ;; Copyright (C) 2003, 2007-2015 Free Software Foundation, Inc.
5 ;; Author: James Clark
6 ;; Keywords: wp, hypermedia, languages, XML
8 ;; This file is part of GNU Emacs.
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 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (defconst nxml-debug nil
28 "Enable nxml debugging. Effective only at compile time.")
30 (defsubst nxml-debug (format &rest args)
31 (when nxml-debug
32 (apply #'message format args)))
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))))
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))))
46 (defmacro nxml-debug-clear-inside (start end)
47 (when nxml-debug
48 `(cl-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))))
53 (defun nxml-make-namespace (str)
54 "Return a symbol for the namespace URI STR.
55 STR must be a string. If STR is the empty string, return nil.
56 Otherwise, return the symbol whose name is STR prefixed with a colon."
57 (if (string-equal str "")
58 nil
59 (intern (concat ":" str))))
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)))
66 (defconst nxml-xml-namespace-uri
67 (nxml-make-namespace "http://www.w3.org/XML/1998/namespace"))
69 (defconst nxml-xmlns-namespace-uri
70 (nxml-make-namespace "http://www.w3.org/2000/xmlns/"))
72 (defmacro nxml-with-degradation-on-error (context &rest body)
73 (declare (indent 1) (debug t))
74 (if (not nxml-debug)
75 (let ((error-symbol (make-symbol "err")))
76 `(condition-case ,error-symbol
77 (progn ,@body)
78 (error
79 (nxml-degrade ,context ,error-symbol))))
80 `(progn ,@body)))
82 (defmacro nxml-with-invisible-motion (&rest body)
83 "Evaluate body without calling any point motion hooks."
84 (declare (indent 0) (debug t))
85 `(let ((inhibit-point-motion-hooks t))
86 ,@body))
88 (defun nxml-display-file-parse-error (err)
89 (let* ((filename (nth 1 err))
90 (buffer (find-file-noselect filename))
91 (pos (nth 2 err))
92 (message (nth 3 err)))
93 (pop-to-buffer buffer)
94 ;; What's the right thing to do if the buffer's modified?
95 ;; The position in the saved file could be completely different.
96 (goto-char (if (buffer-modified-p) 1 pos))
97 (error "%s" message)))
99 (defun nxml-signal-file-parse-error (file pos message &optional error-symbol)
100 (signal (or error-symbol 'nxml-file-parse-error)
101 (list file pos message)))
103 (define-error 'nxml-error nil)
104 (define-error 'nxml-file-parse-error "Error parsing file" 'nxml-error)
106 (provide 'nxml-util)
108 ;;; nxml-util.el ends here