Is Allman/BSD indentation style supported? #20
Replies: 5 comments 10 replies
-
Hello @pierre-rouleau, Regarding indentation, I would recommend to try the version of cperl-mode.el which comes with Emacs 30. It is available from the Emacs repository and also from the "upstream" branch in this repository. In cperl-mode, you can select between different indentation styles. Currently the style as defined by Damian Conway in the book "Perl Best Practices" is probably the most popular one. Selecting a style can be done globally with the command So far I have never used BSD indentation and can't comment on whether the "BSD" style fits the Allman recommendation. In any case, the way to adjust it to your expectations would be to tune the values of |
Beta Was this translation helpful? Give feedback.
-
The "upstream" version of this repository will go into Emacs 30, but work with 27 and newer. I found that Regarding the indentation: Do you have a recipe to reproduce the unwanted reformatting? As far as I see cperl-mode does not reformat subroutine headings at all: It leaves braces where they were. There are, however, separate customization options Regarding the BTWs: Most of the indentation code is old and has dark corners I do not fully understand. I wrote some tests for the PBP style when I added it - but have not touched the other styles: I do not know the expected behavior well enough. |
Beta Was this translation helpful? Give feedback.
-
Hi @HaraldJoerg , my impression of the cperl code implementation and its support for the various indentation style was done when styles were not as formally named and crystallized as they are today (although it'll probably remain a moving target as new programming languages come up). I'm guessing that the cperl code is probably missing variables to describe some aspects of some styles, as the focus was probably always what is most popular and described in Perl books: K&R derived style. So I though I would start by putting example of all styles together quickly and identify the various aspects of these styles, mapping them to the existing cperl variable/user-options to see if there are any missing. Once the analysis completed I would probably look at adding documentation of the various styles and building test code for them. And then adding the required code once I understand better the cperl code. For now, I started documenting the styles in a PDF file built as a table part of my system and using the same mechanism I already use: https://raw.githubusercontent.com/pierre-rouleau/pel/master/doc/pdf/lang/indentation-styles.pdf . I know, ideally this would be written in a markup language (I would probably use reStructuredText) but for the other PDF pages I wrote for my projects there's just too much markup and I did not find any markup that allowed me to express everything I use, so I ended up using macOS Numbers to create the tables. I will use that to perform the analysis and will then check if extra variables are required to express the various styles. |
Beta Was this translation helpful? Give feedback.
-
Hi @HaraldJoerg ,
Would you agree if I re-ordered them? I'm also thinking of adding one new variable, The #21 PR includes the described changes. I see that test fail on those but it seems to be caused by other aspects of the master branch code I assume you have fixed in the code in the branch for Emacs 30. Note that currently this probably applies globally, to all cperl-mode buffers. I wonder if it would not also be a good idea to provide the ability to control the style per buffer. But that would be for later. |
Beta Was this translation helpful? Give feedback.
-
@HaraldJoerg I have a question related to the upstream version of the code and the default value of `cperl-file-style'.
My questions:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @HaraldJoerg, thanks for writing this!
Is cperl-mode currently supporting the Allman/BSD indentation style?
I realize that K&R indentation style is the norm/preferred/PBP style, but I need to edit code that uses Allman/BSD style and don't want to modify it when I reformat some code using cperl commands such as
cperl-indent-exp
.I could use perltidy integration but I want to prevent having formatting bouncing back and forth beween the K&R style and the Allman/BSD style when I have to edit old code that uses Allman/BSD style.
If this is not supported, do you have a suggestion as to best support it? I'm starting to look at the elisp code and if it is not supported I would like to add the ability to support it. I would add some new user-option, allowing customization to select between the K&R (default) and Allman/BSD.
Beta Was this translation helpful? Give feedback.
All reactions