Function: web-mode-element-is-opened

web-mode-element-is-opened is a natively compiled function defined in web-mode.el.

Signature

(web-mode-element-is-opened POS LIMIT)

Source Code

;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
;;TODO : prendre en compte part-token
;; state=t <=> start tag
(defun web-mode-element-is-opened (pos limit)
  (let (tag
        last-end-tag
        tag-pos block-pos
        state
        n
        ret
        (continue t)
        controls
        (h (make-hash-table :test 'equal))
        (h2 (make-hash-table :test 'equal)))

    ;;    (message "pos-ori=%S limit=%S" pos limit)

    (while continue
      (setq controls nil
            last-end-tag nil
            tag nil)

      (cond
        ((and (eq (get-text-property pos 'tag-type) 'comment)
              (web-mode-looking-at "<!--#\\(endif\\|if\\)" pos))
         ;;(message "pos=%S" pos)
         (setq tag "#if")
         (setq n (gethash tag h 0))
         (if (string= (match-string-no-properties 1) "if")
             (puthash tag (1+ n) h)
             (puthash tag (1- n) h))
         ;;(setq tag-pos pos)
         )
        ((get-text-property pos 'tag-beg)
         (when (member (get-text-property pos 'tag-type) '(start end))
           (setq tag (get-text-property pos 'tag-name)
                 state (eq (get-text-property pos 'tag-type) 'start))
           (if (null state) (setq last-end-tag (cons tag pos)))
           (setq n (gethash tag h 0))
           (cond
             ((null state)
              (when (> n 0) (puthash tag (1- n) h))
              (puthash tag (1- n) h2))
             ((member tag web-mode-offsetless-elements)
              )
             (t
              (puthash tag (1+ n) h)
              (puthash tag (1+ n) h2))
             ) ;cond
           ) ;when
         (when (setq pos (web-mode-tag-end-position pos))
           (setq tag-pos nil)
           (when (and block-pos (> pos block-pos))
             (setq block-pos nil))
           ) ;when
         )
        ((and web-mode-enable-control-block-indentation
              (get-text-property pos 'block-beg))
         (when (setq controls (web-mode-block-controls-get pos))
           (dolist (control controls)
             (setq tag (cdr control))
             (setq n (gethash tag h 0))
             (cond
               ((eq (car control) 'inside)
                )
               ((eq (car control) 'open)
                (puthash tag (1+ n) h))
               ((> n 0)
                (puthash tag (1- n) h))
               ) ;cond
             ) ;dolist
           )
         (when (setq pos (web-mode-block-end-position pos))
           (setq block-pos nil)
           (when (and tag-pos (> pos tag-pos))
             (setq tag-pos nil))
           )
         )
        ) ;cond

      ;;      (message "tag=%S end-pos=%S" tag pos)

      (when (and pos (< pos limit))
        (when (or (null tag-pos) (>= pos tag-pos))
          (setq tag-pos (web-mode-tag-next-position pos limit))
          ;;          (message "from=%S tag-next-pos=%S" pos tag-pos)
          )
        (when (or (null block-pos) (>= pos block-pos))
          (setq block-pos (web-mode-block-next-position pos limit))
          ;;          (message "from=%S block-next-pos=%S" pos block-pos)
          )
        )

      (cond
        ((null pos)
         )
        ((and (null tag-pos)
              (null block-pos))
         (setq pos nil))
        ((and tag-pos block-pos)
         (if (< tag-pos block-pos)
             (progn
               (setq pos tag-pos)
               (setq tag-pos nil))
             (setq pos block-pos)
             (setq block-pos nil))
         )
        ((null tag-pos)
         (setq pos block-pos)
         (setq block-pos nil))
        (t
         (setq pos tag-pos)
         (setq tag-pos nil))
        )

      (when (or (null pos)
                (>= pos limit))
        (setq continue nil))
      ) ;while

    ;;(message "hashtable=%S" h)
    (maphash (lambda (_k v) (if (> v 0) (setq ret t))) h)

    (when (and (null ret)
               last-end-tag
               (> (hash-table-count h2) 1)
               (< (gethash (car last-end-tag) h2) 0))
      ;;      (message "last-end-tag=%S" last-end-tag)
      (save-excursion
        (goto-char (cdr last-end-tag))
        (web-mode-tag-match)
        (when (not (= (point) (cdr last-end-tag)))
          (setq n (point))
          (back-to-indentation)
          (if (= n (point)) (setq ret (current-indentation))))
        ))

    ret))