8

I've been using Emacs for quite a number of years now, but I only recently stumbled over the coding standards. There it is stated:

Don't make a habit of putting close-parentheses on lines by themselves; Lisp programmers find this disconcerting.

This is exactly the habit I've built up, since I find the code to be easier to read. I see mixed styles in the packages delivered with Emacs. My question is if this disconcert is common to most elisp programmers.

Edit: Looking at my code, I'm not strictly following this. Then the code would be quite horrible. It's mostly defun, let, if and so forth. But, it seems to be against the grain, so I should probably stop doing this. Cheers for the input.

(Borderline opinion based, but it seems related to closing braces in C++, where it shouldn't be controversial to state that they generally should be on their own lines).

closed as primarily opinion-based by paprika, nicael, Luke, Constantine, lunaryorn Dec 3 '14 at 13:03

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Not unacceptable, just really annoying:) – abo-abo Dec 2 '14 at 11:18
  • 4
    Think of it like a whitespace language, except brackets remove possible ambiguity - in well formatted lisp you should be able to read it without looking at the brackets – Squidly Dec 2 '14 at 11:26
  • 1
    I'm curious as to which packages delivered with emacs don't adhere to this. – Malabarba Dec 2 '14 at 12:49
  • 3
    @Malabarba A search with ag on the lisp sources gives me 3414 candidates for the ^\s*?\)$ regex which make up 468 files which belong to about 200 packages? – wasamasa Dec 2 '14 at 13:03
  • 1
    @wasamasa Good idea. I put that through a couple more pipes, and got that 90% of the .el files have less than 10 instances of this. Meaning these files don't adopt it as a style, they just use it at some convenient locations (like to finish off really long functions). – Malabarba Dec 2 '14 at 14:53
6

Well a short answer is "there is no need". As Emacs can parse the s-expressions of LISP it knows exactly where the forms balance out and can re-indent the code correctly. In this case putting moving a bracket down to it's own line simply wastes an extra line of space and at the same time is non-idomatic and jarring to other LISP programmers who are used to the canonical style. As has been mentioned in the comments this doesn't preclude you from using vertical white-space to visually separate chunks of code.

In practice a lot of Emacs using LISP programmers use a variety of additional visual cues like show-paren-mode that help navigating through a dense nest of closing parenthesis. Engineers that have subsumed modules like paredit and smart-parens into their editing cycle have become at one with the AST and are simply manipulating its structure directly in a way that expressions are always balanced and complete.

  • Of course I have parenthesis matching and so forth, but I think vertical space has a place in all code, and that is what this non-recommended habit brings. But a common style is always good, for anything public I would use the recommended way. But to turn it around, what value does the mass of parentheses at the end bring :). – Meaningful Username Dec 2 '14 at 14:21
  • 4
    You can always add vertical space; nothing says you have to smoosh each line up to the next. Sometimes vertical space is useful; sometimes it's not. Putting the parentheses at the end of the line lets you choose when to add vertical space and when not to. Parens on a new line forces vertical space, and a lot of it. – zck Dec 2 '14 at 14:33
  • @zck: I've updated the answer to mention your point. Thanks. – stsquad Dec 2 '14 at 16:30
  • Good point. I've started to change my code to conform to the standard. Not much difference, so should be quick to get used to. Guess I just felt the parentheses should be used for something, whereas most others seem to pretty much ignore 'em. – Meaningful Username Dec 2 '14 at 17:52
6

Riastradh's Lisp Style Guide elaborates a bit more on this specific topic. While he generally discourages from placing closing parentheses on their own line, he recognizes several exceptions, such as a previous line with a closing paren being commented out and really long lists that would otherwise constantly mess up diffs when adding new elements at their beginning or end.

1

I've been writing Elisp for about 2-3 years now. At first, I was doing the hanging parens thing, but since I've discovered the rule that you mentioned, I've started doing it myself. And I can say now that it's much easier to read the code when it's properly styled.

I even wrote some LISP prettifying code here: lispy-tab.

And, of course, I have show-paren-mode on all the time.

Not the answer you're looking for? Browse other questions tagged or ask your own question.