Function: sgml-skip-tag-backward

sgml-skip-tag-backward is an interactive and byte-compiled function defined in sgml-mode.el.gz.

Signature

(sgml-skip-tag-backward ARG)

Documentation

Skip to beginning of tag or matching opening tag if present.

With prefix argument ARG, repeat this ARG times. Return non-nil if we skipped over matched tags.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/sgml-mode.el.gz
(defun sgml-skip-tag-backward (arg)
  "Skip to beginning of tag or matching opening tag if present.
With prefix argument ARG, repeat this ARG times.
Return non-nil if we skipped over matched tags."
  (interactive "p")
  ;; FIXME: use sgml-get-context or something similar.
  (let ((return t))
    (while (>= arg 1)
      (search-backward "<" nil t)
      (if (looking-at "</\\([^ \n\t>]+\\)")
          ;; end tag, skip any nested pairs
          (let ((case-fold-search t)
                (re (concat "</?" (regexp-quote (match-string 1))
                            ;; Ignore empty tags like <foo/>.
                            "\\([^>]*[^/>]\\)?>")))
            (while (and (re-search-backward re nil t)
                        (eq (char-after (1+ (point))) ?/))
              (forward-char 1)
              (sgml-skip-tag-backward 1)))
        (setq return nil))
      (setq arg (1- arg)))
    return))