Function: sgml-quote

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

Signature

(sgml-quote START END &optional UNQUOTEP)

Documentation

Quote SGML text in region START ... END.

Only &, <, >, ' and " characters are quoted, the rest is left untouched. This is sufficient to use quoted text as SGML argument.

With prefix argument UNQUOTEP, unquote the region. All numeric entities,
"amp", "lt", "gt" and "quot" named entities are unquoted.

Probably introduced at or before Emacs version 27.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/sgml-mode.el.gz
(defun sgml-quote (start end &optional unquotep)
  "Quote SGML text in region START ... END.
Only &, <, >, ' and \" characters are quoted, the rest is left
untouched.  This is sufficient to use quoted text as SGML argument.

With prefix argument UNQUOTEP, unquote the region.  All numeric entities,
\"amp\", \"lt\", \"gt\" and \"quot\" named entities are unquoted."
  (interactive "r\nP")
  (save-restriction
    (narrow-to-region start end)
    (goto-char (point-min))
    (if unquotep
	;; FIXME: We should unquote other named character references as well.
	(while (re-search-forward
		"\\(&\\(amp\\|quot\\|lt\\|gt\\|#\\([0-9]+\\|[xX][[:xdigit:]]+\\)\\)\\)\\([][<>&;\n\t \"%!'(),/=?]\\|$\\)"
		nil t)
          (replace-match
           (string
            (or (cdr (assq (char-after (match-beginning 2))
                           '((?a . ?&) (?q . ?\") (?l . ?<) (?g . ?>))))
                (let ((num (match-string 3)))
                  (if (or (eq ?x (aref num 0)) (eq ?X (aref num 0)))
                      (string-to-number (substring num 1) 16)
                    (string-to-number num 10)))))
           t t nil (if (eq (char-before (match-end 0)) ?\;) 0 1)))
      (while (re-search-forward "[&<>\"']" nil t)
	(replace-match (cdr (assq (char-before) '((?& . "&amp;")
						  (?< . "&lt;")
						  (?> . "&gt;")
                                                  (?\" . "&#34;")
                                                  (?' . "&#39;"))))
		       t t)))))