Page 1 of 1

Indenting "HTML" S-expressions

Posted: Fri Jul 18, 2008 6:45 am
by bnordbo
A common method when working with HTML in Common Lisp seems to transform S-expressions to HTML such that
(:h1 :class "foo" "Hello") => <h1 class="foo">Hello</h1>
I like this method a lot, but the default indentation of Emacs/Slime bothers me:

Code: Select all

(:h1 :class "foo"
     "Hello")
The indentation code indents it as if :H1 was a function called with three arguments, which is understandable. It should be possible to make an exception for the case "non-quoted list whose first element starts with a colon" and rather indent it like this:

Code: Select all

(:h1 :class "foo"
 "Hello")
Before I spend the weekend trying to modify the indentation code, I was wondering if anybody has done this before or know of a workaround?

Re: Indenting "HTML" S-expressions

Posted: Sun Jul 20, 2008 4:46 am
by G-Brain
The indentation makes perfect sense to me:

Code: Select all

(:div :class "whatever"
      "Text here")
Turns into this:

Code: Select all

<div class="whatever">
     Text here
</div>
Which is how I do my HTML, and I'm pretty sure that's the standard.

Re: Indenting "HTML" S-expressions

Posted: Sat Aug 02, 2008 5:41 am
by bnordbo
Ok, consider this then:

Code: Select all

(:div :class "foo"
      (:div :class "bar"
            (:div :class "zot"
                  ...)))
After three DIV-tags its already indented 18 columns to the right. This also makes the HTML S-expressions less uniform; it would be slightly easier to read if they were always indented only one column. Consider these two examples:

Code: Select all

(:div :class "foo"
      (:div
       (:div :class "bar"
	     (:a :href "zot.html"
                 (:img :src "zot.jpg)))

Code: Select all

(:div :class "foo"
 (:div
  (:div :class "bar"
   (:a :href "zot.html"
    (:img :src "zot.jpg)))
In my opinion the second one is superior.

There is supposed to be a space before the second DIV by the way, but phpBB doesn't show it for some reason.

Re: Indenting "HTML" S-expressions

Posted: Sun Aug 03, 2008 4:57 am
by G-Brain
Ahh, now I see your point. It automatically aligns nested tags under the first attribute of it's parent, instead of just indenting by a single column. I'll see if there's a way to turn that off.

Re: Indenting "HTML" S-expressions

Posted: Sun Aug 03, 2008 10:46 am
by bnordbo
Good. :-) I'm sorry about my first example; I tried to keep it simple, but appearently overshot quite a bit...

Re: Indenting "HTML" S-expressions

Posted: Fri May 04, 2012 7:08 pm
by arvid
Assuming you use common-lisp-indentation, look at edit slime-cl-indent.el

you could add rules for :div, :a, etc

(:div (&body)) ;; indents by 2 spaces (uses variable lisp-body-indent)
or
(:div (&whole 1)) ;; indents by 1 space

(:a (as :div)) ;; :a uses :div definition

one way of doing this without edit slime-cl-indent.el would be
add commands like

Code: Select all

(put :div 'common-lisp-indent-function '(:div (&body)))
to your .emacs

Re: Indenting "HTML" S-expressions

Posted: Sun Jun 17, 2012 9:33 am
by arvid