Function: sgml-mode

sgml-mode is an autoloaded, interactive and byte-compiled function defined in sgml-mode.el.gz.

Signature

(sgml-mode)

Documentation

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-function 'upcase) in your init file.

Use M-x sgml-validate (sgml-validate) to validate your document with an SGML parser.

Do C-h v (describe-variable) sgml- SPC to see available variables. Do C-h k (describe-key) on the following bindings to discover what they do.
/ sgml-slash
C-c / sgml-close-tag
C-c 8 sgml-name-8bit-mode(var)/sgml-name-8bit-mode(fun)
C-c <left> sgml-skip-tag-backward
C-c <right> sgml-skip-tag-forward
C-c ? sgml-tag-help(var)/sgml-tag-help(fun)
C-c C-a sgml-attributes
C-c C-b sgml-skip-tag-backward
C-c C-d sgml-delete-tag
C-c C-e sgml-close-tag
C-c C-f sgml-skip-tag-forward
C-c C-n sgml-name-char
C-c C-o sgml-tag
C-c C-t sgml-tag
C-c C-v sgml-validate
C-c DEL sgml-delete-tag
C-c TAB sgml-tags-invisible(var)/sgml-tags-invisible(fun)
C-c ] sgml-close-tag
Ā..\x3FFFFF sgml-maybe-name-self

In addition to any hooks its parent mode text-mode might have run, this mode runs the hook sgml-mode-hook, as the final or penultimate step during initialization.

View in manual

Probably introduced at or before Emacs version 19.31.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/sgml-mode.el.gz
;;;###autoload
(define-derived-mode sgml-mode text-mode '(sgml-xml-mode "XML" "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-function \\='upcase)
in your init 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)
  ;; If encoding does not allow non-break space character, use reference.
  ;; FIXME: Perhaps use &nbsp; if possible (e.g. when we know its HTML)?
  (setq-local tildify-space-string
              (if (equal (decode-coding-string
                          (encode-coding-string " " buffer-file-coding-system)
                          buffer-file-coding-system)
                         " ")
                  " " "&#160;"))
  ;; FIXME: Use the fact that we're parsing the document already
  ;; rather than using regex-based filtering.
  (setq-local tildify-foreach-region-function
              (apply-partially
               'tildify-foreach-ignore-environments
               `((,(concat
                    "<\\("
                    (regexp-opt '("pre" "dfn" "code" "samp" "kbd" "var"
                                  "PRE" "DFN" "CODE" "SAMP" "KBD" "VAR"))
                    "\\)\\>[^>]*>")
                  . ("</" 1 ">"))
                 ("<! *--" . "-- *>")
                 ("<" . ">"))))
  ;;(make-local-variable 'facemenu-remove-face-function)
  ;; 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.
  (setq-local paragraph-start (concat "[ \t]*$\\|\
\[ \t]*</?\\(" sgml-name-re sgml-attrs-re "\\)?>"))
  (setq-local paragraph-separate (concat paragraph-start "$"))
  (setq-local adaptive-fill-regexp "[ \t]*")
  (add-hook 'fill-nobreak-predicate #'sgml-fill-nobreak nil t)
  (setq-local indent-line-function #'sgml-indent-line)
  (setq-local comment-start "<!-- ")
  (setq-local comment-end " -->")
  (setq-local comment-indent-function #'sgml-comment-indent)
  (setq-local comment-line-break-function #'sgml-comment-indent-new-line)
  (setq-local skeleton-further-elements '((completion-ignore-case t)))
  (setq-local skeleton-end-newline nil)
  (setq-local skeleton-end-hook
	      (lambda ()
		(or (eolp)
		    (not (or (eq v2 '\n) (eq (car-safe v2) '\n)))
		    (newline-and-indent))))
  (setq font-lock-defaults '((sgml-font-lock-keywords
			      sgml-font-lock-keywords-1
			      sgml-font-lock-keywords-2)
                             nil t nil
                             (font-lock-syntactic-face-function
                              . sgml-font-lock-syntactic-face)))
  (setq-local syntax-propertize-function #'sgml-syntax-propertize)
  (setq-local syntax-ppss-table sgml-tag-syntax-table)
  (setq-local facemenu-add-face-function #'sgml-mode-facemenu-add-face-function)
  (when (sgml-xml-guess)
    (setq-local sgml-xml-mode t))
  (unless sgml-xml-mode
    (setq-local skeleton-transformation-function sgml-transformation-function))
  ;; This will allow existing comments within declarations to be
  ;; recognized.
  ;; I can't find a clear description of SGML/XML comments, but it seems that
  ;; the only reliable ones are <!-- ... --> although it's not clear what
  ;; "..." can contain.  It used to accept -- ... -- as well, but that was
  ;; apparently a mistake.
  (setq-local comment-start-skip "<!--[ \t]*")
  (setq-local comment-end-skip "[ \t]*--[ \t\n]*>")
  ;; This definition has an HTML leaning but probably fits well for other modes.
  (setq imenu-generic-expression
	`((nil
	   ,(concat "<!\\(element\\|entity\\)[ \t\n]+%?[ \t\n]*\\("
		    sgml-name-re "\\)")
	   2)
	  ("Id"
	   ,(concat "<[^>]+[ \t\n]+[Ii][Dd]=\\(['\"]"
		    (if sgml-xml-mode "" "?")
		    "\\)\\(" sgml-name-re "\\)\\1")
	   2)
	  ("Name"
	   ,(concat "<[^>]+[ \t\n]+[Nn][Aa][Mm][Ee]=\\(['\"]"
		    (if sgml-xml-mode "" "?")
		    "\\)\\(" sgml-name-re "\\)\\1")
	   2)))
  (setq-local hs-block-start-regexp "<[^/>]*?")
  (setq-local hs-block-end-regexp "</[^/>]*[^/]>")
  (setq-local hs-c-start-regexp "<!--")
  (setq-local hs-forward-sexp-function #'sgml-skip-tag-forward))