diff lisp/textmodes/sgml-mode.el @ 90072:cb67264d6096

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-2 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-83 - miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-84 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-3 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-4 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-5 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-6 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-11 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-12 Remove "-face" suffix from lazy-highlight face name * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-13 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-16 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-17 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-18 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-21 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-22 <no summary provided> * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-23 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-39 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40 Fix regressions from latest reftex update * miles@gnu.org--gnu-2005/gnus--rel--5.10--base-0 tag of miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-1 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-2 Merge from miles@gnu.org--gnu-2004 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-3 Merge from emacs--cvs-trunk--0
author Miles Bader <miles@gnu.org>
date Sun, 16 Jan 2005 03:40:12 +0000
parents cb7f41387eb3 e51199adcfb0
children 3ebd9bdb4fe5
line wrap: on
line diff
--- a/lisp/textmodes/sgml-mode.el	Sun Jan 02 09:21:32 2005 +0000
+++ b/lisp/textmodes/sgml-mode.el	Sun Jan 16 03:40:12 2005 +0000
@@ -1,6 +1,6 @@
 ;;; sgml-mode.el --- SGML- and HTML-editing modes
 
-;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004
+;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004, 2005
 ;;           Free Software Foundation, Inc.
 
 ;; Author: James Clark <jjc@jclark.com>
@@ -392,6 +392,14 @@
 	(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.
@@ -422,6 +430,7 @@
   (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) " -->")
@@ -1138,17 +1147,19 @@
 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
-    ;; 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.
+    ;; 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 ignore
+	     (or stack
 		 (not (if until (eq until 'empty) context))
 		 (not (sgml-at-indentation-p))
 		 (and context
@@ -1172,24 +1183,25 @@
        ;; 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)))
+	 ((null stack)
+	  (if (member-ignore-case (sgml-tag-name tag-info) ignore)
 	      ;; There was an implicit end-tag.
 	      nil
-	    (push tag-info context)))
+	    (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 ignore) nil nil t))
-	  (setq ignore (cdr ignore)))
+				 (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 ignore))
+		(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.
@@ -1200,13 +1212,19 @@
 		    (setq tmp (cdr tmp)))
 		  (if (cdr tmp) (setcdr tmp (cddr tmp)))))
 	    (message "Unmatched tags <%s> and </%s>"
-		     (sgml-tag-name tag-info) (pop ignore))))))
+		     (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) ignore)))
+	  (push (sgml-tag-name tag-info) stack)))
        ))
 
     ;; return context