TransWikia.com

Different fill-column for comments than code in programming modes

Emacs Asked by Daniel Doherty on February 5, 2021

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?

One Answer

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.

Answered by Daniel Doherty on February 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP