Function: web-mode-element-close
web-mode-element-close is an interactive and natively compiled
function defined in web-mode.el.
Signature
(web-mode-element-close)
Documentation
Close html element.
Key Bindings
web-mode-map C-c C-e /
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-element-close ()
"Close html element."
(interactive)
(let (jmp epp ins tag)
(if (and (eq (char-before) ?\>)
(web-mode-element-is-void (get-text-property (1- (point)) 'tag-name)))
(unless (eq (char-before (1- (point))) ?\/)
(backward-char)
(insert "/")
(forward-char))
(setq epp (web-mode-element-parent-position)))
;;(message "epp=%S" epp)
(when epp
(setq tag (get-text-property epp 'tag-name))
(setq tag (web-mode-element-tag-name epp))
;;(message "tag=%S %c" tag (char-before))
(cond
((or (null tag) (web-mode-element-is-void tag))
(setq epp nil))
((looking-back "</" (point-min))
(setq ins tag))
((looking-back "<" (point-min))
(setq ins (concat "/" tag)))
(t
;;auto-close-style = 2
;;(message "%S %c" (point) (char-after))
(when (and (looking-at-p "[[:alpha:]]") (> (length tag) 4))
(dolist (elt '("div" "span" "strong" "pre" "li"))
(when (and (string-match-p (concat "^" elt) tag) (not (string= tag elt)))
(setq tag elt)
(put-text-property epp (point) 'tag-name tag))
)
) ;when
(if (web-mode-element-is-void (get-text-property (point) 'tag-name))
(setq ins nil
epp nil)
(setq ins (concat "</" tag)))
)
) ;cond
(when ins
(unless (looking-at-p "[ ]*>")
(setq ins (concat ins ">")))
(insert ins)
(setq tag (downcase tag))
(save-excursion
(search-backward "<")
(setq jmp (and (eq (char-before) ?\>)
(string= (get-text-property (1- (point)) 'tag-name) tag)))
(if jmp (setq jmp (point)))
) ;save-excursion
(if jmp (goto-char jmp))
) ;when not ins
) ;when epp
epp))