web-mode
web-mode copied to clipboard
Consider making `web-mode-comment-insert` engine aware
When editing a handlebars buffer like this
(|
determines the current cursor position)
|
{{#if this.isOk}}
<p>Hello</p
{{/if}}
and then M-;
it inserts a <!-- -->
style comment, but I want {{!-- --}}
.
Looking at web-mode-comment-insert
, this could be added
(t
(cond
((string= web-mode-engine "ctemplate")
(insert "{{!-- --}}")
(search-backward "--}}"))
(progn
(insert "<!-- -->")
(search-backward " -->")))
) ;case html
in
(defun my-web-mode-comment-insert ()
(let ((alt nil) (pos 22) (web-mode-engine "ctemplate"))
(cond
((get-text-property pos 'block-side)
(cond
((and alt (string= alt "//"))
(insert "// "))
(t
(insert "/* */")
(search-backward " */"))
) ;cond
) ;case block-side
((get-text-property pos 'part-side)
(cond
((and alt (string= alt "//"))
(insert "// "))
(t
(insert "/* */")
(search-backward " */"))
) ;cond
) ;case part-side
(t
(cond
((string= web-mode-engine "ctemplate")
(insert "{{!-- --}}")
(search-backward "--}}"))
(progn
(insert "<!-- -->")
(search-backward " -->")))
) ;case html
) ;cond
))
I hard-coded the variables in the last code block to do a quick test. I also deleted references to language
since this was only used to print a message, which was commented out.
I see there is web-mode-comment-style
which could be used with web-mode-engine-alist
to loop through all the atoms and then compare to grab the match, to finally access web-mode-comment-style
to insert the comment according to its engine.
Thoughts?