Function: web-mode-uncomment

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

Signature

(web-mode-uncomment 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-uncomment (pos)
  (let ((beg pos) (end pos) (sub2 "") comment boundaries)
    (save-excursion
      (cond
        ((and (get-text-property pos 'block-side)
              (intern-soft (concat "web-mode-uncomment-" web-mode-engine "-block")))
         (funcall (intern (concat "web-mode-uncomment-" web-mode-engine "-block")) pos))
        ((and (setq boundaries (web-mode-comment-boundaries pos))
              (setq beg (car boundaries))
              (setq end (1+ (cdr boundaries)))
              (> (- end beg) 4))
         (when (and (eq (get-text-property beg 'part-token) 'comment)
                    (> beg 1) ;#1158
                    (get-text-property (1- beg) 'jsx-beg))
           (setq beg (1- beg)
                 end (1+ end)))
         (setq comment (buffer-substring-no-properties beg end))
         (setq sub2 (substring comment 0 2))
         (cond
           ((member sub2 '("<!" "<%"))
            (setq comment (replace-regexp-in-string "\\(^<[!%]--[ ]?\\|[ ]?--[%]?>$\\)" "" comment)))
           ((string= sub2 "{#")
            (setq comment (replace-regexp-in-string "\\(^{#[ ]?\\|[ ]?#}$\\)" "" comment)))
           ((string= sub2 "{/") ;jsx comments
            (setq comment (replace-regexp-in-string "\\(^{/\\*[ ]?\\|[ ]?\\*/}$\\)" "" comment)))
           ((string= sub2 "/*")
            ;;(message "%S" comment)
            ;;(setq comment (replace-regexp-in-string "\\(\\*/\\|^/\\*[ ]?\\|^[ \t]*\\*\\)" "" comment))
            (setq comment (replace-regexp-in-string "\\([ ]?\\*/$\\|^/\\*[ ]?\\)" "" comment))
            (setq comment (replace-regexp-in-string "\\(^[ \t]*\\*\\)" "" comment))
            ;;(message "%S" comment)
            )
           ((string= sub2 "''")
            (setq comment (replace-regexp-in-string "''" "" comment)))
           ((string= sub2 "//")
            (setq comment (replace-regexp-in-string "^ *//" "" comment)))
           ) ;cond
         (delete-region beg end)
         (web-mode-insert-and-indent comment)
         (goto-char beg)
         )
        ) ;cond
      (indent-according-to-mode)
      )))