;;; xml-lite.el --- an indentation-engine for XML ;; Copyright (C) 2002 Free Software Foundation, Inc. ;; Author: Mike Williams ;; Created: February 2001 ;; Keywords: xml ;; This file is part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; ;; This package provides a simple indentation engine for XML. It is ;; intended for use in situations where the full power of the popular PSGML ;; package (DTD parsing, syntax checking) is not required. ;; ;; xml-lite is designed to be used in conjunction with the default GNU ;; Emacs sgml-mode, to provide a lightweight XML-editing environment. ;;; Thanks: ;; ;; Jens Schmidt ;; for his feedback and suggestions ;; PLEASE NOTE! ;; xml-lite is on it's way out, as functionality is merged into ;; sgml-mode. ;;; Code: (eval-when-compile (require 'cl)) (require 'sgml-mode) ;; Syntax analysis (defsubst xml-lite-at-indentation-p () "Return true if point is at the first non-whitespace character on the line." (save-excursion (skip-chars-backward " \t") (bolp))) ;; Parsing (defstruct (xml-lite-tag (:constructor xml-lite-make-tag (type start end name))) type start end name) (defsubst xml-lite-parse-tag-name () "Skip past a tag-name, and return the name." (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)))) (equal s (buffer-substring-no-properties limit (point))))) (defsubst xml-lite-looking-at (s) (let ((limit (min (+ (point) (length s))))) (equal s (buffer-substring-no-properties (point) limit)))) (defun xml-lite-parse-tag-backward () "Parse an SGML tag backward, and return information about the tag. Assume that parsing starts from within a textual context. Leave point at the beginning of the tag." (let (tag-type tag-start tag-end name) (search-backward ">") (setq tag-end (1+ (point))) (cond ((xml-lite-looking-back-at "--") ; comment (setq tag-type 'comment tag-start (search-backward "") ((eq type 'cdata) "]]>") ((eq type 'jsp) "%>") ((eq type 'pi) "?>") (t ">")))) ;; inside an element ((eq type 'open) (insert "") (indent-according-to-mode)) (t (error "Nothing to close"))))) (defun xml-lite-slash (arg) "Insert ARG slash characters. Behaves electrically if `xml-lite-electric-slash' is non-nil." (interactive "p") (cond ((not (and (eq (char-before) ?<) (= arg 1))) (insert-char ?/ arg)) ((eq xml-lite-electric-slash 'indent) (insert-char ?/ 1) (indent-according-to-mode)) ((eq xml-lite-electric-slash 'close) (delete-backward-char 1) (xml-lite-insert-end-tag)) (t (insert-char ?/ arg)))) (provide 'xml-lite) ;;; xml-lite.el ends here