/[emacs]/emacs/lisp/textmodes/xml-lite.el
ViewVC logotype

Diff of /emacs/lisp/textmodes/xml-lite.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by monnier, Fri Mar 29 20:10:46 2002 UTC revision 1.8 by monnier, Fri Mar 29 22:16:38 2002 UTC
# Line 223  immediately enclosing the current positi Line 223  immediately enclosing the current positi
223      (skip-chars-backward " \t\n")      ; Make sure we're not at indentation.      (skip-chars-backward " \t\n")      ; Make sure we're not at indentation.
224      (while      (while
225          (and (or ignore (not (if full (eq full 'empty) context))          (and (or ignore (not (if full (eq full 'empty) context))
226                   (not (xml-lite-at-indentation-p)))                   (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)))
231               (setq tag-info (xml-lite-parse-tag-backward)))               (setq tag-info (xml-lite-parse-tag-backward)))
232                
233        ;; This tag may enclose things we thought were tags.  If so,        ;; This tag may enclose things we thought were tags.  If so,
# Line 242  immediately enclosing the current positi Line 246  immediately enclosing the current positi
246         ;; start-tag         ;; start-tag
247         ((eq (xml-lite-tag-type tag-info) 'open)         ((eq (xml-lite-tag-type tag-info) 'open)
248          (cond          (cond
249           ((null ignore) (push tag-info context))           ((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)))
259           ((eq t (compare-strings (xml-lite-tag-name tag-info) nil nil           ((eq t (compare-strings (xml-lite-tag-name tag-info) nil nil
260                                   (car ignore) nil nil t))                                   (car ignore) nil nil t))
261            (setq ignore (cdr ignore)))            (setq ignore (cdr ignore)))
# Line 278  If FULL is non-nil, parse back to the be Line 291  If FULL is non-nil, parse back to the be
291    
292  ;; Indenting  ;; Indenting
293    
 (defun xml-lite-calculate-indent ()  
   "Calculate the column to which this line should be indented."  
   (let* ((here (point))  
          (context (save-excursion (xml-lite-get-context)))  
          (ref-tag-info (car context))  
          (last-tag-info (car (last context))))  
   
     (save-excursion  
       (cond  
   
        ;; no context  
        ((null context) 0)  
   
        ;; inside a comment  
        ((eq 'comment (xml-lite-tag-type last-tag-info))  
         (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 ((start-of-enclosing-string  
                (xml-lite-in-string-p (xml-lite-tag-start last-tag-info))))  
           (cond  
            ;; 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)  
                  (progn  
                    (goto-char (xml-lite-tag-name-end last-tag-info))  
                    (not (looking-at "[ \t]*$"))))  
             (1+ (current-column)))  
            ;; otherwise, add indent-offset  
            (t  
             (goto-char (xml-lite-tag-start last-tag-info))  
             (+ (current-column) xml-lite-basic-offset)))))  
   
        ;; inside an element  
        (t  
         ;; indent to start of tag  
         (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 "</"))  
               (setq indent-offset 0))  
           (goto-char (xml-lite-tag-start ref-tag-info))  
           (+ (current-column) indent-offset)))  
   
        ))))  
   
 (defun xml-lite-indent-line ()  
   "Indent the current line as XML."  
   (interactive)  
   (let* ((savep (point))  
          (indent-col  
           (save-excursion  
             (back-to-indentation)  
             (if (>= (point) savep) (setq savep nil))  
             (xml-lite-calculate-indent))))  
     (if savep  
         (save-excursion (indent-line-to indent-col))  
       (indent-line-to indent-col))))  
   
294    
295  ;; Editing shortcuts  ;; Editing shortcuts
296    
# Line 431  Key bindings: Line 373  Key bindings:
373          (set (make-local-variable 'sgml-xml-mode) t)          (set (make-local-variable 'sgml-xml-mode) t)
374          (set (make-local-variable 'xml-lite-orig-indent-line-function)          (set (make-local-variable 'xml-lite-orig-indent-line-function)
375               indent-line-function)               indent-line-function)
376          (set (make-local-variable 'indent-line-function) 'xml-lite-indent-line))          (set (make-local-variable 'indent-line-function) 'sgml-indent-line))
377      (kill-local-variable 'sgml-xml-mode)      (kill-local-variable 'sgml-xml-mode)
378      (setq indent-line-function xml-lite-orig-indent-line-function)))      (setq indent-line-function xml-lite-orig-indent-line-function)))
379    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26