Lisp-style indenting?

37 views
Skip to first unread message

John Gabriele

unread,
May 29, 2012, 11:52:52 AM5/29/12
to nicee...@googlegroups.com
What are your thoughts on having ne do proper lisp-style indenting for
editing the various lisps? (In particular, I'm interested in Clojure.)
That is, vertically align function arguments, as in:

~~~
(+ (some-func 1
2
3)
4)
~~~

where the 1, 2, and 3 are all vertically aligned, and the 4 is
underneath the "(" in "(some-func".

I haven't run across many editors that properly indent Lisps. Emacs
does (of course), and my understanding is that Vim and Eclipse + the
Counterclockwise plug-in do. But I don't know of any others (except
for Clooj, which is a Clojure ide currently under development).

Would be cool for a nice little editor like ne to be able to do this
trick. What would be involved in teaching ne to line up args
vertically like that?

Thanks,
---John

Sebastiano Vigna

unread,
May 29, 2012, 11:59:16 AM5/29/12
to nicee...@googlegroups.com
On May 29, 2012, at 8:52 AM, John Gabriele wrote:

> Would be cool for a nice little editor like ne to be able to do this
> trick. What would be involved in teaching ne to line up args
> vertically like that?


Well, it's incredibly complicated as there are dependencies for an unbounded number of lines... it could be conceivable as an offline thing (like: select a block and them format it).

Ciao,

seba

John Gabriele

unread,
May 30, 2012, 9:41:40 AM5/30/12
to nicee...@googlegroups.com
How about this then: add a simple VAlignIndent command that looks at
the previous line, and indents you out to where, on the previous line,
the next non-whitespace character is. For example, if you've got:

~~~
(+ (some-func 1
^
~~~

(where the caret ("^") is where the cursor is), and you do a
VAlignIndent, it gets you to

~~~
(+ (some-func 1
^
~~~

(cursor is under the 2nd open paren). Hit it again, and it takes you to:

~~~
(+ (some-func 1
^
~~~

(cursor is under the "1").

Having that command would also be very useful for when creating tables, as in

~~~
size color
---- --------
7 red
8 green
9 blue
~~~

---John

John Gabriele

unread,
May 31, 2012, 11:08:14 AM5/31/12
to nicee...@googlegroups.com
On Wed, May 30, 2012 at 9:41 AM, John Gabriele <jmg...@gmail.com> wrote:
> On Tue, May 29, 2012 at 11:59 AM, Sebastiano Vigna <vi...@dsi.unimi.it> wrote:
>> On May 29, 2012, at 8:52 AM, John Gabriele wrote:
>
> How about this then: add a simple VAlignIndent command that looks at
> the previous line, and indents you out to where, on the previous line,
> the next non-whitespace character is. {snip}

Actually, this wouldn't help in the common case where you've already
got something like:

~~~
(+ (some-func 1
2
3)^
~~~

and you want to be able to get the cursor underneath that 2nd
open-paren, like so:

~~~
(+ (some-func 1
2
3)
^
~~~

Hm. Being able to do that would be key...

---John

John Gabriele

unread,
Jun 1, 2012, 11:36:42 AM6/1/12
to nicee...@googlegroups.com
On Tue, May 29, 2012 at 11:59 AM, Sebastiano Vigna <vi...@dsi.unimi.it> wrote:
Ok, I think we might have an easy solution here that will help out a
great deal for a large number of cases.

When the cursor is at the end of a line, and the user runs this command
(maybe call it "ParenMatchIndent"), here's the pseudo-macro/code for what
it would do:

~~~
if the previous character is a close-paren:
PushPrefs
move the cursor one place to the left (MoveLeft)
go to matching paren (MatchBracket)
note the column number at which we are now located
go back (MatchBracket)
move cursor right one place (MoveRight)
shut off AutoIndent
Return (^m)
indent to column we noted earlier
PopPrefs
otherwise:
Return (^m)
~~~

Here's some of the situations where that ParenMatchIndent command
would be most useful (prev cursor location shown by caret, resulting
cursor location shown by "@"):

~~~
(+ (some-func 1
2
3)^
@
~~~

Perfect. Here's more:

~~~
(some-func (func-a 1)^
@

(some-func (func-a 1
2)^
@

(func-a (func-b (func-c 1))^
@

(defn some-func
[x]
(let [...]
(something
(this-and-that 1
2))))^
@
~~~

This one:

~~~
(defn foo
"some docstring"
[arg1 arg2]
(let [a (* arg1 arg2)^
@
~~~

isn't so bad. We *want* the cursor to land under the "a", but
ParenMatchIndent would get us pretty close. Using the usual
auto-indent (typically enabled (for me anyway)) would do ok
here too.

This:

~~~
(defn foo
[a b]
(let [a ( ... )
b ( .......... )]^
~~~

is one where a ParenMatchIndent wouldn't help us, since the line
we're on doesn't end in a close-paren.

***

(For me, I'd probably use ^j for ParenMatchIndent and alt-j to jump
to line number, leaving "goto column num" available only via the menu.)

What do you think?

---John

John Gabriele

unread,
Jun 1, 2012, 1:06:20 PM6/1/12
to niceeditor
On Jun 1, 11:36 am, John Gabriele <jmg3...@gmail.com> wrote:
>
>


Actually, the handling of both this one:

> ~~~
> (+ (some-func 1
>               2
>               3)^
>    @
> ~~~

and this one:

> ~~~
> (defn foo
>   [a b]
>   (let [a ( ... )
>         b ( .......... )]^
> ~~~
>
> is one where a ParenMatchIndent wouldn't help us, since the line
> we're on doesn't end in a close-paren.

could be very much improved by changing the "otherwise" in

> ~~~
> if the previous character is a close-paren:
> PushPrefs
> move the cursor one place to the left (MoveLeft)
> go to matching paren (MatchBracket)
> note the column number at which we are now located
> go back (MatchBracket)
> move cursor right one place (MoveRight)
> shut off AutoIndent
> Return (^m)
> indent to column we noted earlier
> PopPrefs
> otherwise:
> Return (^m)
> ~~~

to:

~~~
otherwise:
PushPrefs
go back until you find an open paren
note what column it's in
go forward, returning to where you started
shut off autoindent
Return (^m)
indent to column we just noted
PopPrefs
~~~

This way, when you have something like:

~~~
(func-aaa (func-bbb (func-ccc 1^
@
~~~

instead of hitting Return and getting sent all the way back to column
1, you could do ParenMatchIndent and land where the "@" is.

Even better,

~~~
(defn foo
[x]
(foobarbaz x
(fn [y] ...
(let [a ...
b ... ]^
@
~~~

which puts you just about exactly where you want. :)

---John
Reply all
Reply to author
Forward
0 new messages