From: Mike Williams Date: Thu, 11 Apr 2002 21:59:45 +0000 (+0000) Subject: (sgml-guess-indent): New function. X-Git-Tag: ttn-vms-21-2-B4~15689 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2871b07a8940301a85d266008daee5b8bf28198a;p=emacs.git (sgml-guess-indent): New function. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ff6ad3b4795..82eff1a7346 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2002-04-12 Mike Williams + + * textmodes/sgml-mode.el (sgml-guess-indent): New function. + 2002-04-11 Pavel Jan,Bm(Bk * menu-bar.el (menu-bar-adv-search-menu): Add incremental search. diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 9df19cc1180..2a410554de6 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -889,7 +889,7 @@ If nil, start from a preceding tag at indentation." (unless (search-forward "]]>" pos 'move) (list 0 nil nil 'cdata nil nil nil nil cdata-start)))) (t - ;; We've reached a tag. Parse it. + ;; We've reached a tag. Parse it. ;; FIXME: Handle net-enabling start-tags (parse-partial-sexp (point) pos 0)))))) (cond @@ -1031,7 +1031,7 @@ 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 + (and (or ignore (not (if full (eq full 'empty) context)) (not (sgml-at-indentation-p)) (and context @@ -1104,7 +1104,7 @@ If FULL is non-nil, parse back to the beginning of the buffer." (text (let ((context (save-excursion (sgml-get-context)))) (if context - (progn + (progn (insert "") (indent-according-to-mode))))) (otherwise @@ -1227,6 +1227,21 @@ If FULL is non-nil, parse back to the beginning of the buffer." (save-excursion (indent-line-to indent-col)) (indent-line-to indent-col)))) +(defun sgml-guess-indent () + "Guess an appropriate value for `sgml-basic-offset'. +Base the guessed identation level on the first indented tag in the buffer. +Add this to `sgml-mode-hook' for convenience." + (interactive) + (save-excursion + (goto-char (point-min)) + (if (re-search-forward "^\\([ \t]+\\)<" 100 'noerror) + (progn + (set (make-local-variable 'sgml-basic-offset) + (length (match-string 1))) + (message "Guessed sgml-basic-offset = %d" + sgml-basic-offset) + )))) + (defun sgml-parse-dtd () "Simplistic parse of the current buffer as a DTD. Currently just returns (EMPTY-TAGS UNCLOSED-TAGS)."