Function: web-mode-dom-errors-show

web-mode-dom-errors-show is an interactive and natively compiled function defined in web-mode.el.

Signature

(web-mode-dom-errors-show)

Documentation

Show unclosed tags.

Key Bindings

web-mode-map C-c C-d d

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-dom-errors-show ()
  "Show unclosed tags."
  (interactive)
  (let (beg end tag pos l tags i cont cell overlay overlays first
            (ori (point))
            (errors 0)
            (continue t)
            )
    (setq overlays (overlays-in (point-min) (point-max)))
    (when overlays
      (dolist (overlay overlays)
        (when (eq (overlay-get overlay 'face) 'web-mode-warning-face)
          (delete-overlay overlay)
          )
        )
      )
    (goto-char (point-min))
    (when (not (or (get-text-property (point) 'tag-beg)
                   (web-mode-tag-next)))
      (setq continue nil))
    (while continue
      (setq pos (point))
      (setq tag (get-text-property pos 'tag-name))
      (cond
        ((eq (get-text-property (point) 'tag-type) 'start)
         (setq tags (push (list tag pos) tags))
         ;;        (message "(%S) opening %S" pos tag)
         )
        ((eq (get-text-property (point) 'tag-type) 'end)
         (setq i 0
               l (length tags)
               cont t)
         (while (and (< i l) cont)
           (setq cell (nth i tags))
           ;;          (message "cell=%S" cell)
           (setq i (1+ i))
           (cond
             ((string= tag (nth 0 cell))
              (setq cont nil)
              )
             (t
              (setq errors (1+ errors))
              (setq beg (nth 1 cell))
              (setq end (web-mode-tag-end-position beg))
              (unless first
                (setq first beg))
              (setq overlay (make-overlay beg (1+ end)))
              (overlay-put overlay 'font-lock-face 'web-mode-warning-face)
              ;;            (message "invalid <%S> at %S" (nth 0 cell) (nth 1 cell))
              )
             ) ;cond
           ) ;while

         (dotimes (_i i)
           (setq tags (cdr tags)))

         )
        ) ;cond
      (when (not (web-mode-tag-next))
        (setq continue nil))
      ) ;while
    (message "%S error(s) detected" errors)
    (if (< errors 1)
        (goto-char ori)
        (goto-char first)
        (recenter))
    ;;    (message "%S" tags)
    ))