3

When commenting C-style code like C++, JavaScript etc., I use single-line comments to be able to uncomment a previously commented region selectively, i.e

// This 
// is
// a single-line style
// comment

If I later want to uncomment lines 2 and 3, for example, I would simply select them and uncomment. With multi-line comments /* */, however, I would first need to uncomment the whole block, then selectively comment the parts excluding those that I wanted to uncomment in the first place. From this question, I found out that I can change the comment character to // by putting in my config

(setq-default web-mode-comment-formats (remove '("javascript" . "/*") web-mode-comment-formats))
(add-to-list 'web-mode-comment-formats '("javascript" . "//"))

This, however, does not change the commenting behavior of web-mode. When I select the desired region and run web-mode-comment-or-uncomment-region, it still exhibits multi-line behavior and uncomments the whole block instead of the region that I select.

How can I uncomment just the selected region instead of the whole block?

1 Answer 1

0

It could be that web-mode-comment-formats is not defined when emacs is initialized and thus removes nothing from it at that stage, in my case web-mode is loaded only on demand so trying to customize it at that point doesn't make sense. Try to do that customization in a web-mode-hook or set explicitly the values you need in that list:

(setq web-mode-comment-formats '(("typescript" . "//")
                                 ("javascript" . "//")
                                 ("java" . "//"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.