changeset 44180:e7a365c909ff

Don't require `custom'. (xml-lite-parse-tag-name): Properly treat non-ASCII chars. (xml-lite-parse-tag-backward): Obey sgml-empty-tags. (xml-lite-get-context): Drop nested tags not just for comments. (xml-lite-indent-line): Be more careful about moving point. (xml-lite-insert-end-tag, xml-lite-slash): Use indent-according-to-mode instead of xml-lite-indent-line. (xml-lite-mode): Make xml-lite-orig-indent-line-function buffer-local. Set sgml-xml-mode. Don't call force-mode-line-update. (xml-lite-mode-map): Don't bind TAB.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 27 Mar 2002 18:02:36 +0000
parents 02b2708043f0
children 81c46680d4c6
files lisp/textmodes/xml-lite.el
diffstat 1 files changed, 34 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/xml-lite.el	Wed Mar 27 16:32:15 2002 +0000
+++ b/lisp/textmodes/xml-lite.el	Wed Mar 27 18:02:36 2002 +0000
@@ -4,7 +4,7 @@
 
 ;; Author:     Mike Williams <mdub@bigfoot.com>
 ;; Created:    February 2001
-;; Version:    $Revision: 1.28 $
+;; Version:    $Revision: 1.2 $
 ;; Keywords:   xml
 
 ;; This file is part of GNU Emacs.
@@ -47,7 +47,6 @@
 
 (eval-when-compile (require 'cl))
 (require 'sgml-mode)
-(require 'custom)
 
 
 ;; Variables
@@ -127,9 +126,8 @@
 
 (defsubst xml-lite-parse-tag-name ()
   "Skip past a tag-name, and return the name."
-  (let ((here (point)))
-    (if (> (skip-chars-forward "-._:A-Za-z0-9") 0)
-        (buffer-substring-no-properties here (point)))))
+  (buffer-substring-no-properties
+   (point) (progn (skip-syntax-forward "w_") (point))))
 
 (defsubst xml-lite-looking-back-at (s)
   (let ((limit (max (- (point) (length s)) (point-min))))
@@ -206,7 +204,9 @@
             name (xml-lite-parse-tag-name)
             name-end (point))
       ;; check whether it's an empty tag
-      (if (and tag-end (eq ?/ (char-before (- tag-end 1))))
+      (if (or (and tag-end (eq ?/ (char-before (- tag-end 1))))
+	      (and (not sgml-xml-mode)
+                   (member-ignore-case name sgml-empty-tags)))
           (setq tag-type 'empty))))
 
     (cond 
@@ -243,6 +243,13 @@
                    (not (xml-lite-at-indentation-p)))
                (setq tag-info (xml-lite-parse-tag-backward)))
 
+        ;; This tag may enclose things we thought were tags.  If so,
+        ;; discard them.
+        (while (and context
+                    (> (xml-lite-tag-end tag-info)
+                       (xml-lite-tag-end (car context))))
+          (setq context (cdr context)))
+           
         (cond
 
          ;; inside a tag ...
@@ -253,20 +260,13 @@
          ((eq (xml-lite-tag-type tag-info) 'open)
           (setq ignore-depth (1- ignore-depth))
           (when (= ignore-depth -1)
-            (setq context (cons tag-info context))
+            (push tag-info context)
             (setq ignore-depth 0)))
 
          ;; end-tag
          ((eq (xml-lite-tag-type tag-info) 'close)
           (setq ignore-depth (1+ ignore-depth)))
          
-         ((eq (xml-lite-tag-type tag-info) 'comment)
-          ;; this comment may enclose things we thought were tags
-          (while (and context
-                      (> (xml-lite-tag-end tag-info)
-                         (xml-lite-tag-end (car context))))
-            (setq context (cdr context))))
-           
          )))
 
     ;; return context
@@ -342,30 +342,17 @@
 (defun xml-lite-indent-line ()
   "Indent the current line as XML."
   (interactive)
-  (let ((origin-point (point))
-        bol-point indent-point
-        indent-col)
-
-    ;; save beginning of line
-    (beginning-of-line)
-    (setq bol-point (point))
-    ;; save current indent
-    (skip-chars-forward " \t")
-    (setq indent-point (point))
-
-    ;; calculate basic indent
-    (setq indent-col (xml-lite-calculate-indent))
-
-    (unless (eq (current-column) indent-col)
-      ;; re-indent, adjusting origin point for indentation change
-      (delete-region bol-point (point))
-      (indent-to indent-col)
-      (setq origin-point (+ origin-point (- (point) indent-point))))
-
-    (if (> origin-point (point))
-        (goto-char origin-point))
-
-    ))
+  (let* ((savep (point))
+	 (indent-col
+	  (save-excursion
+	    (beginning-of-line)
+	    (skip-chars-forward " \t")
+	    (if (>= (point) savep) (setq savep nil))
+	    ;; calculate basic indent
+	    (xml-lite-calculate-indent))))
+    (if savep
+	(save-excursion (indent-line-to indent-col))
+      (indent-line-to indent-col))))
 
 
 ;; Editing shortcuts
@@ -395,7 +382,7 @@
      ;; inside an element
      ((eq type 'open)
       (insert "</" (xml-lite-tag-name tag-info) ">")
-      (xml-lite-indent-line))
+      (indent-according-to-mode))
 
      (t
       (error "Nothing to close")))))
@@ -409,7 +396,7 @@
     (insert-char ?/ arg))
    ((eq xml-lite-electric-slash 'indent)
     (insert-char ?/ 1)
-    (xml-lite-indent-line))
+    (indent-according-to-mode))
    ((eq xml-lite-electric-slash 'close)
     (delete-backward-char 1)
     (xml-lite-insert-end-tag))
@@ -421,7 +408,6 @@
 
 (defvar xml-lite-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "\t" 'indent-for-tab-command)
     (define-key map "\C-c/" 'xml-lite-insert-end-tag)
     (define-key map "\C-c\C-s" 'xml-lite-show-context)
     (define-key map "/" 'xml-lite-slash)
@@ -446,14 +432,13 @@
   'xml-lite-mode-map                    ; keymap
   (if xml-lite-mode
       (progn
-        (if (eq major-mode 'fundamental-mode)
-            (sgml-mode))
-        (make-local-variable 'indent-line-function)
-        (setq xml-lite-mode t
-              xml-lite-orig-indent-line-function indent-line-function
-              indent-line-function 'xml-lite-indent-line))
-    (setq indent-line-function xml-lite-orig-indent-line-function))
-  (force-mode-line-update))
+        (if (eq major-mode 'fundamental-mode) (sgml-mode))
+	(set (make-local-variable 'sgml-xml-mode) t)
+        (set (make-local-variable 'xml-lite-orig-indent-line-function)
+	     indent-line-function)
+	(set (make-local-variable 'indent-line-function) 'xml-lite-indent-line))
+    (kill-local-variable 'sgml-xml-mode)
+    (setq indent-line-function xml-lite-orig-indent-line-function)))
 
 (provide 'xml-lite)