[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indentation with inline comments in Emacs

From: Taylan Kammer
Subject: Re: Indentation with inline comments in Emacs
Date: Sun, 17 Apr 2022 05:03:08 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

On 16.04.2022 14:12, Zelphir Kaltstahl wrote:
> Hello Guile users!
> The subject might not be only Guile related, but I figure, that many on this 
> mailing list are using Emacs for writing Guile code. I wonder, if anyone has 
> some trick for fixing the following indentation issue:
> Sometimes I want to put inline comments with #||# in things like lists, 
> arguments for function calls or vectors. For example I want to write the name 
> of the month next to the number of days of that month, in a vector creation. 
> Here is the example:
> ~~~~
> (define DAYS-IN-MONTH
>   #(#|January|# 31
>                 #|February|# 28
>                              #|March|# 31 #|April|# 30 #|May|# 31 #|June|# 30 
> #|July|# 31 #|August|# 30
>                               30 30))
> ~~~~
> As you can see, the indentation is adjusted each line according to the 
> non-comment thing on the previous line, when I press TAB or whatever other 
> key binding one has for indentation. However, in this case I would rather 
> want it to adjust indentation. Is there a quick fix for this? Or some way to 
> make Emacs understand this as a separate case and have it indent "correctly"? 
> Does anyone have a solution?
> Regards,
> Zelphir

To be honest, the easiest thing to do here is probably use a different comment 

In this particular example I would probably just go full vertical:

  (define DAYS-IN-MONTH
    #(31 ;january
      28 ;february
      31 ;march
      30 ;april
      31 ;may
      ;; ...

I know it doesn't fulfill your requirement, but usually I find it wise to use 
"path of least resistance" when it comes to how an editor/IDE wants to format 
and just go with the rules it has.  Makes life easier for others who might not 
whatever custom configuration you add to your editor to bend it to your will.


I've also tried out a "columns" variant with multiple numbers per row and a 
above each row identifying the numbers, but Emacs seems to insist on 
the first column in that case, regardless of comments, like this:

  (define days
    #(31      28       31
              30       31          30
              xx       yy          zz
              ;; ...

That's already ugly without comments, and IMO a significant issue.

Maybe it would be good to teach Emacs to indent lists/vectors that don't 
a function/macro call.  This indentation clearly assumes that the leading "31" 
the vector is the operator, and the rest of the vector operands.

It should probably not assume that for vectors #(...) and quoted lists '(...).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]