Bug 207002

Summary: [PATCH] Alternative lisp indenter for katepart
Product: [Applications] kate Reporter: Matteo Sasso <matteo.sasso>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: The indentation script
The indentation script, v1.1
The indentation script, v1.1 (for real)

Description Matteo Sasso 2009-09-10 22:48:56 UTC
Version:            (using KDE 4.3.1)
OS:                Linux
Installed from:    Unlisted Binary Package

Here's a lisp indenter which is a little different and, to me, more usable.

It assumes that everything is a function or an argument to a function and indents forms accordingly. It has no knowledge of special forms or macros, so it never indents correctly things like "(when condition body)". This is annoying but can be fixed manually and the indenter is smart enough to keep the indentation of the surrounding lines, if it makes sense.
On the other hand not relying on a list of language-specific symbles makes this indenter truly language agnostic. It would be great if kate scripts would offer a callback for when the unindent key is pressed: scripts could offer an alternative indentation instead of the current lisp-unfriendly behaviour.
Comment 1 Matteo Sasso 2009-09-10 22:50:26 UTC
Created attachment 36850 [details]
The indentation script
Comment 2 Matteo Sasso 2009-09-12 11:52:48 UTC
Created attachment 36887 [details]
The indentation script, v1.1

Better behaviour for some Common Lisp special forms (cond, let, ...).
Comment 3 Matteo Sasso 2009-09-12 11:54:49 UTC
Created attachment 36888 [details]
The indentation script, v1.1 (for real)

Oops, wrong file.
Comment 4 Dominik Haumann 2009-09-13 14:06:47 UTC
Hi, I once wrote the Lisp indenter but just as a proof of concept. I have no idea whether it's really useful for programming Lisp. Hence, does it make sense to replace it? Or add yours as another "Lisp2" indenter (with a better name)?
Comment 5 Matteo Sasso 2009-09-13 19:34:59 UTC
Well, the part that indented comments was good and in fact I used it. On the other hand, it is not really usable for lisp programmers since it indents everything by a fixed amount. Readable lisp code is a little bit more convoluted since it must convey the structure of the program, thus offsetting the homogeneous syntax.

My approach is still a little trivial, but is somewhat usable. Of course opinions of other lisp (or scheme) developers are most welcome.
Comment 6 Dominik Haumann 2009-09-13 23:33:21 UTC
Well, I'd be fine with replacing my indenter then. I doubt other lisp programmers read this thread, so if we want feedback we'd have to ask directly in lisp communities or blog about it.
Comment 7 Dominik Haumann 2009-09-13 23:34:32 UTC
Ah, just stumbled over bug #147693. Can you have a look? Probably we can close that one then.
Comment 8 Matteo Sasso 2009-09-14 02:37:28 UTC
I posted a link to this bug on comp.lang.lisp and on the clojure group. Unfortunately it seems most developers are happy with emacs; I'm not going to blame them.

Yes, bug bug #147693 is partially solved by my indenter. Unfortunately there are some technical limitations which make a "perfect" lisp indenter non-trivial.
Good improvements would be possible if Kate would call the indent() function (or another callback... unindent() maybe?) in response to an unindent command (backspace or shift+tab). Adding a backspace character to triggerCharacters doesn't seem to have any effect right now.
Comment 9 Christoph Cullmann 2011-08-12 13:38:44 UTC
Git commit bc6dcd8ad017908b951fb379c706efd5913f4c31 by Christoph Cullmann.
Committed on 12/08/2011 at 15:38.
Pushed by cullmann into branch 'master'.

add new lisp indenter, feel free to mail further improvements
BUG: 207002

M  +79   -34   part/script/data/lisp.js

http://commits.kde.org/kate/bc6dcd8ad017908b951fb379c706efd5913f4c31