Function: web-mode-tag-fetch-opening

web-mode-tag-fetch-opening is a natively compiled function defined in web-mode.el.

Signature

(web-mode-tag-fetch-opening REGEXP POS)

Source Code

;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
(defun web-mode-tag-fetch-opening (regexp pos)
  (let ((counter 1) (n 0) (is-comment nil) (types '(start end)))
    (when (eq (aref regexp 1) ?\!)
      (setq types '(comment)
            is-comment t))
    (goto-char pos)
    (while (and (> counter 0) (re-search-backward regexp nil t))
      (when (and (get-text-property (point) 'tag-beg)
                 (member (get-text-property (point) 'tag-type) types))
        (setq n (1+ n))
        (cond
          ((and is-comment
                (eq (aref (match-string-no-properties 0) 5) ?e))
           (setq counter (1+ counter)))
          (is-comment
           (setq counter (1- counter)))
          ((eq (get-text-property (point) 'tag-type) 'end)
           (setq counter (1+ counter)))
          (t
           (setq counter (1- counter))
           )
          )
        )
      )
    (if (= n 0) (goto-char pos))
    ))