# HG changeset patch # User Stefan Monnier # Date 1016409315 0 # Node ID 6dff5806cdcde8c26993b89218cd0573b9a1ede7 # Parent 9f447f01d6c9c05bed153666911a2792dceefb1f (sgml-xml-mode): Renamed from sgml-xml. (sgml-xml-guess): Simplify. (sgml-mode-common): Remove (move into sgml-mode). (sgml-mode): Add code from sgml-mode-common. Remove redundant setting of indent-line-function. Don't set skeleton-transformation when in XML mode. diff -r 9f447f01d6c9 -r 6dff5806cdcd lisp/textmodes/sgml-mode.el --- a/lisp/textmodes/sgml-mode.el Sun Mar 17 21:51:46 2002 +0000 +++ b/lisp/textmodes/sgml-mode.el Sun Mar 17 23:55:15 2002 +0000 @@ -319,7 +319,7 @@ (string :tag "Description"))) :group 'sgml) -(defcustom sgml-xml nil +(defcustom sgml-xml-mode nil "*When non-nil, tag insertion functions will be XML-compliant. If this variable is customized, the custom value is used always. Otherwise, it is set to be buffer-local when the file has @@ -335,34 +335,51 @@ "Guess whether the current buffer is XML." (save-excursion (goto-char (point-min)) - (cond ((or (string= "xml" (file-name-extension (or buffer-file-name ""))) - (looking-at "\\s-*<\\?xml")) - (set (make-local-variable 'sgml-xml) t)) - ((re-search-forward - (eval-when-compile - (mapconcat 'identity - '("")) + (concat "<" face ">")) + (error "Face not configured for %s mode" mode-name))) + + +;;;###autoload +(define-derived-mode sgml-mode text-mode "SGML" + "Major mode for editing SGML documents. +Makes > match <. +Keys <, &, SPC within <>, \" and ' can be electric depending on +`sgml-quick-keys'. + +An argument of N to a tag-inserting command means to wrap it around +the next N words. In Transient Mark mode, when the mark is active, +N defaults to -1, which means to wrap it around the current region. + +If you like upcased tags, put (setq sgml-transformation 'upcase) in +your `.emacs' file. + +Use \\[sgml-validate] to validate your document with an SGML parser. + +Do \\[describe-variable] sgml- SPC to see available variables. +Do \\[describe-key] on the following bindings to discover what they do. +\\{sgml-mode-map}" (make-local-variable 'sgml-saved-validate-command) (make-local-variable 'facemenu-end-add-face) ;;(make-local-variable 'facemenu-remove-face-function) - (set (make-local-variable 'indent-line-function) 'indent-relative-maybe) ;; A start or end tag by itself on a line separates a paragraph. ;; This is desirable because SGML discards a newline that appears ;; immediately after a start tag or immediately before an end tag. @@ -374,7 +391,6 @@ (set (make-local-variable 'comment-start) "") (set (make-local-variable 'comment-indent-function) 'sgml-comment-indent) - (set (make-local-variable 'skeleton-transformation) sgml-transformation) (set (make-local-variable 'skeleton-further-elements) '((completion-ignore-case t))) (set (make-local-variable 'skeleton-end-hook) @@ -391,46 +407,15 @@ . sgml-font-lock-syntactic-keywords))) (set (make-local-variable 'facemenu-add-face-function) 'sgml-mode-facemenu-add-face-function) - ;; `sgml-xml' not customized -- guess - (unless (get 'sgml-xml 'saved-value) (sgml-xml-guess)) + (sgml-xml-guess) + (if sgml-xml-mode + (setq mode-name "XML") + (set (make-local-variable 'skeleton-transformation) sgml-transformation)) ;; This will allow existing comments within declarations to be ;; recognized. (set (make-local-variable 'comment-start-skip) "\\(?:\\)?")) - - -(defun sgml-mode-facemenu-add-face-function (face end) - (if (setq face (cdr (assq face sgml-face-tag-alist))) - (progn - (setq face (funcall skeleton-transformation face)) - (setq facemenu-end-add-face (concat "")) - (concat "<" face ">")) - (error "Face not configured for %s mode" mode-name))) - - -;;;###autoload -(define-derived-mode sgml-mode text-mode "SGML" - "Major mode for editing SGML documents. -Makes > match <. Makes / blink matching /. -Keys <, &, SPC within <>, \" and ' can be electric depending on -`sgml-quick-keys'. - -An argument of N to a tag-inserting command means to wrap it around -the next N words. In Transient Mark mode, when the mark is active, -N defaults to -1, which means to wrap it around the current region. - -If you like upcased tags, put (setq sgml-transformation 'upcase) in -your `.emacs' file. - -Use \\[sgml-validate] to validate your document with an SGML parser. - -Do \\[describe-variable] sgml- SPC to see available variables. -Do \\[describe-key] on the following bindings to discover what they do. -\\{sgml-mode-map}" - (sgml-mode-common) - (when sgml-xml (setq mode-name "XML")) - ;; Set `imenu-generic-expression' here, rather than in `sgml-mode-common', - ;; because this definition probably is not useful in HTML mode. + (set (make-local-variable 'comment-end-skip) "[ \t]*--\\([ \t\n]*>\\)?") + ;; This definition probably is not useful in derived modes. (set (make-local-variable 'imenu-generic-expression) "")) - ((or (and (eq v2 t) (not sgml-xml)) (string-match "^[/!?]" ,str)) + ((or (and (eq v2 t) (not sgml-xml-mode)) (string-match "^[/!?]" ,str)) nil) ((symbolp v2) ;; Make sure we don't fall into an infinite loop. @@ -869,7 +854,7 @@ (setq alist (cdr alist)) (if (stringp (car alist)) (insert "=\"" (car alist) ?\") - (if (and (eq (car alist) t) (not sgml-xml)) + (if (and (eq (car alist) t) (not sgml-xml-mode)) (when (cdr alist) (insert "=\"") (setq alist (skeleton-read '(completing-read "Value: " (cdr alist)))) @@ -1026,7 +1011,7 @@ ("rev" ,@rel) ("title"))) (list '((nil \n ("List item: " "
  • " str - (if sgml-xml "
  • ") \n)))) + (if sgml-xml-mode "") \n)))) (cell `(t ,@align ("valign" ,@valign) @@ -1040,7 +1025,7 @@ ("dir" ,@list) ("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7) ("form" (\n _ \n "" ">")) + (if sgml-xml-mode "/>" ">")) ("action" ,@(cdr href)) ("method" ("get") ("post"))) ("h1" ,@align) ("h2" ,@align) @@ -1062,13 +1047,13 @@ ("p" t ,@align) ("select" (nil \n ("Text: " - "") \n)) + "") \n)) ,name ("size" ,@1-9) ("multiple" t)) ("table" (nil \n ((completing-read "Cell kind: " '(("td") ("th")) nil t "t") "<" str ?> _ - (if sgml-xml (concat "<" str ">")) \n)) + (if sgml-xml-mode (concat "<" str ">")) \n)) ("border" t ,@1-9) ("width" "10") ("cellpadding")) ("td" ,@cell) ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9)) @@ -1081,7 +1066,7 @@ ("acronym") ("address") ("array" (nil \n - ("Item: " "" str (if sgml-xml "") \n)) + ("Item: " "" str (if sgml-xml-mode "") \n)) "align") ("au") ("b") @@ -1090,22 +1075,22 @@ ("blockquote" \n) ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#") ("link" "#") ("alink" "#") ("vlink" "#")) - ("box" (nil _ "" _ (if sgml-xml ""))) + ("box" (nil _ "" _ (if sgml-xml-mode ""))) ("br" t ("clear" ("left") ("right"))) ("caption" ("valign" ("top") ("bottom"))) ("center" \n) ("cite") ("code" \n) - ("dd" ,(not sgml-xml)) + ("dd" ,(not sgml-xml-mode)) ("del") ("dfn") ("div") ("dl" (nil \n ( "Term: " - "
    " str (if sgml-xml "
    ") - "
    " _ (if sgml-xml "
    ") \n))) - ("dt" (t _ (if sgml-xml "") - "
    " (if sgml-xml "
    ") \n)) + "
    " str (if sgml-xml-mode "
    ") + "
    " _ (if sgml-xml-mode "
    ") \n))) + ("dt" (t _ (if sgml-xml-mode "") + "
    " (if sgml-xml-mode "
    ") \n)) ("em") ;("fn" "id" "fn") ; ??? ("head" \n) @@ -1124,7 +1109,7 @@ ("isindex" t ("action") ("prompt")) ("kbd") ("lang") - ("li" ,(not sgml-xml)) + ("li" ,(not sgml-xml-mode)) ("math" \n) ("nobr") ("option" t ("value") ("label") ("selected" t)) @@ -1307,7 +1292,7 @@ outline-level (lambda () (char-before (match-end 0)))) (setq imenu-create-index-function 'html-imenu-index) - (when sgml-xml (setq mode-name "XHTML")) + (when sgml-xml-mode (setq mode-name "XHTML")) (set (make-local-variable 'sgml-empty-tags) '("br" "hr" "img" "input" "area" "link" "param" "col" "base" "meta" "basefont" "frame" "isindex" "wbr")) @@ -1396,44 +1381,44 @@ (define-skeleton html-horizontal-rule "HTML horizontal rule tag." nil - (if sgml-xml "
    " "
    ") \n) + (if sgml-xml-mode "
    " "
    ") \n) (define-skeleton html-image "HTML image tag." nil "" ">")) + (if sgml-xml-mode "/>" ">")) (define-skeleton html-line "HTML line break tag." nil - (if sgml-xml "
    " "
    ") \n) + (if sgml-xml-mode "
    " "
    ") \n) (define-skeleton html-ordered-list "HTML ordered list tags." nil "
      " \n - "
    1. " _ (if sgml-xml "
    2. ") \n + "
    3. " _ (if sgml-xml-mode "
    4. ") \n "
    ") (define-skeleton html-unordered-list "HTML unordered list tags." nil "") (define-skeleton html-list-item "HTML list item tag." nil (if (bolp) nil '\n) - "
  • " _ (if sgml-xml "
  • ")) + "
  • " _ (if sgml-xml-mode "
  • ")) (define-skeleton html-paragraph "HTML paragraph tag." nil (if (bolp) nil ?\n) - \n "

    " _ (if sgml-xml "

    ")) + \n "

    " _ (if sgml-xml-mode "

    ")) (define-skeleton html-checkboxes "Group of connected checkbox inputs." @@ -1446,11 +1431,11 @@ "\" value=\"" str ?\" (when (y-or-n-p "Set \"checked\" attribute? ") (funcall skeleton-transformation " checked")) - (if sgml-xml "/>" ">") + (if sgml-xml-mode "/>" ">") (skeleton-read "Text: " (capitalize str)) (or v2 (setq v2 (if (y-or-n-p "Newline after text? ") (funcall skeleton-transformation - (if sgml-xml "
    " "
    ")) + (if sgml-xml-mode "
    " "
    ")) ""))) \n)) @@ -1465,11 +1450,11 @@ "\" value=\"" str ?\" (when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? "))) (funcall skeleton-transformation " checked")) - (if sgml-xml "/>" ">") + (if sgml-xml-mode "/>" ">") (skeleton-read "Text: " (capitalize str)) (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ") (funcall skeleton-transformation - (if sgml-xml "
    " "
    ")) + (if sgml-xml-mode "
    " "
    ")) ""))) \n))