diff options
| author | Stefan Monnier | 2002-03-27 22:25:45 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-03-27 22:25:45 +0000 |
| commit | 3c856284309670fa5a34c23ab081aeaf269d2aea (patch) | |
| tree | d3087386d6f6e813767cff7e041517cfe037dc98 | |
| parent | 0fcbf8d6018cd4363d42fb17636739002f571821 (diff) | |
| download | emacs-3c856284309670fa5a34c23ab081aeaf269d2aea.tar.gz emacs-3c856284309670fa5a34c23ab081aeaf269d2aea.zip | |
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.
| -rw-r--r-- | lisp/textmodes/xml-lite.el | 78 |
1 files changed, 33 insertions, 45 deletions
diff --git a/lisp/textmodes/xml-lite.el b/lisp/textmodes/xml-lite.el index 0318e0b339e..a32a7a8f8f4 100644 --- a/lisp/textmodes/xml-lite.el +++ b/lisp/textmodes/xml-lite.el | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | ;;; xml-lite.el --- an indentation-engine for XML | 1 | ;;; xml-lite.el --- an indentation-engine for XML |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2001 Mike Williams <mdub@bigfoot.com> | 3 | ;; Copyright (C) 2002 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Mike Williams <mdub@bigfoot.com> | 5 | ;; Author: Mike Williams <mdub@bigfoot.com> |
| 6 | ;; Created: February 2001 | 6 | ;; Created: February 2001 |
| 7 | ;; Version: $Revision: 1.2 $ | ||
| 8 | ;; Keywords: xml | 7 | ;; Keywords: xml |
| 9 | 8 | ||
| 10 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| @@ -32,11 +31,6 @@ | |||
| 32 | ;; | 31 | ;; |
| 33 | ;; xml-lite is designed to be used in conjunction with the default GNU | 32 | ;; xml-lite is designed to be used in conjunction with the default GNU |
| 34 | ;; Emacs sgml-mode, to provide a lightweight XML-editing environment. | 33 | ;; Emacs sgml-mode, to provide a lightweight XML-editing environment. |
| 35 | ;; | ||
| 36 | ;; Updates will be made available at: | ||
| 37 | ;; http://www.bigfoot.com/~mdub/software/xml-lite.el | ||
| 38 | ;; | ||
| 39 | ;; Note: the font-lock support that was in this package has been removed. | ||
| 40 | 34 | ||
| 41 | ;;; Thanks: | 35 | ;;; Thanks: |
| 42 | ;; | 36 | ;; |
| @@ -56,14 +50,8 @@ | |||
| 56 | :group 'languages | 50 | :group 'languages |
| 57 | ) | 51 | ) |
| 58 | 52 | ||
| 59 | (defcustom xml-lite-indent-offset 4 | 53 | (defcustom xml-lite-basic-offset 2 |
| 60 | "*Specifies the default indentation level for `xml-lite-indent-line'." | 54 | "*Specifies the basic indentation level for `xml-lite-indent-line'." |
| 61 | :type 'integer | ||
| 62 | :group 'xml-lite | ||
| 63 | ) | ||
| 64 | |||
| 65 | (defcustom xml-lite-indent-comment-offset 5 | ||
| 66 | "*Specifies the indentation level for XML comments." | ||
| 67 | :type 'integer | 55 | :type 'integer |
| 68 | :group 'xml-lite | 56 | :group 'xml-lite |
| 69 | ) | 57 | ) |
| @@ -119,11 +107,9 @@ Set this to nil if you don't want a modeline indicator for xml-lite-mode." | |||
| 119 | 107 | ||
| 120 | 108 | ||
| 121 | ;; Parsing | 109 | ;; Parsing |
| 122 | |||
| 123 | (defstruct (xml-lite-tag | 110 | (defstruct (xml-lite-tag |
| 124 | (:constructor xml-lite-make-tag (type start end name name-end))) | 111 | (:constructor xml-lite-make-tag (type start end name name-end))) |
| 125 | type start end name name-end) | 112 | type start end name name-end) |
| 126 | |||
| 127 | (defsubst xml-lite-parse-tag-name () | 113 | (defsubst xml-lite-parse-tag-name () |
| 128 | "Skip past a tag-name, and return the name." | 114 | "Skip past a tag-name, and return the name." |
| 129 | (buffer-substring-no-properties | 115 | (buffer-substring-no-properties |
| @@ -133,7 +119,7 @@ Set this to nil if you don't want a modeline indicator for xml-lite-mode." | |||
| 133 | (let ((limit (max (- (point) (length s)) (point-min)))) | 119 | (let ((limit (max (- (point) (length s)) (point-min)))) |
| 134 | (equal s (buffer-substring-no-properties limit (point))))) | 120 | (equal s (buffer-substring-no-properties limit (point))))) |
| 135 | 121 | ||
| 136 | (defsubst xml-lite-looking-at (s) | 122 | (defsubst xml-lite-looking-at (s) |
| 137 | (let ((limit (min (+ (point) (length s))))) | 123 | (let ((limit (min (+ (point) (length s))))) |
| 138 | (equal s (buffer-substring-no-properties (point) limit)))) | 124 | (equal s (buffer-substring-no-properties (point) limit)))) |
| 139 | 125 | ||
| @@ -254,7 +240,7 @@ immediately enclosing the current position." | |||
| 254 | 240 | ||
| 255 | ;; inside a tag ... | 241 | ;; inside a tag ... |
| 256 | ((xml-lite-inside-tag-p tag-info here) | 242 | ((xml-lite-inside-tag-p tag-info here) |
| 257 | (setq context (cons tag-info context))) | 243 | (push tag-info context)) |
| 258 | 244 | ||
| 259 | ;; start-tag | 245 | ;; start-tag |
| 260 | ((eq (xml-lite-tag-type tag-info) 'open) | 246 | ((eq (xml-lite-tag-type tag-info) 'open) |
| @@ -294,23 +280,27 @@ If FULL is non-nil, parse back to the beginning of the buffer." | |||
| 294 | (cond | 280 | (cond |
| 295 | 281 | ||
| 296 | ;; no context | 282 | ;; no context |
| 297 | ((null context) | 283 | ((null context) 0) |
| 298 | 0) | ||
| 299 | 284 | ||
| 300 | ;; inside a comment | 285 | ;; inside a comment |
| 301 | ((eq 'comment (xml-lite-tag-type last-tag-info)) | 286 | ((eq 'comment (xml-lite-tag-type last-tag-info)) |
| 302 | (goto-char (xml-lite-tag-start last-tag-info)) | 287 | (let ((mark (looking-at "--"))) |
| 303 | (+ (current-column) xml-lite-indent-comment-offset)) | 288 | (goto-char (xml-lite-tag-start last-tag-info)) |
| 289 | (forward-char 2) | ||
| 290 | (if mark (current-column) | ||
| 291 | (forward-char 2) | ||
| 292 | (+ (if (zerop (skip-chars-forward " \t")) 1 0) | ||
| 293 | (current-column))))) | ||
| 304 | 294 | ||
| 305 | ;; inside a tag | 295 | ;; inside a tag |
| 306 | ((xml-lite-inside-tag-p last-tag-info here) | 296 | ((xml-lite-inside-tag-p last-tag-info here) |
| 307 | 297 | ||
| 308 | (let ((in-string | 298 | (let ((start-of-enclosing-string |
| 309 | (xml-lite-in-string-p (xml-lite-tag-start last-tag-info)))) | 299 | (xml-lite-in-string-p (xml-lite-tag-start last-tag-info)))) |
| 310 | (cond | 300 | (cond |
| 311 | ;; inside a string | 301 | ;; inside an attribute value |
| 312 | (in-string | 302 | (start-of-enclosing-string |
| 313 | (goto-char (nth 1 in-string)) | 303 | (goto-char start-of-enclosing-string) |
| 314 | (1+ (current-column))) | 304 | (1+ (current-column))) |
| 315 | ;; if we have a tag-name, base indent on that | 305 | ;; if we have a tag-name, base indent on that |
| 316 | ((and (xml-lite-tag-name-end last-tag-info) | 306 | ((and (xml-lite-tag-name-end last-tag-info) |
| @@ -321,21 +311,19 @@ If FULL is non-nil, parse back to the beginning of the buffer." | |||
| 321 | ;; otherwise, add indent-offset | 311 | ;; otherwise, add indent-offset |
| 322 | (t | 312 | (t |
| 323 | (goto-char (xml-lite-tag-start last-tag-info)) | 313 | (goto-char (xml-lite-tag-start last-tag-info)) |
| 324 | (+ (current-column) xml-lite-indent-offset))))) | 314 | (+ (current-column) xml-lite-basic-offset))))) |
| 325 | 315 | ||
| 326 | ;; inside an element | 316 | ;; inside an element |
| 327 | (t | 317 | (t |
| 328 | ;; indent to start of tag | 318 | ;; indent to start of tag |
| 329 | (let ((here (point)) | 319 | (let ((indent-offset xml-lite-basic-offset)) |
| 330 | indent-col) | 320 | ;; add xml-lite-basic-offset, unless we're looking at the |
| 321 | ;; matching end-tag | ||
| 322 | (if (and (eq (length context) 1) | ||
| 323 | (xml-lite-looking-at "</")) | ||
| 324 | (setq indent-offset 0)) | ||
| 331 | (goto-char (xml-lite-tag-start ref-tag-info)) | 325 | (goto-char (xml-lite-tag-start ref-tag-info)) |
| 332 | (setq indent-col (current-column)) | 326 | (+ (current-column) indent-offset))) |
| 333 | (goto-char here) | ||
| 334 | ;; add xml-lite-indent-offset, unless we're looking at the matching | ||
| 335 | ;; end-tag | ||
| 336 | (unless (and (eq (length context) 1) (looking-at "</")) | ||
| 337 | (setq indent-col (+ indent-col xml-lite-indent-offset))) | ||
| 338 | indent-col)) | ||
| 339 | 327 | ||
| 340 | )))) | 328 | )))) |
| 341 | 329 | ||
| @@ -371,13 +359,13 @@ If FULL is non-nil, parse back to the beginning of the buffer." | |||
| 371 | 359 | ||
| 372 | ;; inside a tag | 360 | ;; inside a tag |
| 373 | ((xml-lite-inside-tag-p tag-info) | 361 | ((xml-lite-inside-tag-p tag-info) |
| 374 | (cond | 362 | (insert (cond |
| 375 | ((eq type 'open) (insert " />")) | 363 | ((eq type 'open) " />") |
| 376 | ((eq type 'comment) (insert " -->")) | 364 | ((eq type 'comment) " -->") |
| 377 | ((eq type 'cdata) (insert "]]>")) | 365 | ((eq type 'cdata) "]]>") |
| 378 | ((eq type 'jsp) (insert "%>")) | 366 | ((eq type 'jsp) "%>") |
| 379 | ((eq type 'pi) (insert "?>")) | 367 | ((eq type 'pi) "?>") |
| 380 | (t (insert ">")))) | 368 | (t ">")))) |
| 381 | 369 | ||
| 382 | ;; inside an element | 370 | ;; inside an element |
| 383 | ((eq type 'open) | 371 | ((eq type 'open) |
| @@ -423,7 +411,7 @@ Behaves electrically if `xml-lite-electric-slash' is non-nil." | |||
| 423 | With ARG, enable xml-lite-mode if and only if ARG is positive. | 411 | With ARG, enable xml-lite-mode if and only if ARG is positive. |
| 424 | 412 | ||
| 425 | xml-lite-mode provides indentation for XML tags. The value of | 413 | xml-lite-mode provides indentation for XML tags. The value of |
| 426 | `xml-lite-indent-offset' determines the amount of indentation. | 414 | `xml-lite-basic-offset' determines the amount of indentation. |
| 427 | 415 | ||
| 428 | Key bindings: | 416 | Key bindings: |
| 429 | \\{xml-lite-mode-map}" | 417 | \\{xml-lite-mode-map}" |