aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-03-29 22:16:38 +0000
committerStefan Monnier2002-03-29 22:16:38 +0000
commit4c0414fef484b5809552beb99a43c24a305e280c (patch)
tree27dbff1a90cae2526a346185a31513c9217cf733
parent83f1651d4f683badb8c3c6d4c825fb4e572d43e7 (diff)
downloademacs-4c0414fef484b5809552beb99a43c24a305e280c.tar.gz
emacs-4c0414fef484b5809552beb99a43c24a305e280c.zip
(xml-lite-get-context): Don't stop parsing
at unclosed tags unless it is at indentation. Kill nested unclosed tags. (xml-lite-calculate-indent, xml-lite-indent-line): Remove. (xml-lite-mode): Use sgml-indent-line instead.
-rw-r--r--lisp/textmodes/xml-lite.el90
1 files changed, 16 insertions, 74 deletions
diff --git a/lisp/textmodes/xml-lite.el b/lisp/textmodes/xml-lite.el
index 0dfe41c6b2a..ccab39365f4 100644
--- a/lisp/textmodes/xml-lite.el
+++ b/lisp/textmodes/xml-lite.el
@@ -223,7 +223,11 @@ immediately enclosing the current position."
223 (skip-chars-backward " \t\n") ; Make sure we're not at indentation. 223 (skip-chars-backward " \t\n") ; Make sure we're not at indentation.
224 (while 224 (while
225 (and (or ignore (not (if full (eq full 'empty) context)) 225 (and (or ignore (not (if full (eq full 'empty) context))
226 (not (xml-lite-at-indentation-p))) 226 (not (xml-lite-at-indentation-p))
227 (and (not sgml-xml-mode) context
228 (/= (point) (xml-lite-tag-start (car context)))
229 (member-ignore-case (xml-lite-tag-name (car context))
230 sgml-unclosed-tags)))
227 (setq tag-info (xml-lite-parse-tag-backward))) 231 (setq tag-info (xml-lite-parse-tag-backward)))
228 232
229 ;; This tag may enclose things we thought were tags. If so, 233 ;; This tag may enclose things we thought were tags. If so,
@@ -242,7 +246,16 @@ immediately enclosing the current position."
242 ;; start-tag 246 ;; start-tag
243 ((eq (xml-lite-tag-type tag-info) 'open) 247 ((eq (xml-lite-tag-type tag-info) 'open)
244 (cond 248 (cond
245 ((null ignore) (push tag-info context)) 249 ((null ignore)
250 (if (and (not sgml-xml-mode) context
251 (member-ignore-case (xml-lite-tag-name tag-info)
252 sgml-unclosed-tags)
253 (eq t (compare-strings
254 (xml-lite-tag-name tag-info) nil nil
255 (xml-lite-tag-name (car context)) nil nil t)))
256 ;; There was an implicit end-tag.
257 nil
258 (push tag-info context)))
246 ((eq t (compare-strings (xml-lite-tag-name tag-info) nil nil 259 ((eq t (compare-strings (xml-lite-tag-name tag-info) nil nil
247 (car ignore) nil nil t)) 260 (car ignore) nil nil t))
248 (setq ignore (cdr ignore))) 261 (setq ignore (cdr ignore)))
@@ -278,77 +291,6 @@ If FULL is non-nil, parse back to the beginning of the buffer."
278 291
279;; Indenting 292;; Indenting
280 293
281(defun xml-lite-calculate-indent ()
282 "Calculate the column to which this line should be indented."
283 (let* ((here (point))
284 (context (save-excursion (xml-lite-get-context)))
285 (ref-tag-info (car context))
286 (last-tag-info (car (last context))))
287
288 (save-excursion
289 (cond
290
291 ;; no context
292 ((null context) 0)
293
294 ;; inside a comment
295 ((eq 'comment (xml-lite-tag-type last-tag-info))
296 (let ((mark (looking-at "--")))
297 (goto-char (xml-lite-tag-start last-tag-info))
298 (forward-char 2)
299 (if mark (current-column)
300 (forward-char 2)
301 (+ (if (zerop (skip-chars-forward " \t")) 1 0)
302 (current-column)))))
303
304 ;; inside a tag
305 ((xml-lite-inside-tag-p last-tag-info here)
306
307 (let ((start-of-enclosing-string
308 (xml-lite-in-string-p (xml-lite-tag-start last-tag-info))))
309 (cond
310 ;; inside an attribute value
311 (start-of-enclosing-string
312 (goto-char start-of-enclosing-string)
313 (1+ (current-column)))
314 ;; if we have a tag-name, base indent on that
315 ((and (xml-lite-tag-name-end last-tag-info)
316 (progn
317 (goto-char (xml-lite-tag-name-end last-tag-info))
318 (not (looking-at "[ \t]*$"))))
319 (1+ (current-column)))
320 ;; otherwise, add indent-offset
321 (t
322 (goto-char (xml-lite-tag-start last-tag-info))
323 (+ (current-column) xml-lite-basic-offset)))))
324
325 ;; inside an element
326 (t
327 ;; indent to start of tag
328 (let ((indent-offset xml-lite-basic-offset))
329 ;; add xml-lite-basic-offset, unless we're looking at the
330 ;; matching end-tag
331 (if (and (eq (length context) 1)
332 (xml-lite-looking-at "</"))
333 (setq indent-offset 0))
334 (goto-char (xml-lite-tag-start ref-tag-info))
335 (+ (current-column) indent-offset)))
336
337 ))))
338
339(defun xml-lite-indent-line ()
340 "Indent the current line as XML."
341 (interactive)
342 (let* ((savep (point))
343 (indent-col
344 (save-excursion
345 (back-to-indentation)
346 (if (>= (point) savep) (setq savep nil))
347 (xml-lite-calculate-indent))))
348 (if savep
349 (save-excursion (indent-line-to indent-col))
350 (indent-line-to indent-col))))
351
352 294
353;; Editing shortcuts 295;; Editing shortcuts
354 296
@@ -431,7 +373,7 @@ Key bindings:
431 (set (make-local-variable 'sgml-xml-mode) t) 373 (set (make-local-variable 'sgml-xml-mode) t)
432 (set (make-local-variable 'xml-lite-orig-indent-line-function) 374 (set (make-local-variable 'xml-lite-orig-indent-line-function)
433 indent-line-function) 375 indent-line-function)
434 (set (make-local-variable 'indent-line-function) 'xml-lite-indent-line)) 376 (set (make-local-variable 'indent-line-function) 'sgml-indent-line))
435 (kill-local-variable 'sgml-xml-mode) 377 (kill-local-variable 'sgml-xml-mode)
436 (setq indent-line-function xml-lite-orig-indent-line-function))) 378 (setq indent-line-function xml-lite-orig-indent-line-function)))
437 379