From: Stefan Monnier Date: Thu, 5 Jun 2003 01:14:23 +0000 (+0000) Subject: (sgml-parse-tag-backward): Try and detect X-Git-Tag: ttn-vms-21-2-B4~9730 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=59444a9cccb3f5c10536f7bfcc776e9afa29438e;p=emacs.git (sgml-parse-tag-backward): Try and detect when we're starting from within a tag. (sgml-get-context): When called from inside a tag, do something useful. Rename the arg now that it's never used for `full' context anymore. (sgml-calculate-indent): Make `lcon' an argument. Return nil when we don't know what to do. If the initial lcon turns out to be wrong, try again. (sgml-indent-line): If sgml-calculate-indent returns nil, don't indent. --- diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 87c9e820e1f..d942c263274 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -368,8 +368,8 @@ Otherwise, it is set to be buffer-local when the file has (looking-at "\\s-*<\\?xml") (when (re-search-forward (eval-when-compile - (mapconcat 'identity - '("" limit 'move) + (or (re-search-backward "[<>]" limit 'move) (error "No tag found")) + (when (eq (char-after) ?<) + ;; Oops!! Looks like we were not in a textual context after all!. + ;; Let's try to recover. + (with-syntax-table sgml-tag-syntax-table + (forward-sexp) + (forward-char -1))) (setq tag-end (1+ (point))) (cond ((sgml-looking-back-at "--") ; comment @@ -1082,15 +1088,17 @@ Leave point at the beginning of the tag." (goto-char tag-start) (sgml-make-tag tag-type tag-start tag-end name))) -(defun sgml-get-context (&optional full) +(defun sgml-get-context (&optional until) "Determine the context of the current position. -If FULL is `empty', return even if the context is empty (i.e. +By default, parse until we find a start-tag as the first thing on a line. +If UNTIL is `empty', return even if the context is empty (i.e. we just skipped over some element and got to a beginning of line). -If FULL is non-nil, parse back to the beginning of the buffer, otherwise -parse until we find a start-tag as the first thing on a line. The context is a list of tag-info structures. The last one is the tag -immediately enclosing the current position." +immediately enclosing the current position. + +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) @@ -1101,12 +1109,13 @@ immediately enclosing the current position." ;; enclosing start-tags we'll have to ignore. (skip-chars-backward " \t\n") ; Make sure we're not at indentation. (while - (and (or ignore - (not (if full (eq full 'empty) context)) + (and (not (eq until 'now)) + (or ignore + (not (if until (eq until 'empty) context)) (not (sgml-at-indentation-p)) (and context (/= (point) (sgml-tag-start (car context))) - (sgml-unclosed-tag-p (sgml-tag-name (car context))))) + (sgml-unclosed-tag-p (sgml-tag-name (car context))))) (setq tag-info (ignore-errors (sgml-parse-tag-backward)))) ;; This tag may enclose things we thought were tags. If so, @@ -1117,6 +1126,10 @@ immediately enclosing the current position." (setq context (cdr context))) (cond + ((> (sgml-tag-end tag-info) here) + ;; Oops!! Looks like we were not outside of any tag, after all. + (push tag-info context) + (setq until 'now)) ;; start-tag ((eq (sgml-tag-type tag-info) 'open) @@ -1207,99 +1220,113 @@ the current start-tag or the current comment or the current cdata, ..." (and (not sgml-xml-mode) (member-ignore-case tag-name sgml-unclosed-tags))) -(defun sgml-calculate-indent () - "Calculate the column to which this line should be indented." - (let ((lcon (sgml-lexical-context))) - - ;; Indent comment-start markers inside