# HG changeset patch # User Stefan Monnier # Date 1105627917 0 # Node ID e51199adcfb05dffb2d3054765696ba55900b91b # Parent d91d1f84814f553b3ff950b3593208fd986a01a4 (sgml-fill-nobreak): New fun. (sgml-mode): Use it. (sgml-get-context): Better keep track of implicitly closed tags. diff -r d91d1f84814f -r e51199adcfb0 lisp/ChangeLog --- a/lisp/ChangeLog Thu Jan 13 14:35:11 2005 +0000 +++ b/lisp/ChangeLog Thu Jan 13 14:51:57 2005 +0000 @@ -1,3 +1,9 @@ +2005-01-13 Stefan Monnier + + * textmodes/sgml-mode.el (sgml-fill-nobreak): New fun. + (sgml-mode): Use it. + (sgml-get-context): Better keep track of implicitly closed tags. + 2005-01-13 Kenichi Handa * textmodes/ispell.el: These changes are to fix misalignment error @@ -28,8 +34,8 @@ 2005-01-12 Nick Roberts - * xt-mouse.el (xterm-mouse-translate, xterm-mouse-event): Enable - mouse clicks on mode-line, header-line and margin. + * xt-mouse.el (xterm-mouse-translate, xterm-mouse-event): + Enable mouse clicks on mode-line, header-line and margin. (event-type): Give mouse event symbols an 'event-kind property with value 'mouse-click. diff -r d91d1f84814f -r e51199adcfb0 lisp/textmodes/sgml-mode.el --- a/lisp/textmodes/sgml-mode.el Thu Jan 13 14:35:11 2005 +0000 +++ b/lisp/textmodes/sgml-mode.el Thu Jan 13 14:51:57 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 @@ -394,6 +394,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. @@ -424,6 +432,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) "") @@ -1140,17 +1149,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 @@ -1174,24 +1185,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. @@ -1202,13 +1214,19 @@ (setq tmp (cdr tmp))) (if (cdr tmp) (setcdr tmp (cddr tmp))))) (message "Unmatched tags <%s> and " - (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 : empty tag" (sgml-tag-name tag-info)) - (push (sgml-tag-name tag-info) ignore))) + (push (sgml-tag-name tag-info) stack))) )) ;; return context