0

I don't mind if the occasional code line runs long. For example, the Shopify ruby standard allows lines of 120. But I want comments to be restricted to the first 78 lines or so. Is there any way in a programming major mode to have a different fill column for comment lines than for code line?

2
  • Not that I know of. But it's easy to just C-x f to change the fill-column here or there. Then M-q to re-fill. Commented Sep 11, 2020 at 22:31
  • What are fill-paragraph-function and fill-forward-paragraph-function set to? Emacs actually has some logic for filling comments differently than the code, but it may not be relevant in your case, if ruby-mode overrides the default behavior (which it probably does). Anyways, my approach would be to look for ruby-mode's function to fill paragraph, and see if it is possible to extend / replace it with something of your own design that deals with comments the way you want. Commented Sep 13, 2020 at 6:58

2 Answers 2

0

OK. With some prodding from @wvxvw, I looked at some source code, though the code for fill-paragraph rather than ruby-mode. There is a function for filling comments, but it does not take a fill-column parameter. So, I tried the following advice, which appears to do the trick:

 (defvar ded:fill-column-for-progs 78) (defun ded:prog-fill-paragraph (orig-fun &rest args) (let ((fill-column ded:fill-column-for-progs)) (apply orig-fun args))) (advice-add 'fill-comment-paragraph :around #'ded:prog-fill-paragraph) 

The ded: is just my personal prefix. So far, so good. It even uses justification when used with the universal argument.

0

Just a quick note to save others time: for c-mode, I had to apply this to c-fill-paragraph instead of fill-comment-paragaph.

(defun my-comment-fill-paragraph (orig-fun &rest args) (let ((fill-column 72)) (apply orig-fun args))) (advice-add 'c-fill-paragraph :around #'my-comment-fill-paragraph) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.