annotate lisp/psgml/psgml-edit.el @ 164:4e0740e5aab2

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