0

How can I adjust how M-; (comment-dwim) works in markdown-mode? Specifically, I'd like for it to not use delimiters for each line. As an example, in Markdown mode, if I commend a line like

This is a comment
that spans multiple lines

I get

<!-- This is a comment -->
<!-- that spans multiple lines -->

But I would prefer for it to look like

<!---
This is a comment
that spans multiple lines
--->

(web-mode does something similar to this, but also insists on indenting the comment, which seems unnecessary)

1 Answer 1

1

As a first approximation, try this:

(defun ndk/md-set-comment-stuff ()
   (setq-local comment-style 'extra-line)
   (setq-local comment-continue "")
   (setq-local comment-start "<!--")
   (setq-local comment-end "-->"))

(add-hook 'markdown-mode-hook #'ndk/md-set-comment-stuff)

You have to close and reopen the file after evaluating the above code.

It almost does what you want, but not quite. The result on the above is:

<!--
This is a comment
that spans multiple lines
  -->

The extra spaces are produced by comment-make-extra-lines: it sets the variable eindent to 2 in a section of the code that has the following comment above it:

;; Try to match CS and CE's content so they align aesthetically.

It seems to me that it fails to do that: I haven't looked at the algorithm in detail but it seems to align the dashes vertically. In any case, the value of eindent is used later on to add the two spaces to the left of the closing delimiter. Unfortunately, I see no obvious way of changing that behavior (other than changing the code of course, but that's a can of worms that I don't want to get into).

2
  • I'd also be happy with the <!-- on the same line as the comment if that ends up being easier to do.
    – asmeurer
    Apr 11, 2022 at 22:06
  • I don't think it's any easier.
    – NickD
    Apr 12, 2022 at 5:20

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.