annotate lisp/psgml/psgml-edit.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; psgml-edit.el --- Editing commands for SGML-mode with parsing support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; $Id: psgml-edit.el,v 1.1.1.1 1996/12/18 03:35:19 steve Exp $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1994, 1995, 1996 Lennart Staflin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Lennart Staflin <lenst@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This program is free software; you can redistribute it and/or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; modify it under the terms of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; as published by the Free Software Foundation; either version 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; of the License, or (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Part of major mode for editing the SGML document-markup language.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (provide 'psgml-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (require 'psgml)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (require 'psgml-parse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;;; Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defvar sgml-split-level nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "Used by sgml-split-element")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;; SGML mode: structure editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defun sgml-last-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 "Return the element where last command left point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 This either uses the save value in `sgml-last-element' or parses the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 to find current open element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (setq sgml-markup-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (if (and (memq last-command sgml-users-of-last-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 sgml-last-element) ; Don't return nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 sgml-last-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq sgml-last-element (sgml-find-context-of (point)))) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defun sgml-set-last-element (&optional el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if el (setq sgml-last-element el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (sgml-show-context sgml-last-element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defun sgml-beginning-of-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "Move to after the start-tag of the current element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 If the start-tag is implied, move to the start of the element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (goto-char (sgml-element-stag-end (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (sgml-set-last-element (if (sgml-element-empty sgml-last-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (sgml-element-parent sgml-last-element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun sgml-end-of-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Move to before the end-tag of the current element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (goto-char (sgml-element-etag-start (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (sgml-set-last-element (if (sgml-element-empty sgml-last-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (sgml-element-parent sgml-last-element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun sgml-backward-up-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 "Move backward out of this element level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 That is move to before the start-tag or where a start-tag is implied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (goto-char (sgml-element-start (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (sgml-set-last-element (sgml-element-parent sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (defun sgml-up-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 "Move forward out of this element level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 That is move to after the end-tag or where an end-tag is implied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (goto-char (sgml-element-end (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (sgml-set-last-element (sgml-element-parent sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun sgml-forward-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "Move forward over next element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (let ((next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (sgml-find-element-after (point) (sgml-last-element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (goto-char (sgml-element-end next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (sgml-set-last-element (sgml-element-parent next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun sgml-backward-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Move backward over previous element at this level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 With implied tags this is ambigous."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (let ((prev ; previous element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (sgml-find-previous-element (point) (sgml-last-element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (goto-char (sgml-element-start prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (sgml-set-last-element (sgml-element-parent prev))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defun sgml-down-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "Move forward and down one level in the element structure."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (let ((to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (sgml-find-element-after (point) (sgml-last-element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (goto-char (sgml-element-stag-end to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (sgml-set-last-element (if (sgml-element-empty to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (sgml-element-parent to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defun sgml-kill-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "Kill the element following the cursor."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (when sgml-markup-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (error "Point is inside markup"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (kill-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (sgml-element-end (sgml-find-element-after (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defun sgml-transpose-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "Interchange element before point with element after point, leave point after."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let ((pre (sgml-find-previous-element (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (next (sgml-find-element-after (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 s1 s2 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (goto-char (sgml-element-start next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq m2 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq s2 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (sgml-element-end next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (delete-region (point) (sgml-element-end next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (goto-char (sgml-element-start pre))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq s1 (buffer-substring (point) (sgml-element-end pre)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (delete-region (point) (sgml-element-end pre))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (insert-before-markers s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (goto-char m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (insert s1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (sgml-message "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defun sgml-mark-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "Set mark after next element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (push-mark (sgml-element-end (sgml-find-element-after (point))) nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defun sgml-mark-current-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "Set mark at end of current element, and leave point before current element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let ((el (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (goto-char (sgml-element-start el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (push-mark (sgml-element-end el) nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun sgml-change-element-name (gi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Replace the name of the current element with a new name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 Eventual attributes of the current element will be translated if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 possible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (list (let ((el (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (goto-char (sgml-element-start el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (sgml-read-element-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (format "Change %s to: " (sgml-element-name el))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (when (or (null gi) (equal gi ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (error "Illegal name"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let* ((element (sgml-find-element-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (attspec (sgml-element-attribute-specification-list element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (oldattlist (sgml-element-attlist element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (unless (sgml-element-empty element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (goto-char (sgml-element-end element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (delete-char (- (sgml-element-etag-len element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (insert (sgml-end-tag-of gi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (goto-char (sgml-element-start element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (delete-char (sgml-element-stag-len element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (insert (sgml-start-tag-of gi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let* ((newel (sgml-find-element-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (newattlist (sgml-element-attlist newel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (newasl (sgml-translate-attribute-specification-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 attspec oldattlist newattlist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (sgml-insert-attributes newasl newattlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (defun sgml-translate-attribute-specification-list (values from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 "Translate attribute specification from one element type to another.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 Input attribute values in VALUES using attlist FROM is translated into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 a list using attlist TO."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (let ((new-values nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (sgml-show-warnings t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (loop for attspec in values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 as from-decl = (sgml-lookup-attdecl (sgml-attspec-name attspec) from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 as to-decl = (sgml-lookup-attdecl (sgml-attspec-name attspec) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; Special case ID attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ((and (eq 'id (sgml-attdecl-declared-value from-decl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (setq tem (sgml-attribute-with-declared-value to 'id)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (sgml-make-attspec (sgml-attdecl-name tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (sgml-attspec-attval attspec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 new-values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; Use attribute with same name if compatible type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ((equal (sgml-attdecl-declared-value from-decl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (sgml-attdecl-declared-value to-decl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (push attspec new-values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (to-decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (sgml-log-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Attribute %s has new declared-value"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (sgml-attspec-name attspec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (push attspec new-values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (sgml-log-warning "Can't translate attribute %s = %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (sgml-attspec-name attspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (sgml-attspec-attval attspec)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 new-values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun sgml-untag-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Remove tags from current element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (let ((el (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (when (or (sgml-strict-epos-p (sgml-element-stag-epos el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (sgml-strict-epos-p (sgml-element-etag-epos el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (error "Current element has some tag inside an entity reference"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (goto-char (sgml-element-etag-start el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (delete-char (sgml-element-etag-len el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (goto-char (sgml-element-start el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (delete-char (sgml-element-stag-len el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (defun sgml-kill-markup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 "Kill next tag, markup declaration or process instruction."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq sgml-markup-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (cond ((sgml-parse-markup-declaration 'ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ((sgml-parse-processing-instruction))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ((sgml-skip-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (kill-region start (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;;; SGML mode: folding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun sgml-fold-region (beg end &optional unhide)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Hide (or if prefixarg unhide) region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 If called from a program first two arguments are start and end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 region. And optional third argument true unhides."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (interactive "r\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (let ((mp (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (inhibit-read-only t) ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (buffer-read-only nil) ; should not need this, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ; perhaps some old version of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ; emacs does not understand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ; inhibit-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (before-change-function nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (after-change-function nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (subst-char-in-region beg end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (if unhide ?\r ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (if unhide ?\n ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 'noundo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (when sgml-buggy-subst-char-in-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (set-buffer-modified-p mp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun sgml-fold-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Fold the lines comprising the current element, leaving the first line visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 This uses the selective display feature."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (cond ((and (eq sgml-current-tree sgml-top-tree) ; outside document element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 sgml-markup-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (sgml-fold-region sgml-markup-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (sgml-parse-to (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ((and (eq sgml-current-tree sgml-top-tree) ; outside document element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (looking-at " *<!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (sgml-fold-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (sgml-parse-to (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (let ((el (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (when (eq el sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (error "No element here"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (goto-char (sgml-element-end el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (when (zerop (sgml-element-etag-len el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (skip-chars-backward " \t\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (sgml-fold-region (sgml-element-start el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (defun sgml-fold-subelement ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 "Fold all elements current elements content, leaving the first lines visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 This uses the selective display feature."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (let* ((el (sgml-find-element-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (start (sgml-element-start el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (end (sgml-element-end el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (c (sgml-element-content el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (while c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (sgml-fold-region (sgml-element-start c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (sgml-element-end c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq c (sgml-element-next c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defun sgml-unfold-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 "Show hidden lines in current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let ((op (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (sgml-fold-region (point) (mark) 'unhide)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (goto-char op)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (defun sgml-unfold-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 "Show all hidden lines in current element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (let* ((element (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (sgml-fold-region (sgml-element-start element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (sgml-element-end element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 'unfold)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (defun sgml-expand-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 "As sgml-fold-subelement, but unfold first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (sgml-unfold-element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (sgml-fold-subelement))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defun sgml-unfold-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 "Show all hidden lines in buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (sgml-fold-region (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 'unfold))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;;;; SGML mode: indentation and movement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (defun sgml-indent-line (&optional col element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 "Indent line, calling parser to determine level unless COL or ELEMENT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 is given. If COL is given it should be the column to indent to. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ELEMENT is given it should be a parse tree node, from which the level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 is determined."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (when sgml-indent-step
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (let ((here (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (unless (or col element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; Determine element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (setq element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (let ((sgml-throw-on-error 'parse-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (catch sgml-throw-on-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (sgml-find-context-of (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (sgml-find-element-of (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (when (eq element sgml-top-tree) ; not in a element at all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (setq element nil) ; forget element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (goto-char here)) ; insert normal tab insted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (when element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (let ((stag (sgml-is-start-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (etag (sgml-is-end-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (when (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (not (member* (sgml-element-gi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (if (or stag etag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (sgml-element-parent element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 sgml-inhibit-indent-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 :test #'equalp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (or sgml-indent-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (not (sgml-element-data-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (if stag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (sgml-element-parent element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (setq col
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (* sgml-indent-step
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (+ (if (or stag etag) -1 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (sgml-element-level element))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (when (and col (/= col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (indent-to col))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (when (< (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 col)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (defun sgml-next-data-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 "Move forward to next point where data is allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (when (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (error "End of buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (let ((sgml-throw-on-warning 'next-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (avoid-el (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; Avoid stopping in current element, unless point is in the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ;; tag of the element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (when (< (point) (sgml-element-stag-end avoid-el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (setq avoid-el nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (catch sgml-throw-on-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (sgml-parse-to (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (setq sgml-last-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (if (not (eq ?< (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (sgml-find-element-of (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (or (eq sgml-last-element avoid-el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (not (sgml-element-data-p sgml-last-element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (sgml-set-last-element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defun sgml-next-trouble-spot ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 "Move forward to next point where something is amiss with the structure."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (sgml-note-change-at (point)) ; Prune the parse tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (sgml-parse-to (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (let ((sgml-last-trouble-spot (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (sgml-throw-on-warning 'trouble))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (or (catch sgml-throw-on-warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (sgml-parse-until-end-of nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (message "Ok"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;;;; SGML mode: information display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (defun sgml-list-valid-tags ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 "Display a list of the contextually valid tags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let ((model (sgml-element-model sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (with-output-to-temp-buffer "*Tags*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (princ (format "Current element: %s %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (sgml-element-name sgml-current-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (sgml-eltype-defined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (sgml-element-eltype sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 "[UNDEFINED]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (princ (format "Element content: %s %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (cond ((or (sgml-current-mixed-p) (eq model sgml-any))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 "mixed")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ((sgml-model-group-p model)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 "element")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 model))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (if (eq model sgml-any)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 "[ANY]" "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (cond ((sgml-final-p sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (princ "Valid end-tags : ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (loop for e in (sgml-current-list-of-endable-eltypes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 do (princ (sgml-end-tag-of e)) (princ " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (terpri))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (princ "Current element can not end here\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;;; (let ((s (sgml-tree-shortmap sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;;; (when s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;;; (princ (format "Current shortref map: %s\n" s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (princ "Valid start-tags\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (sgml-print-valid-tags "In current element:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 sgml-current-tree sgml-current-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (defun sgml-print-valid-tags (prompt tree state &optional exclude omitted-stag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (if (not (sgml-model-group-p state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (princ (format "%s (in %s)\n" prompt state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (let* ((req (sgml-required-tokens state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (elems (nconc req
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (delq sgml-pcdata-token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (sgml-optional-tokens state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (in (sgml-tree-includes tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (ex (append exclude (sgml-tree-excludes tree))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; Modify for exceptions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (while in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (unless (memq (car in) elems)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq elems (nconc elems (list (car in)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (setq in (cdr in)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (while ex
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (setq elems (delq (car ex) elems))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (setq ex (cdr ex)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (setq elems (sort elems (function string-lessp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (sgml-print-list-of-tags prompt elems)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; Check for omissable start-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (when (and req (null (cdr req)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; *** Assumes tokens are eltypes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (let ((el (sgml-fake-open-element tree (car req))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (when (sgml-element-stag-optional el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (sgml-print-valid-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (format "If omitting %s:" (sgml-start-tag-of el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (sgml-element-model el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (append exclude elems)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 'omitted-stag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;; Check for omissable end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (when (and (not omitted-stag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (sgml-final-p state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (sgml-element-etag-optional tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (sgml-print-valid-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (format "If omitting %s:" (sgml-end-tag-of tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (sgml-element-parent tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (sgml-element-pstate tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (append exclude elems))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (defun sgml-print-list-of-tags (prompt list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (when list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (princ prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (let ((col (length prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (w (1- (frame-width))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (loop for e in list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 as str = (sgml-start-tag-of e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (setq col (+ col (length str) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (cond ((>= col w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (setq col (+ (length str) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (terpri)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (princ " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (princ str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (terpri))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (defun sgml-show-context (&optional element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 "Display where the cursor is in the element hierarchy."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (let* ((el (or element (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (model (sgml-element-model el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (sgml-message "%s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ((and (null element) ; Don't trust sgml-markup-type if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ; explicit element is given as argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 sgml-markup-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ((sgml-element-mixed el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "#PCDATA")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ((not (sgml-model-group-p model))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 model)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (t ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (if (eq el sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 "in empty context"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (sgml-element-context-string el)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (defun sgml-what-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 "Display what element is under the cursor."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (let ((el (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (assert (not (null el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (message "%s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (cond ((eq el sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 "outside document element")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ((< (point) (sgml-element-stag-end el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 "start-tag")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ((>= (point) (sgml-element-etag-start el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 "end-tag")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 "content"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (sgml-element-context-string el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;;;; SGML mode: keyboard inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defun sgml-insert-tag (tag &optional silent no-nl-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 "Insert a tag, reading tag name in minibuffer with completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 If the variable sgml-balanced-tag-edit is t, also inserts the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 corresponding end tag. If sgml-leave-point-after-insert is t, the point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 is left after the inserted tag(s), unless the element has som required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 content. If sgml-leave-point-after-insert is nil the point is left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 after the first tag inserted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (completing-read "Tag: " (sgml-completion-table) nil t "<" )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (sgml-find-context-of (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (assert (null sgml-markup-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ;; Fix white-space before tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (unless (sgml-element-data-p (sgml-parse-to-here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (cond ((bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (if (looking-at "^\\s-*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (fixup-whitespace)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (insert "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (insert tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (sgml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (unless no-nl-after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (unless (sgml-element-data-p (sgml-parse-to-here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (unless (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (save-excursion (insert "\n"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (or silent (sgml-show-context)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (defvar sgml-new-attribute-list-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (function sgml-default-asl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (defun sgml-insert-element (name &optional after silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 "Reads element name from minibuffer and inserts start and end tags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (interactive (list (sgml-read-element-name "Element: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 sgml-leave-point-after-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (let (newpos ; position to leave cursor at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 element ; inserted element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (sgml-show-warnings nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (when (and name (not (equal name "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (sgml-insert-tag (sgml-start-tag-of name) 'silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (setq element (sgml-find-element-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (sgml-insert-attributes (funcall sgml-new-attribute-list-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (sgml-element-attlist element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (when (not (sgml-element-empty element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (when (and sgml-auto-insert-required-elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (sgml-model-group-p sgml-current-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (let (tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (while (and (setq tem (sgml-required-tokens sgml-current-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (null (cdr tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (setq tem (sgml-insert-element (car tem) t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (setq newpos (or newpos tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (sgml-parse-to-here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (when tem ; more than one req elem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (when sgml-insert-missing-element-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (insert (format "<!-- one of %s -->" tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (sgml-indent-line nil element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (setq newpos (or newpos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (when sgml-insert-end-tag-on-new-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (sgml-insert-tag (sgml-end-tag-of name) 'silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (unless after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (goto-char newpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (unless silent (sgml-show-context)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 newpos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (defun sgml-default-asl (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (loop for attdecl in (sgml-element-attlist element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 when (sgml-default-value-type-p (sgml-attdecl-default-value attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 'required)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (sgml-make-attspec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (sgml-attdecl-name attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (sgml-read-attribute-value attdecl nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (defun sgml-tag-region (element start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 "Reads element name from minibuffer and inserts start and end tags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (save-excursion (goto-char (region-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (sgml-read-element-name "Tag region with element: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (when (and element (not (equal element "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (insert (sgml-end-tag-of element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (sgml-insert-tag (sgml-start-tag-of element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (defun sgml-insert-attributes (avl attlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 "Insert the attributes with values AVL and declarations ATTLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 AVL should be a assoc list mapping symbols to strings."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (let (name val dcl def tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (loop for attspec in attlist do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (setq name (sgml-attspec-name attspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 val (cdr-safe (sgml-lookup-attspec name avl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 dcl (sgml-attdecl-declared-value attspec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 def (sgml-attdecl-default-value attspec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (unless val ; no value given
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 ;; Supply the default value if a value is needed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (cond ((sgml-default-value-type-p 'required def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (setq val ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ((and (not (or sgml-omittag sgml-shorttag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (consp def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (setq val (sgml-default-value-attval def)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ((null val)) ; Ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; Ignore attributes with default value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ((and (consp def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (eq sgml-minimize-attributes 'max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (or sgml-omittag sgml-shorttag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (equal val (sgml-default-value-attval def))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;; No attribute name for token groups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 ((and sgml-minimize-attributes sgml-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (member (sgml-general-case val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (sgml-declared-value-token-group dcl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (insert " " val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (insert " " name "=" (sgml-quote-attribute-value val)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (when auto-fill-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (funcall auto-fill-function))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (defun sgml-quote-attribute-value (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 "Add quotes to the string VALUE unless minimization is on."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (let ((quote ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (cond ((and (not sgml-always-quote-attributes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 sgml-shorttag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (string-match "\\`[.A-Za-z0-9---]+\\'" value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 ) ; no need to quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ((not (string-match "\"" value)) ; can use "" quotes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (setq quote "\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (t ; use '' quotes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq quote "'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (concat quote value quote)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (defun sgml-completion-table (&optional avoid-tags-in-cdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (when sgml-markup-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (error "No tags allowed"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (cond ((or (sgml-model-group-p sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (eq sgml-current-state sgml-any))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (mapcar (function (lambda (x) (cons (sgml-end-tag-of x) x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (sgml-current-list-of-endable-eltypes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (mapcar (function (lambda (x) (cons (sgml-start-tag-of x) x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (sgml-current-list-of-valid-eltypes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (sgml-message "%s" sgml-current-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (defun sgml-insert-end-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 "Insert end-tag for the current open element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ((eq sgml-current-tree sgml-top-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (sgml-error "No open element"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ((not (sgml-final-p sgml-current-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (sgml-error "Can`t end element here"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (when (and sgml-indent-step
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (not (sgml-element-data-p sgml-current-tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (unless (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (insert "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (when (prog1 (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (insert (if (eq t (sgml-element-net-enabled sgml-current-tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 "/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; wing change: If there is more than one endable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;; tag, we probably want the outermost one rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;; than the innermost one. Thus, we end a </ul>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; even when a </li> is possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (sgml-end-tag-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (car (last (sgml-current-list-of-endable-eltypes)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (sgml-indent-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (defun sgml-insert-start-tag (name asl attlist &optional net)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (insert "<" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (sgml-insert-attributes asl attlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (insert (if net "/" ">")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (defun sgml-change-start-tag (element asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (let ((name (sgml-element-gi element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (attlist (sgml-element-attlist element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (assert (sgml-bpos-p (sgml-element-stag-epos element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (goto-char (sgml-element-start element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (delete-char (sgml-element-stag-len element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (sgml-insert-start-tag name asl attlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (eq t (sgml-element-net-enabled element)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (defun sgml-read-attribute-value (attdecl curvalue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 "Return the attribute value read from user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 ATTDECL is the attribute declaration for the attribute to read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 CURVALUE is nil or a string that will be used as default value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (assert attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (let* ((name (sgml-attdecl-name attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (dv (sgml-attdecl-declared-value attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (tokens (sgml-declared-value-token-group dv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (notations (sgml-declared-value-notation dv))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (type (cond (tokens "token")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (notations "notation")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (t (symbol-name dv))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (format "Value for %s (%s%s): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 name type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (if curvalue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (format " Default: %s" curvalue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (setq value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (if (or tokens notations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (completing-read prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (mapcar 'list (or tokens notations))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (read-string prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (if (and curvalue (equal value ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 curvalue value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (defun sgml-non-fixed-attributes (attlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (loop for attdecl in attlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 unless (sgml-default-value-type-p 'fixed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (sgml-attdecl-default-value attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 collect attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (defun sgml-insert-attribute (name value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 "Read attribute name and value from minibuffer and insert attribute spec."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (let* ((el (sgml-find-attribute-element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 "Attribute name: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (mapcar (function (lambda (a) (list (sgml-attdecl-name a))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (sgml-non-fixed-attributes (sgml-element-attlist el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (list name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (sgml-read-attribute-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (sgml-lookup-attdecl name (sgml-element-attlist el))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (sgml-element-attval el name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ;; Body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (assert (stringp name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (assert (or (null value) (stringp value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (let* ((el (sgml-find-attribute-element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (asl (cons (sgml-make-attspec name value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (sgml-element-attribute-specification-list el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (in-tag (< (point) (sgml-element-stag-end el))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (sgml-change-start-tag el asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (when in-tag (forward-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (defun sgml-split-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 "Split the current element at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 If repeated, the containing element will be split before the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 of then current element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (setq sgml-split-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (if (eq this-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (1+ sgml-split-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (let ((u (sgml-find-context-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (start (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (loop repeat sgml-split-level do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (goto-char (sgml-element-start u))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (setq u (sgml-element-parent u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;; Verify that a new element can be started
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (unless (and (sgml-element-pstate u) ; in case of top element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (sgml-get-move (sgml-element-pstate u)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (sgml-element-name u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (sgml-error "The %s element can't be split"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (sgml-element-name u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;; Do the split
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (sgml-insert-end-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (sgml-insert-tag (sgml-start-tag-of u) 'silent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (sgml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (when (> sgml-split-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (goto-char start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (or (eq sgml-top-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (setq u (sgml-element-parent u)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (sgml-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 "Repeat the command to split the containing %s element"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (sgml-element-name u)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ;;; David Megginson's custom menus for keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (defun sgml-custom-dtd (doctype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 "Insert a DTD declaration from the sgml-custom-dtd alist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (list (completing-read "Insert DTD: " sgml-custom-dtd nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (let ((entry (assoc doctype sgml-custom-dtd)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (sgml-doctype-insert (second entry) (cddr entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (defun sgml-custom-markup (markup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 "Insert markup from the sgml-custom-markup alist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (list (completing-read "Insert Markup: " sgml-custom-markup nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (sgml-insert-markup (cadr (assoc markup sgml-custom-markup))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;;;; SGML mode: Menu inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (defun sgml-tags-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 "Pop up a menu with valid tags and insert the choosen tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 If the variable sgml-balanced-tag-edit is t, also inserts the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 corresponding end tag. If sgml-leave-point-after-insert is t, the point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 is left after the inserted tag(s), unless the element has som required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 content. If sgml-leave-point-after-insert is nil the point is left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 after the first tag inserted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (interactive "*e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (let ((end (sgml-mouse-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ((eq sgml-markup-type 'start-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (sgml-attrib-menu event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (let ((what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (sgml-menu-ask event (if (or end sgml-balanced-tag-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 'element 'tags))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ((null what))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (sgml-tag-region what (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (sgml-balanced-tag-edit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (sgml-insert-element what))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (sgml-insert-tag what))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (defun sgml-element-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 "Pop up a menu with valid elements and insert choice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 If sgml-leave-point-after-insert is nil the point is left after the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 tag inserted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (interactive "*e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (let ((what (sgml-menu-ask event 'element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (and what (sgml-insert-element what))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (defun sgml-start-tag-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 "Pop up a menu with valid start-tags and insert choice."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (interactive "*e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (let ((what (sgml-menu-ask event 'start-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (and what (sgml-insert-tag what))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun sgml-end-tag-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 "Pop up a menu with valid end-tags and insert choice."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (interactive "*e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (let ((what (sgml-menu-ask event 'end-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (and what (sgml-insert-tag what))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (defun sgml-tag-region-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 "Pop up a menu with valid elements and tag current region with the choice."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (interactive "*e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (let ((what (sgml-menu-ask event 'element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (and what (sgml-tag-region what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (region-beginning)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (region-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (defun sgml-menu-ask (event type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (let (tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (title (capitalize (symbol-name type))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (sgml-markup-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ((eq type 'element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (setq tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (mapcar (function symbol-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (sgml-current-list-of-valid-eltypes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (unless (eq type 'start-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (setq tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (mapcar (function sgml-end-tag-of)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (sgml-current-list-of-endable-eltypes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (unless (eq type 'end-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (setq tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (nconc tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (mapcar (function sgml-start-tag-of)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (sgml-current-list-of-valid-eltypes)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (or tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (error "No valid %s at this point" type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (sgml-popup-menu event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 title
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (mapcar (function (lambda (x) (cons x x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 tab))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (message nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (defun sgml-entities-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (interactive "*e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (sgml-need-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (let ((menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (mapcar (function (lambda (x) (cons x x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (sort (sgml-map-entities (function sgml-entity-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (sgml-dtd-entities sgml-dtd-info)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (function string-lessp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (unless menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (error "No entities defined"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (setq choice (sgml-popup-menu event "Entities" menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (when choice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (insert "&" choice ";"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (defun sgml-doctype-insert (doctype vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 "Insert string DOCTYPE (ignored if nil) and set variables in &rest VARS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 VARS should be a list of variables and values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 For backward compatibility a singel string instead of a variable is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 assigned to sgml-default-dtd-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 All variables are made buffer local and are also added to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 buffers local variables list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (when doctype
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (unless (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (unless (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (sgml-insert-markup doctype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (while vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (cond ((stringp (car vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (sgml-set-local-variable 'sgml-default-dtd-file (car vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (setq vars (cdr vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ((car vars) ; Avoid nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (sgml-set-local-variable (car vars) (cadr vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (setq vars (cddr vars)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (setq sgml-top-tree nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (defun sgml-attrib-menu (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 "Pop up a menu of the attributes of the current element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 \(or the element whith start-tag before point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (let* ((el (sgml-find-attribute-element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (attlist (sgml-non-fixed-attributes (sgml-element-attlist el)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 tokens menu other)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (or attlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (error "No non-fixed attributes for element"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (setq menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (loop for attdecl in attlist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 for name = (sgml-attdecl-name attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 for defval = (sgml-attdecl-default-value attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 for tokens = (or (sgml-declared-value-token-group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (sgml-attdecl-declared-value attdecl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (sgml-declared-value-notation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (sgml-attdecl-declared-value attdecl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (sgml-attdecl-name attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (if tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (loop for val in tokens collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (list val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (list 'sgml-insert-attribute name val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (list "Set attribute value"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (list 'sgml-insert-attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (sgml-attdecl-name attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (list 'sgml-read-attribute-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (list 'quote attdecl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (sgml-element-attval el name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (if (sgml-default-value-type-p 'required defval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (list "--"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (list (if (sgml-default-value-type-p nil defval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (format "Default: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (sgml-default-value-attval defval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 "#IMPLIED")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (list 'sgml-insert-attribute name nil))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (sgml-popup-multi-menu event "Attributes" menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;;;; SGML mode: Fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (defun sgml-fill-element (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 "Fill bigest enclosing element with mixed content.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 If current element has pure element content, recursively fill the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 subelements."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (interactive (list (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (message "Filling...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (when (sgml-element-mixed element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 ;; Find bigest enclosing element with mixed content
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (while (sgml-element-mixed (sgml-element-parent element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (setq element (sgml-element-parent element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (sgml-do-fill element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (sgml-message "Done"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (defun sgml-do-fill (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (when sgml-debug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (goto-char (sgml-element-start element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (sit-for 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ((sgml-element-mixed element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (let (last-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (c (sgml-element-content element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (agenda nil)) ; regions to fill later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (goto-char (sgml-element-stag-end element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (when (eolp) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (setq last-pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (while c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 ((sgml-element-mixed c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 ;; Put region before element on agenda. Can't fill it now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 ;; that would mangel the parse tree that is beeing traversed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (push (cons last-pos (sgml-element-start c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 agenda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (goto-char (sgml-element-start c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (sgml-do-fill c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;; Fill may change parse tree, get a fresh
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (setq c (sgml-find-element-of (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (setq last-pos (sgml-element-end c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (setq c (sgml-element-next c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 ;; Fill the last region in content of element,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;; but get a fresh parse tree, if it has change due to other fills.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (sgml-fill-region last-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (sgml-element-etag-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (sgml-find-element-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (sgml-element-start element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (while agenda
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (sgml-fill-region (caar agenda) (cdar agenda))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (setq agenda (cdr agenda)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;; If element is not mixed, fill subelements recursively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (let ((c (sgml-element-content element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (while c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (goto-char (sgml-element-start c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (sgml-do-fill c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (setq c (sgml-element-next (sgml-find-element-of (point))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (defun sgml-fill-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (sgml-message "Filling...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (while (progn (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (< start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (insert " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (let (give-up prev-column opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (while (and (not give-up) (> (current-column) fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (setq prev-column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (move-to-column (1+ fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (skip-chars-backward "^ \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (re-search-forward "[ \t]" opoint t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (setq give-up t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (delete-region (point) opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (sgml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (setq give-up (>= (current-column) prev-column)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 ;;;; SGML mode: Attribute editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (defvar sgml-start-attributes nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (defvar sgml-main-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (defvar sgml-attlist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (defun sgml-edit-attributes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 "Edit attributes of current element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 Editing is done in a separate window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (let ((element (sgml-find-attribute-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (unless (sgml-bpos-p (sgml-element-stag-epos element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (error "Element's start-tag is not in the buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (goto-char (sgml-element-start element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (let* ((start (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (asl (sgml-element-attribute-specification-list element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (cb (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (quote sgml-always-quote-attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (switch-to-buffer-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (sgml-attribute-buffer element asl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (sgml-edit-attrib-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (make-local-variable 'sgml-attlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (setq sgml-attlist (sgml-element-attlist element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (make-local-variable 'sgml-start-attributes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (setq sgml-start-attributes start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (make-local-variable 'sgml-always-quote-attributes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (setq sgml-always-quote-attributes quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (make-local-variable 'sgml-main-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (setq sgml-main-buffer cb))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (defun sgml-attribute-buffer (element asl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (let ((bname "*Edit attributes*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (buf nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (when (setq buf (get-buffer bname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (setq buf (get-buffer-create bname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (sgml-insert '(read-only t rear-nonsticky (read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 "<%s -- Edit values and finish with C-c C-c --\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (sgml-element-name element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 for attr in (sgml-element-attlist element) do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ;; Produce text like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;; name = value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; -- declaration : default --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (let* ((aname (sgml-attdecl-name attr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (dcl-value (sgml-attdecl-declared-value attr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (def-value (sgml-attdecl-default-value attr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (cur-value (sgml-lookup-attspec aname asl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (sgml-insert ; atribute name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 '(read-only t rear-nonsticky (read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 " %s = " aname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (cond ; attribute value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 ((sgml-default-value-type-p 'fixed def-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (sgml-insert '(read-only t category sgml-fixed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 rear-nonsticky (category))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 "#FIXED %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (sgml-default-value-attval def-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 ((and (null cur-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (or (memq def-value '(implied conref current))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (sgml-default-value-attval def-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (sgml-insert '(category sgml-default rear-nonsticky (category))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 "#DEFAULT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 ((not (null cur-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (sgml-insert nil "%s" (sgml-attspec-attval cur-value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (sgml-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 '(read-only 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 "\n\t-- %s: %s --\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (cond ((sgml-declared-value-token-group dcl-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ((sgml-declared-value-notation dcl-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (format "NOTATION %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (sgml-declared-value-notation dcl-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 dcl-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (cond ((sgml-default-value-attval def-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (concat "#" (upcase (symbol-name def-value))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (sgml-insert '(read-only t) ">")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (sgml-edit-attrib-next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (defvar sgml-edit-attrib-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (define-key sgml-edit-attrib-mode-map "\C-c\C-c" 'sgml-edit-attrib-finish)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (define-key sgml-edit-attrib-mode-map "\C-c\C-d" 'sgml-edit-attrib-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (define-key sgml-edit-attrib-mode-map "\C-c\C-k" 'sgml-edit-attrib-clear)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (define-key sgml-edit-attrib-mode-map "\C-a" 'sgml-edit-attrib-field-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (define-key sgml-edit-attrib-mode-map "\C-e" 'sgml-edit-attrib-field-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (define-key sgml-edit-attrib-mode-map "\t" 'sgml-edit-attrib-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (defun sgml-edit-attrib-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 "Major mode to edit attribute specification list.\\<sgml-edit-attrib-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 Use \\[sgml-edit-attrib-next] to move between input fields. Use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 \\[sgml-edit-attrib-default] to make an attribute have its default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 value. To abort edit kill buffer (\\[kill-buffer]) and remove window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (\\[delete-window]). To finsh edit use \\[sgml-edit-attrib-finish].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 \\{sgml-edit-attrib-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (setq mode-name "SGML edit attributes"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 major-mode 'sgml-edit-attrib-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (use-local-map sgml-edit-attrib-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (run-hooks 'text-mode-hook 'sgml-edit-attrib-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (defun sgml-edit-attrib-finish ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 "Finish editing and insert attribute values in original buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (let ((cb (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (asl (sgml-edit-attrib-specification-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 ;; save buffer local variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (start sgml-start-attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (when (markerp start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (delete-windows-on cb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (switch-to-buffer (marker-buffer start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (kill-buffer cb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (let ((element (sgml-find-element-of start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 ;; *** Should the it be verified that this element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 ;; is the one edited?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (sgml-change-start-tag element asl)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (defun sgml-edit-attrib-specification-list ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (let ((asl nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (al sgml-attlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (while (not (eq ?> (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (sgml-parse-s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (let ((name (sgml-check-nametoken)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (forward-char 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (unless (memq (get-text-property (point) 'category)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 '(sgml-default sgml-fixed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (sgml-make-attspec (sgml-attdecl-name (car al))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (sgml-extract-attribute-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (sgml-attdecl-declared-value (car al))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 asl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (while (progn (beginning-of-line 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (or (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (not (get-text-property (point) 'read-only))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 ; was (eq t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (setq al (cdr al)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 asl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (defun sgml-extract-attribute-value (type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (progn (sgml-edit-attrib-field-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (unless (eq type 'cdata)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (subst-char-in-region (point-min) (point-max) ?\n ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (delete-horizontal-space))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (when (search-forward "\"" nil t) ; don't allow both " and '
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (while (search-forward "'" nil t) ; replace ' with char ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (replace-match "&#39;")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (buffer-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (defun sgml-edit-attrib-default ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 "Set current attribute value to default."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (sgml-edit-attrib-clear)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (sgml-insert '(category sgml-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 "#DEFAULT")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (defun sgml-edit-attrib-clear ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 "Kill the value of current attribute."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (kill-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (progn (sgml-edit-attrib-field-start) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (progn (sgml-edit-attrib-field-end) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (defun sgml-edit-attrib-field-start ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 "Go to the start of the attribute value field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (let (start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (while (not (eq t (get-text-property (point) 'read-only)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (beginning-of-line 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (setq start (next-single-property-change (point) 'read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (unless start (error "No attribute value here"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (assert (number-or-marker-p start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (goto-char start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (defun sgml-edit-attrib-field-end ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 "Go to the end of the attribute value field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (sgml-edit-attrib-field-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (let ((end (if (and (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (get-text-property (1+ (point)) 'read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (next-single-property-change (point) 'read-only))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (assert (number-or-marker-p end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (goto-char end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (defun sgml-edit-attrib-next ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 "Move to next attribute value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (or (search-forward-regexp "^ *[.A-Za-z0-9---]+ *= ?" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (goto-char (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 ;;;; SGML mode: Hiding tags/attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (defconst sgml-tag-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 "\\(</?>\\|</?[A-Za-z][---A-Za-z0-9.]*\\(\\([^'\"></]\\|'[^']*'\\|\"[^\"]*\"\\)*\\)>?\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (defun sgml-operate-on-tags (action &optional attr-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (let ((buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (before-change-function nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (markup-index ; match-data index in tag regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (if attr-p 2 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (tagcount ; number tags to give them uniq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 ; invisible properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (while (re-search-forward sgml-tag-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ((eq action 'hide)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (let ((tag (downcase
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (buffer-substring (1+ (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (match-beginning 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (if (or attr-p (not (member tag sgml-exposed-tags)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (add-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (match-beginning markup-index) (match-end markup-index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (list 'invisible tagcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 'rear-nonsticky '(invisible face))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 ((eq action 'show) ; ignore markup-index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (remove-text-properties (match-beginning 0) (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 '(invisible nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (t (error "Invalid action: %s" action)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (incf tagcount)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (set-buffer-modified-p buffer-modified-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (defun sgml-hide-tags ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 "Hide all tags in buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (sgml-operate-on-tags 'hide))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (defun sgml-show-tags ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 "Show hidden tags in buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (sgml-operate-on-tags 'show))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (defun sgml-hide-attributes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 "Hide all attribute specifications in the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (sgml-operate-on-tags 'hide 'attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (defun sgml-show-attributes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 "Show all attribute specifications in the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (sgml-operate-on-tags 'show 'attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ;;;; SGML mode: Normalize (and misc manipulations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (defun sgml-expand-shortref-to-text (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (let (before-change-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (entity (sgml-lookup-entity name (sgml-dtd-entities sgml-dtd-info))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 ((null entity) (sgml-error "Undefined entity %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 ((sgml-entity-data-p entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (sgml-expand-shortref-to-entity name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (delete-region sgml-markup-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (sgml-entity-insert-text entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (setq sgml-goal (point-max)) ; May have changed size of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 ;; now parse the entity text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (goto-char (setq sgml-rs-ignore-pos sgml-markup-start))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (defun sgml-expand-shortref-to-entity (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (let ((end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (re-found nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 before-change-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (goto-char sgml-markup-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (setq re-found (search-forward "\n" end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (delete-region sgml-markup-start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (insert "&" name (if re-found "\n" ";"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (setq sgml-goal (point-max)) ; May have changed size of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (goto-char (setq sgml-rs-ignore-pos sgml-markup-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (defun sgml-expand-all-shortrefs (to-entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 "Expand all short references in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 Short references to text entities are expanded to the replacement text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 of the entity other short references are expanded into general entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 references. If argument, TO-ENTITY, is non-nil, or if called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 interactive with numeric prefix argument, all short references are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 replaced by generaly entity references."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (sgml-reparse-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (if to-entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (function sgml-expand-shortref-to-entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (function sgml-expand-shortref-to-text))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (defun sgml-normalize (to-entity &optional element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 "Normalize buffer by filling in omitted tags and expanding empty tags.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 Argument TO-ENTITY controls how short references are expanded as with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 `sgml-expand-all-shortrefs'. An optional argument ELEMENT can be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 element to normalize insted of the whole buffer, if used no short
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 references will be expanded."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (unless element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (sgml-expand-all-shortrefs to-entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (let ((only-one (not (null element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (setq element (or element (sgml-top-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (goto-char (sgml-element-end element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (let ((before-change-function nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (sgml-normalize-content element only-one)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (sgml-note-change-at (sgml-element-start element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (sgml-message "Done"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (defun sgml-normalize-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (sgml-normalize nil (sgml-find-element-of (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (defun sgml-normalize-content (element only-first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 "Normalize all elements in a content where ELEMENT is first element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 If sgml-normalize-trims is non-nil, trim off white space from ends of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 elements with omitted end-tags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (let ((content nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (while element ; Build list of content elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (push element content)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (setq element (if only-first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (sgml-element-next element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (while content
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (setq element (car content))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 ;; Progress report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (sgml-lazy-message "Normalizing %d%% left"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (/ (point) (/ (+ (point-max) 100) 100)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 ;; Fix the end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (sgml-normalize-end-tag element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 ;; Fix tags of content
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (sgml-normalize-content (sgml-tree-content element) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 ;; Fix the start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (sgml-normalize-start-tag element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 ;; Next content element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (setq content (cdr content)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (defun sgml-normalize-start-tag (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (when (sgml-bpos-p (sgml-element-stag-epos element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (goto-char (min (point) (sgml-element-start element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (let ((name (sgml-element-gi element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (attlist (sgml-element-attlist element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (asl (sgml-element-attribute-specification-list element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (assert (or (zerop (sgml-element-stag-len element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (= (point) (sgml-element-start element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (delete-char (sgml-element-stag-len element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (sgml-insert-start-tag name asl attlist nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (defun sgml-normalize-end-tag (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 (unless (sgml-element-empty element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (when (sgml-bpos-p (sgml-element-etag-epos element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (goto-char (min (point) (sgml-element-etag-start element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (if (and (zerop (sgml-element-etag-len element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 sgml-normalize-trims)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (skip-chars-backward " \t\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (delete-char (sgml-tree-etag-len element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (save-excursion (insert (sgml-end-tag-of element))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (defun sgml-make-character-reference (&optional invert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 "Convert character after point into a character reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 If called with a numeric argument, convert a character reference back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 to a normal character. If called from a program, set optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 argument INVERT to non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (invert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (or (looking-at "&#\\([0-9]+\\)[;\n]?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (error "No character reference after point"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (let ((c (string-to-int (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (delete-region (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (insert c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 ;; Convert character to &#nn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (let ((c (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (insert (format "&#%d;" c))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (defun sgml-expand-entity-reference ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 "Insert the text of the entity referenced at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (setq sgml-markup-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (sgml-check-delim "ERO")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (let* ((ename (sgml-check-name t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (entity (sgml-lookup-entity ename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (sgml-dtd-entities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (sgml-pstate-dtd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 sgml-buffer-parse-state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (unless entity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (error "Undefined entity %s" ename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (or (sgml-parse-delim "REFC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (sgml-parse-RE))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (delete-region sgml-markup-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (sgml-entity-insert-text entity))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 ;;;; SGML mode: TAB completion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (defun sgml-complete ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 "Complete the word/tag/entity before point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 If it is a tag (starts with < or </) complete with valid tags.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 If it is an entity (starts with &) complete with declared entities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 If it is a markup declaration (starts with <!) complete with markup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 declaration names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 If it is something else complete with ispell-complete-word."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (let ((tab ; The completion table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (pattern nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (c nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (skip-chars-backward "^ \n\t</!&%")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (setq pattern (buffer-substring (point) here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (setq c (char-after (1- (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 ;; entitiy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 ((eq c ?&)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (sgml-need-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (setq tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (sgml-entity-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (sgml-dtd-entities (sgml-pstate-dtd sgml-buffer-parse-state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ;; start-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 ((eq c ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (setq tab (sgml-eltype-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (sgml-current-list-of-valid-eltypes)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 ;; end-tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 ((eq c ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (backward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (sgml-parse-to-here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (setq tab (sgml-eltype-completion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (sgml-current-list-of-endable-eltypes)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 ;; markup declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 ((eq c ?!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (setq tab sgml-markup-declaration-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (ispell-complete-word)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (when tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (let ((completion (try-completion pattern tab)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (cond ((null completion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (message "Can't find completion for \"%s\"" pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 ((eq completion t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (message "[Complete]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ((not (string= pattern completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (delete-char (length pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (insert completion))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (message "Making completion list...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (let ((list (all-completions pattern tab)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (with-output-to-temp-buffer " *Completions*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (display-completion-list list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (message "Making completion list...%s" "done")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 ;;;; SGML mode: Options menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (defun sgml-file-options-menu (&optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (sgml-options-menu event sgml-file-options))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (defun sgml-user-options-menu (&optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (sgml-options-menu event sgml-user-options))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (defun sgml-options-menu (event vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (let ((var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (let ((maxlen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (loop for var in vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 maximize (length (sgml-variable-description var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (sgml-popup-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 event "Options"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (loop for var in vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 for desc = (sgml-variable-description var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (format "%s%s [%s]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 desc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (make-string (- maxlen (length desc)) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (sgml-option-value-indicator var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 var))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (when var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (sgml-do-set-option var event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (defun sgml-do-set-option (var &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (let ((type (sgml-variable-type var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (val (symbol-value var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 ((eq 'toggle type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (message "%s set to %s" var (not val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (set var (not val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 ((eq 'string type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (describe-variable var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (setq val (read-string (concat (sgml-variable-description var) ": ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (when (stringp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (set var val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ((consp type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (let ((val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 (sgml-popup-menu event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (sgml-variable-description var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (loop for c in type collect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (if (consp c) (car c) (format "%s" c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (if (consp c) (cdr c) c))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (set var val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (message "%s set to %s" var val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (describe-variable var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (setq val (read-string (concat (sgml-variable-description var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 " (sexp): ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (when (stringp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (set var (car (read-from-string val)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (force-mode-line-update))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (defun sgml-option-value-indicator (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (let ((type (sgml-variable-type var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (val (symbol-value var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ((eq type 'toggle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (if val "Yes" "No"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 ((eq type 'string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (if (stringp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (substring val 0 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 "-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 ((and (atom type) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 "...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 ((consp type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (or (car (rassq val type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 "-"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 ;;;; NEW
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (defun sgml-trim-and-leave-element ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 (goto-char (sgml-element-etag-start (sgml-last-element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (while (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (looking-at "\\s-"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (sgml-up-element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 ;;; psgml-edit.el ends here