# HG changeset patch # User Stefan Monnier # Date 1017267945 0 # Node ID 65437de0940fcc6da5508ff3716abb71d0482b81 # Parent 9ea4e6199d1c6a688d0245790c271dee102dac55 Fix copyright notice. (xml-lite-basic-offset): Rename from xml-lite-indent-offset. (xml-lite-indent-comment-offset): Remove. (xml-lite-calculate-indent): Use new name. Use natural alignment for comments. diff -r 9ea4e6199d1c -r 65437de0940f lisp/textmodes/xml-lite.el --- a/lisp/textmodes/xml-lite.el Wed Mar 27 22:19:40 2002 +0000 +++ b/lisp/textmodes/xml-lite.el Wed Mar 27 22:25:45 2002 +0000 @@ -1,10 +1,9 @@ ;;; xml-lite.el --- an indentation-engine for XML -;; Copyright (C) 2001 Mike Williams +;; Copyright (C) 2002 Free Software Foundation, Inc. ;; Author: Mike Williams ;; Created: February 2001 -;; Version: $Revision: 1.2 $ ;; Keywords: xml ;; This file is part of GNU Emacs. @@ -32,11 +31,6 @@ ;; ;; xml-lite is designed to be used in conjunction with the default GNU ;; Emacs sgml-mode, to provide a lightweight XML-editing environment. -;; -;; Updates will be made available at: -;; http://www.bigfoot.com/~mdub/software/xml-lite.el -;; -;; Note: the font-lock support that was in this package has been removed. ;;; Thanks: ;; @@ -56,14 +50,8 @@ :group 'languages ) -(defcustom xml-lite-indent-offset 4 - "*Specifies the default indentation level for `xml-lite-indent-line'." - :type 'integer - :group 'xml-lite - ) - -(defcustom xml-lite-indent-comment-offset 5 - "*Specifies the indentation level for XML comments." +(defcustom xml-lite-basic-offset 2 + "*Specifies the basic indentation level for `xml-lite-indent-line'." :type 'integer :group 'xml-lite ) @@ -119,11 +107,9 @@ ;; Parsing - (defstruct (xml-lite-tag (:constructor xml-lite-make-tag (type start end name name-end))) type start end name name-end) - (defsubst xml-lite-parse-tag-name () "Skip past a tag-name, and return the name." (buffer-substring-no-properties @@ -133,7 +119,7 @@ (let ((limit (max (- (point) (length s)) (point-min)))) (equal s (buffer-substring-no-properties limit (point))))) -(defsubst xml-lite-looking-at (s) +(defsubst xml-lite-looking-at (s) (let ((limit (min (+ (point) (length s))))) (equal s (buffer-substring-no-properties (point) limit)))) @@ -254,7 +240,7 @@ ;; inside a tag ... ((xml-lite-inside-tag-p tag-info here) - (setq context (cons tag-info context))) + (push tag-info context)) ;; start-tag ((eq (xml-lite-tag-type tag-info) 'open) @@ -294,23 +280,27 @@ (cond ;; no context - ((null context) - 0) + ((null context) 0) ;; inside a comment ((eq 'comment (xml-lite-tag-type last-tag-info)) - (goto-char (xml-lite-tag-start last-tag-info)) - (+ (current-column) xml-lite-indent-comment-offset)) + (let ((mark (looking-at "--"))) + (goto-char (xml-lite-tag-start last-tag-info)) + (forward-char 2) + (if mark (current-column) + (forward-char 2) + (+ (if (zerop (skip-chars-forward " \t")) 1 0) + (current-column))))) ;; inside a tag ((xml-lite-inside-tag-p last-tag-info here) - (let ((in-string + (let ((start-of-enclosing-string (xml-lite-in-string-p (xml-lite-tag-start last-tag-info)))) (cond - ;; inside a string - (in-string - (goto-char (nth 1 in-string)) + ;; inside an attribute value + (start-of-enclosing-string + (goto-char start-of-enclosing-string) (1+ (current-column))) ;; if we have a tag-name, base indent on that ((and (xml-lite-tag-name-end last-tag-info) @@ -321,21 +311,19 @@ ;; otherwise, add indent-offset (t (goto-char (xml-lite-tag-start last-tag-info)) - (+ (current-column) xml-lite-indent-offset))))) + (+ (current-column) xml-lite-basic-offset))))) ;; inside an element (t ;; indent to start of tag - (let ((here (point)) - indent-col) + (let ((indent-offset xml-lite-basic-offset)) + ;; add xml-lite-basic-offset, unless we're looking at the + ;; matching end-tag + (if (and (eq (length context) 1) + (xml-lite-looking-at "")) - ((eq type 'comment) (insert " -->")) - ((eq type 'cdata) (insert "]]>")) - ((eq type 'jsp) (insert "%>")) - ((eq type 'pi) (insert "?>")) - (t (insert ">")))) + (insert (cond + ((eq type 'open) " />") + ((eq type 'comment) " -->") + ((eq type 'cdata) "]]>") + ((eq type 'jsp) "%>") + ((eq type 'pi) "?>") + (t ">")))) ;; inside an element ((eq type 'open) @@ -423,7 +411,7 @@ With ARG, enable xml-lite-mode if and only if ARG is positive. xml-lite-mode provides indentation for XML tags. The value of -`xml-lite-indent-offset' determines the amount of indentation. +`xml-lite-basic-offset' determines the amount of indentation. Key bindings: \\{xml-lite-mode-map}"