annotate lisp/nxml/rng-nxml.el @ 94437:7780b9720eb9

* tramp.texi (Frequently Asked Questions): Explain, how to disable Tramp via `tramp-mode'.
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 28 Apr 2008 19:40:26 +0000
parents d88d7b016e11
children d495d4d5452f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
1 ;;; rng-nxml.el --- make nxml-mode take advantage of rng-validate-mode
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
2
87665
b9e8ab94c460 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 87347
diff changeset
3 ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
4
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
5 ;; Author: James Clark
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
6 ;; Keywords: XML, RelaxNG
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
7
86550
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
8 ;; This file is part of GNU Emacs.
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
9
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
12 ;; the Free Software Foundation; either version 3, or (at your option)
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
13 ;; any later version.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
14
86550
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
18 ;; GNU General Public License for more details.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
19
86550
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
20 ;; You should have received a copy of the GNU General Public License
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
04422668fe70 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
23 ;; Boston, MA 02110-1301, USA.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
24
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
25 ;;; Commentary:
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
26
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
27 ;;; Code:
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
28
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
29 (require 'easymenu)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
30 (require 'xmltok)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
31 (require 'nxml-util)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
32 (require 'nxml-ns)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
33 (require 'rng-match)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
34 (require 'rng-util)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
35 (require 'rng-valid)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
36 (require 'nxml-mode)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
37 (require 'rng-loc)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
38
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
39 (defcustom rng-nxml-auto-validate-flag t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
40 "*Non-nil means automatically turn on validation with nxml-mode."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
41 :type 'boolean
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
42 :group 'relax-ng)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
43
87717
f13f60e81ce8 (rng-preferred-prefix-alist): Add some defaults.
Jason Rumney <jasonr@gnu.org>
parents: 87665
diff changeset
44 (defcustom rng-preferred-prefix-alist
f13f60e81ce8 (rng-preferred-prefix-alist): Add some defaults.
Jason Rumney <jasonr@gnu.org>
parents: 87665
diff changeset
45 '(("http://www.w3.org/1999/XSL/Transform" . "xsl")
f13f60e81ce8 (rng-preferred-prefix-alist): Add some defaults.
Jason Rumney <jasonr@gnu.org>
parents: 87665
diff changeset
46 ("http://www.w3.org/1999/02/22-rdf-syntax-ns#" . "rdf")
f13f60e81ce8 (rng-preferred-prefix-alist): Add some defaults.
Jason Rumney <jasonr@gnu.org>
parents: 87665
diff changeset
47 ("http://www.w3.org/1999/xlink" . "xlink")
f13f60e81ce8 (rng-preferred-prefix-alist): Add some defaults.
Jason Rumney <jasonr@gnu.org>
parents: 87665
diff changeset
48 ("http://www.w3.org/2001/XmlSchema" . "xsd")
92468
d88d7b016e11 (rng-preferred-prefix-alist): Add dublin core namespaces.
Jason Rumney <jasonr@gnu.org>
parents: 87797
diff changeset
49 ("http://www.w3.org/2001/XMLSchema-instance" . "xsi")
d88d7b016e11 (rng-preferred-prefix-alist): Add dublin core namespaces.
Jason Rumney <jasonr@gnu.org>
parents: 87797
diff changeset
50 ("http://purl.org/dc/elements/1.1/" . "dc")
d88d7b016e11 (rng-preferred-prefix-alist): Add dublin core namespaces.
Jason Rumney <jasonr@gnu.org>
parents: 87797
diff changeset
51 ("http://purl.org/dc/terms/" . "dcterms"))
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
52 "*Alist of namespaces vs preferred prefixes."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
53 :type '(repeat (cons :tag "With"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
54 (string :tag "this namespace URI")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
55 (string :tag "use this prefix")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
56 :group 'relax-ng)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
57
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
58 (defvar rng-complete-end-tags-after-< t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
59 "*Non-nil means immediately after < complete on end-tag names.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
60 Complete on start-tag names regardless.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
61
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
62 (defvar rng-nxml-easy-menu
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
63 '("XML"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
64 ["Show Outline Only" nxml-hide-all-text-content]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
65 ["Show Everything" nxml-show-all]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
66 "---"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
67 ["Validation" rng-validate-mode
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
68 :style toggle
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
69 :selected rng-validate-mode]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
70 "---"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
71 ("Set Schema"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
72 ["Automatically" rng-auto-set-schema]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
73 ("For Document Type"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
74 :filter (lambda (menu)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
75 (mapcar (lambda (type-id)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
76 (vector type-id
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
77 (list 'rng-set-document-type
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
78 type-id)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
79 (rng-possible-type-ids))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
80 ["Any Well-Formed XML" rng-set-vacuous-schema]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
81 ["File..." rng-set-schema-file])
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
82 ["Show Schema Location" rng-what-schema]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
83 ["Save Schema Location" rng-save-schema-location :help
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
84 "Save the location of the schema currently being used for this buffer"]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
85 "---"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
86 ["First Error" rng-first-error :active rng-validate-mode]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
87 ["Next Error" rng-next-error :active rng-validate-mode]
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
88 "---"
87347
5d0236f8335b (rng-nxml-easy-menu): Remove nxml-version.
Jason Rumney <jasonr@gnu.org>
parents: 86550
diff changeset
89 ["Customize nXML" (customize-group 'nxml)]))
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
90
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
91 ;;;###autoload
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
92 (defun rng-nxml-mode-init ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
93 "Initialize `nxml-mode' to take advantage of `rng-validate-mode'.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
94 This is typically called from `nxml-mode-hook'.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
95 Validation will be enabled if `rng-nxml-auto-validate-flag' is non-nil."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
96 (interactive)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
97 (define-key nxml-mode-map "\C-c\C-v" 'rng-validate-mode)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
98 (define-key nxml-mode-map "\C-c\C-s\C-w" 'rng-what-schema)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
99 (define-key nxml-mode-map "\C-c\C-s\C-a" 'rng-auto-set-schema-and-validate)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
100 (define-key nxml-mode-map "\C-c\C-s\C-f" 'rng-set-schema-file-and-validate)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
101 (define-key nxml-mode-map "\C-c\C-s\C-l" 'rng-save-schema-location)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
102 (define-key nxml-mode-map "\C-c\C-s\C-t" 'rng-set-document-type-and-validate)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
103 (define-key nxml-mode-map "\C-c\C-n" 'rng-next-error)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
104 (easy-menu-define rng-nxml-menu nxml-mode-map
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
105 "Menu for nxml-mode used with rng-validate-mode."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
106 rng-nxml-easy-menu)
87792
c689fd3b9cfd (rng-nxml-mode-init): Don't overwrite mode-line-process.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87717
diff changeset
107 (add-to-list 'mode-line-process
87797
3305ad06c630 (rng-nxml-mode-init): Add status after the "degraded" indicator.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87792
diff changeset
108 '(rng-validate-mode (:eval (rng-compute-mode-line-string)))
3305ad06c630 (rng-nxml-mode-init): Add status after the "degraded" indicator.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87792
diff changeset
109 'append)
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
110 (cond (rng-nxml-auto-validate-flag
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
111 (rng-validate-mode 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
112 (add-hook 'nxml-completion-hook 'rng-complete nil t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
113 (add-hook 'nxml-in-mixed-content-hook 'rng-in-mixed-content-p nil t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
114 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
115 (rng-validate-mode 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
116 (remove-hook 'nxml-completion-hook 'rng-complete t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
117 (remove-hook 'nxml-in-mixed-content-hook 'rng-in-mixed-content-p t))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
118
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
119 (defvar rng-tag-history nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
120 (defvar rng-attribute-name-history nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
121 (defvar rng-attribute-value-history nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
122
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
123 (defvar rng-complete-target-names nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
124 (defvar rng-complete-name-attribute-flag nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
125 (defvar rng-complete-extra-strings nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
126
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
127 (defun rng-complete ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
128 "Complete the string before point using the current schema.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
129 Return non-nil if in a context it understands."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
130 (interactive)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
131 (and rng-validate-mode
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
132 (let ((lt-pos (save-excursion (search-backward "<" nil t)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
133 xmltok-dtd)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
134 (and lt-pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
135 (= (rng-set-state-after lt-pos) lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
136 (or (rng-complete-tag lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
137 (rng-complete-end-tag lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
138 (rng-complete-attribute-name lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
139 (rng-complete-attribute-value lt-pos))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
140
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
141 (defconst rng-in-start-tag-name-regex
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
142 (replace-regexp-in-string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
143 "w"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
144 xmltok-ncname-regexp
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
145 "<\\(?:w\\(?::w?\\)?\\)?\\="
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
146 t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
147 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
148
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
149 (defun rng-complete-tag (lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
150 (let (rng-complete-extra-strings)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
151 (when (and (= lt-pos (1- (point)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
152 rng-complete-end-tags-after-<
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
153 rng-open-elements
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
154 (not (eq (car rng-open-elements) t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
155 (or rng-collecting-text
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
156 (rng-match-save
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
157 (rng-match-end-tag))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
158 (setq rng-complete-extra-strings
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
159 (cons (concat "/"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
160 (if (caar rng-open-elements)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
161 (concat (caar rng-open-elements)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
162 ":"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
163 (cdar rng-open-elements))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
164 (cdar rng-open-elements)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
165 rng-complete-extra-strings)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
166 (when (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
167 (re-search-backward rng-in-start-tag-name-regex
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
168 lt-pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
169 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
170 (and rng-collecting-text (rng-flush-text))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
171 (let ((completion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
172 (let ((rng-complete-target-names
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
173 (rng-match-possible-start-tag-names))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
174 (rng-complete-name-attribute-flag nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
175 (rng-complete-before-point (1+ lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
176 'rng-complete-qname-function
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
177 "Tag: "
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
178 nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
179 'rng-tag-history)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
180 name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
181 (when completion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
182 (cond ((rng-qname-p completion)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
183 (setq name (rng-expand-qname completion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
184 t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
185 'rng-start-tag-expand-recover))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
186 (when (and name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
187 (rng-match-start-tag-open name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
188 (or (not (rng-match-start-tag-close))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
189 ;; need a namespace decl on the root element
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
190 (and (car name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
191 (not rng-open-elements))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
192 ;; attributes are required
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
193 (insert " ")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
194 ((member completion rng-complete-extra-strings)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
195 (insert ">")))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
196 t)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
197
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
198 (defconst rng-in-end-tag-name-regex
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
199 (replace-regexp-in-string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
200 "w"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
201 xmltok-ncname-regexp
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
202 "</\\(?:w\\(?::w?\\)?\\)?\\="
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
203 t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
204 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
205
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
206 (defun rng-complete-end-tag (lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
207 (when (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
208 (re-search-backward rng-in-end-tag-name-regex
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
209 lt-pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
210 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
211 (cond ((or (not rng-open-elements)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
212 (eq (car rng-open-elements) t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
213 (message "No matching start-tag")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
214 (ding))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
215 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
216 (let ((start-tag-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
217 (if (caar rng-open-elements)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
218 (concat (caar rng-open-elements)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
219 ":"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
220 (cdar rng-open-elements))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
221 (cdar rng-open-elements)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
222 (end-tag-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
223 (buffer-substring-no-properties (+ (match-beginning 0) 2)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
224 (point))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
225 (cond ((or (> (length end-tag-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
226 (length start-tag-name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
227 (not (string= (substring start-tag-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
228 0
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
229 (length end-tag-name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
230 end-tag-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
231 (message "Expected end-tag %s"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
232 (rng-quote-string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
233 (concat "</" start-tag-name ">")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
234 (ding))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
235 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
236 (delete-region (- (point) (length end-tag-name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
237 (point))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
238 (insert start-tag-name ">")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
239 (when (not (or rng-collecting-text
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
240 (rng-match-end-tag)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
241 (message "Element %s is incomplete"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
242 (rng-quote-string start-tag-name))))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
243 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
244
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
245 (defconst rng-in-attribute-regex
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
246 (replace-regexp-in-string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
247 "w"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
248 xmltok-ncname-regexp
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
249 "<w\\(?::w\\)?\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
250 \\(?:[ \t\r\n]+w\\(?::w\\)?[ \t\r\n]*=\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
251 [ \t\r\n]*\\(?:\"[^\"]*\"\\|'[^']*'\\)\\)*\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
252 [ \t\r\n]+\\(\\(?:w\\(?::w?\\)?\\)?\\)\\="
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
253 t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
254 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
255
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
256 (defvar rng-undeclared-prefixes nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
257
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
258 (defun rng-complete-attribute-name (lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
259 (when (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
260 (re-search-backward rng-in-attribute-regex lt-pos t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
261 (let ((attribute-start (match-beginning 1))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
262 rng-undeclared-prefixes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
263 (and (rng-adjust-state-for-attribute lt-pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
264 attribute-start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
265 (let ((rng-complete-target-names
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
266 (rng-match-possible-attribute-names))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
267 (rng-complete-extra-strings
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
268 (mapcar (lambda (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
269 (if prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
270 (concat "xmlns:" prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
271 "xmlns"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
272 rng-undeclared-prefixes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
273 (rng-complete-name-attribute-flag t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
274 (rng-complete-before-point attribute-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
275 'rng-complete-qname-function
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
276 "Attribute: "
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
277 nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
278 'rng-attribute-name-history))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
279 (insert "=\"")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
280 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
281
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
282 (defconst rng-in-attribute-value-regex
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
283 (replace-regexp-in-string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
284 "w"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
285 xmltok-ncname-regexp
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
286 "<w\\(?::w\\)?\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
287 \\(?:[ \t\r\n]+w\\(?::w\\)?[ \t\r\n]*=\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
288 [ \t\r\n]*\\(?:\"[^\"]*\"\\|'[^']*'\\)\\)*\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
289 [ \t\r\n]+\\(w\\(:w\\)?\\)[ \t\r\n]*=[ \t\r\n]*\
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
290 \\(\"[^\"]*\\|'[^']*\\)\\="
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
291 t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
292 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
293
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
294 (defun rng-complete-attribute-value (lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
295 (when (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
296 (re-search-backward rng-in-attribute-value-regex lt-pos t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
297 (let ((name-start (match-beginning 1))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
298 (name-end (match-end 1))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
299 (colon (match-beginning 2))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
300 (value-start (1+ (match-beginning 3))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
301 (and (rng-adjust-state-for-attribute lt-pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
302 name-start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
303 (if (string= (buffer-substring-no-properties name-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
304 (or colon name-end))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
305 "xmlns")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
306 (rng-complete-before-point
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
307 value-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
308 (rng-strings-to-completion-alist
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
309 (rng-possible-namespace-uris
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
310 (and colon
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
311 (buffer-substring-no-properties (1+ colon) name-end))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
312 "Namespace URI: "
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
313 nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
314 'rng-namespace-uri-history)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
315 (rng-adjust-state-for-attribute-value name-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
316 colon
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
317 name-end)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
318 (rng-complete-before-point
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
319 value-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
320 (rng-strings-to-completion-alist
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
321 (rng-match-possible-value-strings))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
322 "Value: "
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
323 nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
324 'rng-attribute-value-history))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
325 (insert (char-before value-start))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
326 t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
327
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
328 (defun rng-possible-namespace-uris (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
329 (let ((ns (if prefix (nxml-ns-get-prefix prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
330 (nxml-ns-get-default))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
331 (if (and ns (memq prefix (nxml-ns-changed-prefixes)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
332 (list (nxml-namespace-name ns))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
333 (mapcar 'nxml-namespace-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
334 (delq nxml-xml-namespace-uri
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
335 (rng-match-possible-namespace-uris))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
336
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
337 (defconst rng-qname-regexp
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
338 (concat "\\`"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
339 xmltok-ncname-regexp
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
340 "\\(?:" ":" xmltok-ncname-regexp "\\)" "?" "\\'"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
341
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
342 (defun rng-qname-p (string)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
343 (and (string-match rng-qname-regexp string) t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
344
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
345 (defun rng-expand-qname (qname &optional defaultp recover-fun)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
346 (setq qname (rng-split-qname qname))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
347 (let ((prefix (car qname)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
348 (if prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
349 (let ((ns (nxml-ns-get-prefix qname)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
350 (cond (ns (cons ns (cdr qname)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
351 (recover-fun (funcall recover-fun prefix (cdr qname)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
352 (cons (and defaultp (nxml-ns-get-default)) (cdr qname)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
353
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
354 (defun rng-start-tag-expand-recover (prefix local-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
355 (let ((ns (rng-match-infer-start-tag-namespace local-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
356 (and ns
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
357 (cons ns local-name))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
358
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
359 (defun rng-split-qname (qname)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
360 (if (string-match ":" qname)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
361 (cons (substring qname 0 (match-beginning 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
362 (substring qname (match-end 0)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
363 (cons nil qname)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
364
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
365 (defun rng-in-mixed-content-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
366 "Return non-nil if point is in mixed content.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
367 Return nil only if point is definitely not in mixed content.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
368 If unsure, return non-nil."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
369 (if (eq rng-current-schema rng-any-element)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
370 t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
371 (rng-set-state-after)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
372 (rng-match-mixed-text)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
373
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
374 (defun rng-set-state-after (&optional pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
375 "Set the state for after parsing the first token with endpoint >= POS.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
376 This does not change the xmltok state or point. However, it does
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
377 set `xmltok-dtd'. Returns the position of the end of the token."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
378 (unless pos (setq pos (point)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
379 (when (< rng-validate-up-to-date-end pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
380 (message "Parsing...")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
381 (while (and (rng-do-some-validation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
382 (< rng-validate-up-to-date-end pos))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
383 ;; Display percentage validated.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
384 (force-mode-line-update)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
385 ;; Force redisplay but don't allow idle timers to run.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
386 (let ((timer-idle-list nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
387 (sit-for 0)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
388 (message "Parsing...done"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
389 (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
390 (save-restriction
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
391 (widen)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
392 (nxml-with-invisible-motion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
393 (if (= pos 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
394 (rng-set-initial-state)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
395 (let ((state (get-text-property (1- pos) 'rng-state)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
396 (cond (state
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
397 (rng-restore-state state)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
398 (goto-char pos))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
399 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
400 (let ((start (previous-single-property-change pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
401 'rng-state)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
402 (cond (start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
403 (rng-restore-state (get-text-property (1- start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
404 'rng-state))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
405 (goto-char start))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
406 (t (rng-set-initial-state))))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
407 (xmltok-save
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
408 (if (= (point) 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
409 (xmltok-forward-prolog)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
410 (setq xmltok-dtd rng-dtd))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
411 (cond ((and (< pos (point))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
412 ;; This handles the case where the prolog ends
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
413 ;; with a < without any following name-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
414 ;; character. This will be treated by the parser
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
415 ;; as part of the prolog, but we want to treat
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
416 ;; it as the start of the instance.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
417 (eq (char-after pos) ?<)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
418 (<= (point)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
419 (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
420 (goto-char (1+ pos))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
421 (skip-chars-forward " \t\r\n")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
422 (point))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
423 pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
424 ((< (point) pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
425 (let ((rng-dt-namespace-context-getter
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
426 '(nxml-ns-get-context))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
427 (rng-parsing-for-state t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
428 (rng-forward pos))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
429 (point))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
430 (t pos)))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
431
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
432 (defun rng-adjust-state-for-attribute (lt-pos start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
433 (xmltok-save
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
434 (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
435 (goto-char lt-pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
436 (when (memq (xmltok-forward)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
437 '(start-tag
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
438 partial-start-tag
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
439 empty-element
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
440 partial-empty-element))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
441 (when (< start (point))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
442 (setq xmltok-namespace-attributes
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
443 (rng-prune-attribute-at start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
444 xmltok-namespace-attributes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
445 (setq xmltok-attributes
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
446 (rng-prune-attribute-at start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
447 xmltok-attributes)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
448 (let ((rng-parsing-for-state t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
449 (rng-dt-namespace-context-getter '(nxml-ns-get-context)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
450 (rng-process-start-tag 'stop)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
451 (rng-find-undeclared-prefixes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
452 t)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
453
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
454 (defun rng-find-undeclared-prefixes ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
455 ;; Start with the newly effective namespace declarations.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
456 ;; (Includes declarations added during recovery.)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
457 (setq rng-undeclared-prefixes (nxml-ns-changed-prefixes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
458 (let ((iter xmltok-attributes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
459 (ns-state (nxml-ns-state))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
460 att)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
461 ;; Add namespace prefixes used in this tag,
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
462 ;; but not declared in the parent.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
463 (nxml-ns-pop-state)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
464 (while iter
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
465 (setq att (car iter))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
466 (let ((prefix (xmltok-attribute-prefix att)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
467 (when (and prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
468 (not (member prefix rng-undeclared-prefixes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
469 (not (nxml-ns-get-prefix prefix)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
470 (setq rng-undeclared-prefixes
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
471 (cons prefix rng-undeclared-prefixes))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
472 (setq iter (cdr iter)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
473 (nxml-ns-set-state ns-state)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
474 ;; Remove namespace prefixes explicitly declared.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
475 (setq iter xmltok-namespace-attributes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
476 (while iter
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
477 (setq att (car iter))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
478 (setq rng-undeclared-prefixes
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
479 (delete (and (xmltok-attribute-prefix att)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
480 (xmltok-attribute-local-name att))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
481 rng-undeclared-prefixes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
482 (setq iter (cdr iter)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
483
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
484 (defun rng-prune-attribute-at (start atts)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
485 (when atts
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
486 (let ((cur atts))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
487 (while (if (eq (xmltok-attribute-name-start (car cur)) start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
488 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
489 (setq atts (delq (car cur) atts))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
490 nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
491 (setq cur (cdr cur)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
492 atts))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
493
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
494 (defun rng-adjust-state-for-attribute-value (name-start
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
495 colon
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
496 name-end)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
497 (let* ((prefix (if colon
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
498 (buffer-substring-no-properties name-start colon)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
499 nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
500 (local-name (buffer-substring-no-properties (if colon
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
501 (1+ colon)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
502 name-start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
503 name-end))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
504 (ns (and prefix (nxml-ns-get-prefix prefix))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
505 (and (or (not prefix) ns)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
506 (rng-match-attribute-name (cons ns local-name)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
507
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
508 (defun rng-complete-qname-function (string predicate flag)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
509 (let ((alist (mapcar (lambda (name) (cons name nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
510 (rng-generate-qname-list string))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
511 (cond ((not flag)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
512 (try-completion string alist predicate))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
513 ((eq flag t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
514 (all-completions string alist predicate))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
515 ((eq flag 'lambda)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
516 (and (assoc string alist) t)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
517
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
518 (defun rng-generate-qname-list (&optional string)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
519 (let ((forced-prefix (and string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
520 (string-match ":" string)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
521 (> (match-beginning 0) 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
522 (substring string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
523 0
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
524 (match-beginning 0))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
525 (namespaces (mapcar 'car rng-complete-target-names))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
526 ns-prefixes-alist ns-prefixes iter ns prefer)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
527 (while namespaces
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
528 (setq ns (car namespaces))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
529 (when ns
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
530 (setq ns-prefixes-alist
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
531 (cons (cons ns (nxml-ns-prefixes-for
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
532 ns
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
533 rng-complete-name-attribute-flag))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
534 ns-prefixes-alist)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
535 (setq namespaces (delq ns (cdr namespaces))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
536 (setq iter ns-prefixes-alist)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
537 (while iter
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
538 (setq ns-prefixes (car iter))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
539 (setq ns (car ns-prefixes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
540 (when (null (cdr ns-prefixes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
541 ;; No declared prefix for the namespace
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
542 (if forced-prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
543 ;; If namespace non-nil and prefix undeclared,
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
544 ;; use forced prefix.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
545 (when (and ns
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
546 (not (nxml-ns-get-prefix forced-prefix)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
547 (setcdr ns-prefixes (list forced-prefix)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
548 (setq prefer (rng-get-preferred-unused-prefix ns))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
549 (when prefer
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
550 (setcdr ns-prefixes (list prefer)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
551 ;; Unless it's an attribute with a non-nil namespace,
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
552 ;; allow no prefix for this namespace.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
553 (unless rng-complete-name-attribute-flag
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
554 (setcdr ns-prefixes (cons nil (cdr ns-prefixes))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
555 (setq iter (cdr iter)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
556 (rng-uniquify-equal
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
557 (sort (apply 'append
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
558 (cons rng-complete-extra-strings
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
559 (mapcar (lambda (name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
560 (if (car name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
561 (mapcar (lambda (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
562 (if prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
563 (concat prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
564 ":"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
565 (cdr name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
566 (cdr name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
567 (cdr (assoc (car name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
568 ns-prefixes-alist)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
569 (list (cdr name))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
570 rng-complete-target-names)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
571 'string<))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
572
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
573 (defun rng-get-preferred-unused-prefix (ns)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
574 (let ((ns-prefix (assoc (symbol-name ns) rng-preferred-prefix-alist))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
575 iter prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
576 (when ns-prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
577 (setq prefix (cdr ns-prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
578 (when (nxml-ns-get-prefix prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
579 ;; try to find an unused prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
580 (setq iter (memq ns-prefix rng-preferred-prefix-alist))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
581 (while (and iter
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
582 (setq ns-prefix (assoc ns iter)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
583 (if (nxml-ns-get-prefix (cdr ns-prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
584 (setq iter (memq ns-prefix iter))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
585 (setq prefix (cdr ns-prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
586 nil))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
587 prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
588
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
589 (defun rng-strings-to-completion-alist (strings)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
590 (mapcar (lambda (s) (cons s s))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
591 (rng-uniquify-equal (sort (mapcar 'rng-escape-string strings)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
592 'string<))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
593
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
594 (provide 'rng-nxml)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
595
86379
2ac1a9b70580 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 86361
diff changeset
596 ;; arch-tag: bec0d6ed-6be1-4540-9c2c-6f56e8e55d8b
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
597 ;;; rng-nxml.el ends here