It compares the indentation to the parentheses, and complains if they don't agree. It doesn't care about indentation amount (like I-expressions/Wisp/etc.), only that lines following some opened parens get indented more; lines following some closed parens get indented less; and sibling lines are indented the same amount.
I find this much more accurate at spotting the cause of a problem, compared to simply counting whether the openers and closers balance; e.g. the latter will only spot a missing close parenthesis when it reaches the end of the file. This is especially useful for LLMs, which are terrible at counting parentheses.
Unfortunately, there can be some cases where an auto-indenter (e.g. elisp-autofmt) causes parenmedic to complain. One remedy is to alter the auto-indenter's behaviour by inserting a line-comment; but it's not ideal.
I wonder whether Sift would (knowingly or unknowingly) adhere to the rules parenmedic requires?
[3 hidden]5 mins ago
It's fairly common in agentic work with lisps to use the OG of indentation-implies-parens, parinfer. https://github.com/parinfer
It's a little disappointing to not see a credit for it in parenmedic. The agentic interface looks interesting though.
[3 hidden]5 mins ago
Am I getting paranoid or does this text read very LLMish?
[3 hidden]5 mins ago
It's true it's produced by LLM, after my initial sketch/draft and many correction rounds. I just gave it a full revamp to the blog post, with more natural wording and succinter. Apologies for this
[3 hidden]5 mins ago
You need to stop reading things and get your agent to read them for you.
[3 hidden]5 mins ago
Inverse compression once again!
[3 hidden]5 mins ago
It's 100% AI. The formatter is also AI. I wonder if the AI cares about formatting.
It's always interesting to me when the people who have given up on writing code build tools around it. It seems like some form of inertia, performing a pointless ritual because it feels right to them.
I wonder what goes through their minds as they build tools to enable things that they no longer do.
[3 hidden]5 mins ago
What an interesting take. I hadn't looked at it that way.
I’ve only vibe coded tools I’ve needed, used, or wanted to play with. And the vast majority were “disposable artefacts”.
However, my guess is people always wanted X. They didn't have the skill or time to build it so now they pull it from the aether to finally see it exist. Then, they themselves dont use it (or need it) so it just fades away.
I think you've hit on why the trend of “everyone can build an app, so no one really cares about your app” is happening.
[3 hidden]5 mins ago
This tool is already helping humans and LLMs alike. It also helps steer towards best practices, consistent style, etc. I understand you might see this as a slop project, I can ensure you after daily driving Sift for a whole month already I can attest to the polish in the project. But curious if you try it, what you think about it.
[3 hidden]5 mins ago
I wanted to make a Lua like language that was inspired by Rebol and Smalltalk and unified tables with functions. I wanted this for twenty years. Now Claude code writes in my custom language and it makes me smile.
[3 hidden]5 mins ago
It's also funny because anyone who actually wrote Lisp would find this bizarrely solving no problem.
Emacs already formats its own Lisp, so does all self-respecting Common Lisp editor/plugin. And they use precise information from the Lisp image (such as lambda list of user-defined macro), no need to reinvent a whole parser that only has worse information.
[3 hidden]5 mins ago
Absolutely the latter, though that doesn’t mean that you aren’t also getting paranoid.
[3 hidden]5 mins ago
Nowadays I auto-assume LLM slop text.
[3 hidden]5 mins ago
I tried to nail down ubiiquitous formatting for a typed nl-like sexpr language I have been mostly vibe coding.
It is surprisingly hard. I ended up mostly copying the algorithm that can be used through raco (the racket command line tool). It is not particularly fast, only about 10lines of code per core-second, but it produces a good enough result. I had to leave some things to the user, but only about 5 forms.
[3 hidden]5 mins ago
I've been tinkering with common lisp again lately (via VSCode) and I've been looking for something like this! Going to play with it this weekend.
[3 hidden]5 mins ago
OLIVE format using precise information from the CL image, why you need something like this?
[3 hidden]5 mins ago
Lisp people: Look at the elegance and simplicity of S-expressions! Isn't it a beauty?
Also Lisp people: Here is a thesis-sized article about formatting them properly O:)
[3 hidden]5 mins ago
From TFA: In the Lisp world the answer is usually “my editor does it”
And that's where the story ends for most of us. Author's set-up seems to have had CI tools fighting the editor. Most of us would have disabled the misguided CI auto-formatter ...
[3 hidden]5 mins ago
Actually, due to the Lisp syntax, code formatting is usually a non-issue. It is mostly reduced to correct indenting, where a common style had been established very early on in the language history - which means really long ago.
All editors, which are Lisp-aware usually do it very well.
The problem remaining is, that there are editors around, which are not Lisp aware and to my continuing confusion, lots of users, which use them. So there is from time to time the requirement to predictably reformat source files. Of course, also helps a lot with automatic generated code. Just feed it to the formatter. I wrote a tool comparable to gofmt some time ago and it is very helpful.
For example, how should this Emacs Lisp code be formatted?
(foo
bar
baz
quux)
According to Emacs (definitely a "Lisp-aware editor"), it depends on the definition of `foo`! If `foo` is a macro, it can use `(declare (indent ...))` to specify how its use-sites should be indented. If `foo` happens to be a function, or a macro which doesn't use `(declare (indent ...))`, then Emacs will indent it as above. However, if it's defined like this:
So, at the very least, a "Lisp-aware" formatter would need to resolve names, traverse load paths, etc. to find out whether each call is actually a macro, and whether the definition of such a macro declares an indent rule.
With a definition like that, Emacs will choose how much indentation to use by calling the `uh-oh` function! That makes indentation of Emacs Lisp undecidable!
[3 hidden]5 mins ago
That specific example would always be
(foo
bar
baz
quux)
Once we separate even the first argument on its own line, we have made clear that that is where the division is, and given up on more detail: it's some kind of operator with arguments.
If the list is quoted then:
'(foo
bar
baz
quux)
The ambiguity is if you have this:
(foo bar
... )
If foo is a function
(foo bar
baz
quux)
If it is a macro with a trailing body of forms ("implicit progn" in CL parlance) then we don't know, without the macro definition, how many of the initial arguments are not part of those forms:
(foo bar
baz
quux)
or
(foo bar
baz
quux)
or
(foo bar
baz
quux)
A good solution to all this is parinfer: specifically indent -> parens mode. That is to say, manually or semi-automatically control indent, and let parentheses be inferred.
The above issues are all symptoms of the assumption that the programmer controls parentheses, leaving the indentation to be figured out.
But parentheses are the aspect of the code that can only be one way, whereas indentation has latitudes that mean nothing to the machine but visually indicate semantics.
So, switch roles: let the machine deal with the parentheses. Then there is no problem to be solved whatsoever that requires declaration info or execution of functions.
The downside is that if we have a correct inference from parentheses to indentation, it can help to spot errors. For instance, if you write:
(pattern-match pattern
body1
body2)
and the indentation jumps to this:
(pattern-match pattern
body1
body2)
then you have an instant reminder that you forgot to write the expression to be analyzed by the pattern, causing your first body form to be interpreted as that.
To me, that is minor, and I'm willing to throw it under the bus by controlling indentation.
Parens inference from indentation is not perfect, though! This is illustrated best by cond. If you have a cond clause like this:
((condition ...)
form
form)
parinfer wants to do this:
((condition
form
form))
because the forms are indented, they are assumed to be constituents of the condition expression. The fix for that is to just learn to embrace:
(cond
((condition)
form
form)
((condition)
form
form))
Only problem with that is working with your legacy code where you have the indentation.
[3 hidden]5 mins ago
From the article:
> Lisp is a tree of nested lists. The language knows it, and most of the tooling around it pretends otherwise (some with nasty regex magic too).
This was my experience with Clojure too. A lot of "tooling is super easy because it's all lists and code are data structures" and in practice the tooling wasn't there. At all.
[3 hidden]5 mins ago
sad but true
[3 hidden]5 mins ago
i once have written a lisp parser for some static analysy tool. in the end i read the code backwards, nade things more easy. cant rember why
[3 hidden]5 mins ago
that's quite an interesting thought
[3 hidden]5 mins ago
Question for the author: how does Sift decide indentation for user-defined macros? Since the right layout for a form like `with-foo` or `my-let` depends on how it is defined (body-style vs. plain call), I'd be curious whether you ship a fixed table of known forms, read indent hints from the source, or let users configure it per project. For a formatter that runs in CI, I'd guess predictability matters more than being perfectly right for every macro.
[3 hidden]5 mins ago
It's all three, in a fixed precedence order, plus a name-shape guess as the last resort. The chain is in `list-indent` in `src/sift/format.scm` (~L895).
On your CI point: yes, that's the stated priority. Nothing is inferred from how a form is used, there's no scanning of other files or dependencies, and the result is idempotent.
It compares the indentation to the parentheses, and complains if they don't agree. It doesn't care about indentation amount (like I-expressions/Wisp/etc.), only that lines following some opened parens get indented more; lines following some closed parens get indented less; and sibling lines are indented the same amount.
I find this much more accurate at spotting the cause of a problem, compared to simply counting whether the openers and closers balance; e.g. the latter will only spot a missing close parenthesis when it reaches the end of the file. This is especially useful for LLMs, which are terrible at counting parentheses.
Unfortunately, there can be some cases where an auto-indenter (e.g. elisp-autofmt) causes parenmedic to complain. One remedy is to alter the auto-indenter's behaviour by inserting a line-comment; but it's not ideal.
I wonder whether Sift would (knowingly or unknowingly) adhere to the rules parenmedic requires?
It's a little disappointing to not see a credit for it in parenmedic. The agentic interface looks interesting though.
It's always interesting to me when the people who have given up on writing code build tools around it. It seems like some form of inertia, performing a pointless ritual because it feels right to them.
I wonder what goes through their minds as they build tools to enable things that they no longer do.
I’ve only vibe coded tools I’ve needed, used, or wanted to play with. And the vast majority were “disposable artefacts”.
However, my guess is people always wanted X. They didn't have the skill or time to build it so now they pull it from the aether to finally see it exist. Then, they themselves dont use it (or need it) so it just fades away.
I think you've hit on why the trend of “everyone can build an app, so no one really cares about your app” is happening.
Emacs already formats its own Lisp, so does all self-respecting Common Lisp editor/plugin. And they use precise information from the Lisp image (such as lambda list of user-defined macro), no need to reinvent a whole parser that only has worse information.
It is surprisingly hard. I ended up mostly copying the algorithm that can be used through raco (the racket command line tool). It is not particularly fast, only about 10lines of code per core-second, but it produces a good enough result. I had to leave some things to the user, but only about 5 forms.
Also Lisp people: Here is a thesis-sized article about formatting them properly O:)
And that's where the story ends for most of us. Author's set-up seems to have had CI tools fighting the editor. Most of us would have disabled the misguided CI auto-formatter ...
The problem remaining is, that there are editors around, which are not Lisp aware and to my continuing confusion, lots of users, which use them. So there is from time to time the requirement to predictably reformat source files. Of course, also helps a lot with automatic generated code. Just feed it to the formatter. I wrote a tool comparable to gofmt some time ago and it is very helpful.
For example, how should this Emacs Lisp code be formatted?
According to Emacs (definitely a "Lisp-aware editor"), it depends on the definition of `foo`! If `foo` is a macro, it can use `(declare (indent ...))` to specify how its use-sites should be indented. If `foo` happens to be a function, or a macro which doesn't use `(declare (indent ...))`, then Emacs will indent it as above. However, if it's defined like this: Then Emacs will indent it as: So, at the very least, a "Lisp-aware" formatter would need to resolve names, traverse load paths, etc. to find out whether each call is actually a macro, and whether the definition of such a macro declares an indent rule.But it gets worse! Since we can also do:
With a definition like that, Emacs will choose how much indentation to use by calling the `uh-oh` function! That makes indentation of Emacs Lisp undecidable!If the list is quoted then:
The ambiguity is if you have this: If foo is a function If it is a macro with a trailing body of forms ("implicit progn" in CL parlance) then we don't know, without the macro definition, how many of the initial arguments are not part of those forms: or or A good solution to all this is parinfer: specifically indent -> parens mode. That is to say, manually or semi-automatically control indent, and let parentheses be inferred.The above issues are all symptoms of the assumption that the programmer controls parentheses, leaving the indentation to be figured out.
But parentheses are the aspect of the code that can only be one way, whereas indentation has latitudes that mean nothing to the machine but visually indicate semantics.
So, switch roles: let the machine deal with the parentheses. Then there is no problem to be solved whatsoever that requires declaration info or execution of functions.
The downside is that if we have a correct inference from parentheses to indentation, it can help to spot errors. For instance, if you write:
and the indentation jumps to this: then you have an instant reminder that you forgot to write the expression to be analyzed by the pattern, causing your first body form to be interpreted as that.To me, that is minor, and I'm willing to throw it under the bus by controlling indentation.
Parens inference from indentation is not perfect, though! This is illustrated best by cond. If you have a cond clause like this:
parinfer wants to do this: because the forms are indented, they are assumed to be constituents of the condition expression. The fix for that is to just learn to embrace: Only problem with that is working with your legacy code where you have the indentation.> Lisp is a tree of nested lists. The language knows it, and most of the tooling around it pretends otherwise (some with nasty regex magic too).
This was my experience with Clojure too. A lot of "tooling is super easy because it's all lists and code are data structures" and in practice the tooling wasn't there. At all.
On your CI point: yes, that's the stated priority. Nothing is inferred from how a form is used, there's no scanning of other files or dependencies, and the result is idempotent.