Function: nxml-scan-element-backward
nxml-scan-element-backward is a byte-compiled function defined in
nxml-rap.el.gz.
Signature
(nxml-scan-element-backward FROM &optional UP BOUND)
Documentation
Scan backward from FROM over a single balanced element.
Point must be between tokens. Return the position of the end of
the tag that starts the element. xmltok-start will contain the
position of the start of the tag. If UP is non-nil, then scan
past start-tag of element containing point. If BOUND is non-nil,
then don't scan back past BOUND. If no element is found, return
nil. If a well-formedness error prevents scanning, signal an
nxml-scan-error. Point is not moved.
Source Code
;; Defined in /usr/src/emacs/lisp/nxml/nxml-rap.el.gz
(defun nxml-scan-element-backward (from &optional up bound)
"Scan backward from FROM over a single balanced element.
Point must be between tokens. Return the position of the end of
the tag that starts the element. `xmltok-start' will contain the
position of the start of the tag. If UP is non-nil, then scan
past start-tag of element containing point. If BOUND is non-nil,
then don't scan back past BOUND. If no element is found, return
nil. If a well-formedness error prevents scanning, signal an
`nxml-scan-error'. Point is not moved."
(let ((open-tags (and up t))
token-end found)
(save-excursion
(goto-char from)
(while (cond ((or (< (point) nxml-prolog-end)
(not (search-backward "<"
(max (or bound 0)
nxml-prolog-end)
t)))
(when (and (consp open-tags) (not bound))
(nxml-scan-error (cadr open-tags)
"End-tag has no start-tag"))
nil)
((progn
(nxml-move-outside-backwards)
(save-excursion
(nxml-tokenize-forward)
(setq token-end (point)))
(eq xmltok-type 'end-tag))
(setq open-tags
(cons (xmltok-end-tag-qname)
(cons xmltok-start open-tags)))
t)
((eq xmltok-type 'start-tag)
(cond ((not open-tags) nil)
((not (consp open-tags))
(setq found token-end)
nil)
((and (car open-tags)
(not (string= (car open-tags)
(xmltok-start-tag-qname))))
(nxml-scan-error (1+ xmltok-start)
"Mismatched start-tag; \
expected `%s'"
(car open-tags)))
((setq open-tags (cddr open-tags)) t)
(t (setq found token-end) nil)))
((memq xmltok-type '(empty-element
partial-empty-element))
(if open-tags
t
(setq found token-end)
nil))
((eq xmltok-type 'partial-end-tag)
(setq open-tags
(cons nil (cons xmltok-start open-tags)))
t)
((eq xmltok-type 'partial-start-tag)
;; if we have only a partial-start-tag
;; then it's unlikely that there's a matching
;; end-tag, so it's probably not helpful
;; to treat it as a complete start-tag
(nxml-scan-error xmltok-start
"Missing `>'"))
(t t))))
found))