emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/textmodes/sgml-mode.el


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/lisp/textmodes/sgml-mode.el
Date: Thu, 13 Jan 2005 10:10:31 -0500

Index: emacs/lisp/textmodes/sgml-mode.el
diff -c emacs/lisp/textmodes/sgml-mode.el:1.101 
emacs/lisp/textmodes/sgml-mode.el:1.102
*** emacs/lisp/textmodes/sgml-mode.el:1.101     Wed Nov 10 14:39:40 2004
--- emacs/lisp/textmodes/sgml-mode.el   Thu Jan 13 14:51:54 2005
***************
*** 1,6 ****
  ;;; sgml-mode.el --- SGML- and HTML-editing modes
  
! ;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004
  ;;           Free Software Foundation, Inc.
  
  ;; Author: James Clark <address@hidden>
--- 1,6 ----
  ;;; sgml-mode.el --- SGML- and HTML-editing modes
  
! ;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004, 2005
  ;;           Free Software Foundation, Inc.
  
  ;; Author: James Clark <address@hidden>
***************
*** 394,399 ****
--- 394,407 ----
        (concat "<" face ">"))
      (error "Face not configured for %s mode" mode-name)))
  
+ (defun sgml-fill-nobreak ()
+   ;; Don't break between a tag name and its first argument.
+   (save-excursion
+     (skip-chars-backward " \t")
+     (and (not (zerop (skip-syntax-backward "w_")))
+        (skip-chars-backward "/?!")
+        (eq (char-before) ?<))))
+ 
  ;;;###autoload
  (define-derived-mode sgml-mode text-mode "SGML"
    "Major mode for editing SGML documents.
***************
*** 424,429 ****
--- 432,438 ----
    (set (make-local-variable 'paragraph-separate)
         (concat paragraph-start "$"))
    (set (make-local-variable 'adaptive-fill-regexp) "[ \t]*")
+   (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t)
    (set (make-local-variable 'indent-line-function) 'sgml-indent-line)
    (set (make-local-variable 'comment-start) "<!-- ")
    (set (make-local-variable 'comment-end) " -->")
***************
*** 1140,1156 ****
  Point is assumed to be outside of any tag.  If we discover that it's
  not the case, the first tag returned is the one inside which we are."
    (let ((here (point))
        (ignore nil)
        (context nil)
        tag-info)
      ;; CONTEXT keeps track of the tag-stack
!     ;; IGNORE keeps track of the nesting level of point relative to the
!     ;;   first (outermost) tag on the context.  This is the list of
!     ;;   enclosing start-tags we'll have to ignore.
      (skip-chars-backward " \t\n")      ; Make sure we're not at indentation.
      (while
        (and (not (eq until 'now))
!            (or ignore
                 (not (if until (eq until 'empty) context))
                 (not (sgml-at-indentation-p))
                 (and context
--- 1149,1167 ----
  Point is assumed to be outside of any tag.  If we discover that it's
  not the case, the first tag returned is the one inside which we are."
    (let ((here (point))
+       (stack nil)
        (ignore nil)
        (context nil)
        tag-info)
      ;; CONTEXT keeps track of the tag-stack
!     ;; STACK keeps track of the end tags we've seen (and thus the start-tags
!     ;;   we'll have to ignore) when skipping over matching open..close pairs.
!     ;; IGNORE is a list of tags that can be ignored because they have been
!     ;;   closed implicitly.
      (skip-chars-backward " \t\n")      ; Make sure we're not at indentation.
      (while
        (and (not (eq until 'now))
!            (or stack
                 (not (if until (eq until 'empty) context))
                 (not (sgml-at-indentation-p))
                 (and context
***************
*** 1174,1197 ****
         ;; start-tag
         ((eq (sgml-tag-type tag-info) 'open)
        (cond
!        ((null ignore)
!         (if (and context
!                    (sgml-unclosed-tag-p (sgml-tag-name tag-info))
!                  (eq t (compare-strings
!                         (sgml-tag-name tag-info) nil nil
!                         (sgml-tag-name (car context)) nil nil t)))
              ;; There was an implicit end-tag.
              nil
!           (push tag-info context)))
         ((eq t (compare-strings (sgml-tag-name tag-info) nil nil
!                                (car ignore) nil nil t))
!         (setq ignore (cdr ignore)))
         (t
          ;; The open and close tags don't match.
          (if (not sgml-xml-mode)
              (unless (sgml-unclosed-tag-p (sgml-tag-name tag-info))
                (message "Unclosed tag <%s>" (sgml-tag-name tag-info))
!               (let ((tmp ignore))
                  ;; We could just assume that the tag is simply not closed
                  ;; but it's a bad assumption when tags *are* closed but
                  ;; not properly nested.
--- 1185,1209 ----
         ;; start-tag
         ((eq (sgml-tag-type tag-info) 'open)
        (cond
!        ((null stack)
!         (if (member-ignore-case (sgml-tag-name tag-info) ignore)
              ;; There was an implicit end-tag.
              nil
!           (push tag-info context)
!           ;; We're changing context so the tags implicitly closed inside
!           ;; the previous context aren't implicitly closed here any more.
!           ;; [ Well, actually it depends, but we don't have the info about
!           ;; when it doesn't and when it does.   --Stef ]
!           (setq ignore nil)))
         ((eq t (compare-strings (sgml-tag-name tag-info) nil nil
!                                (car stack) nil nil t))
!         (setq stack (cdr stack)))
         (t
          ;; The open and close tags don't match.
          (if (not sgml-xml-mode)
              (unless (sgml-unclosed-tag-p (sgml-tag-name tag-info))
                (message "Unclosed tag <%s>" (sgml-tag-name tag-info))
!               (let ((tmp stack))
                  ;; We could just assume that the tag is simply not closed
                  ;; but it's a bad assumption when tags *are* closed but
                  ;; not properly nested.
***************
*** 1202,1214 ****
                    (setq tmp (cdr tmp)))
                  (if (cdr tmp) (setcdr tmp (cddr tmp)))))
            (message "Unmatched tags <%s> and </%s>"
!                    (sgml-tag-name tag-info) (pop ignore))))))
  
         ;; end-tag
         ((eq (sgml-tag-type tag-info) 'close)
        (if (sgml-empty-tag-p (sgml-tag-name tag-info))
            (message "Spurious </%s>: empty tag" (sgml-tag-name tag-info))
!         (push (sgml-tag-name tag-info) ignore)))
         ))
  
      ;; return context
--- 1214,1232 ----
                    (setq tmp (cdr tmp)))
                  (if (cdr tmp) (setcdr tmp (cddr tmp)))))
            (message "Unmatched tags <%s> and </%s>"
!                    (sgml-tag-name tag-info) (pop stack)))))
!       
!       (if (and (null stack) (sgml-unclosed-tag-p (sgml-tag-name tag-info)))
!           ;; This is a top-level open of an implicitly closed tag, so any
!           ;; occurrence of such an open tag at the same level can be ignored
!           ;; because it's been implicitly closed.
!           (push (sgml-tag-name tag-info) ignore)))
  
         ;; end-tag
         ((eq (sgml-tag-type tag-info) 'close)
        (if (sgml-empty-tag-p (sgml-tag-name tag-info))
            (message "Spurious </%s>: empty tag" (sgml-tag-name tag-info))
!         (push (sgml-tag-name tag-info) stack)))
         ))
  
      ;; return context




reply via email to

[Prev in Thread] Current Thread [Next in Thread]