Indenting "HTML" S-expressions

Discussion of programming Lisps using Emacs, including SLIME and other tools

Indenting "HTML" S-expressions

Postby bnordbo » Fri Jul 18, 2008 6:45 am

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?
bnordbo
 
Posts: 3
Joined: Fri Jul 18, 2008 6:27 am

Re: Indenting "HTML" S-expressions

Postby G-Brain » Sun Jul 20, 2008 4:46 am

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.
G-Brain
 
Posts: 16
Joined: Sat Jun 28, 2008 3:48 am

Re: Indenting "HTML" S-expressions

Postby bnordbo » Sat Aug 02, 2008 5:41 am

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.
bnordbo
 
Posts: 3
Joined: Fri Jul 18, 2008 6:27 am

Re: Indenting "HTML" S-expressions

Postby G-Brain » Sun Aug 03, 2008 4:57 am

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.
G-Brain
 
Posts: 16
Joined: Sat Jun 28, 2008 3:48 am

Re: Indenting "HTML" S-expressions

Postby bnordbo » Sun Aug 03, 2008 10:46 am

Good. :-) I'm sorry about my first example; I tried to keep it simple, but appearently overshot quite a bit...
bnordbo
 
Posts: 3
Joined: Fri Jul 18, 2008 6:27 am

Re: Indenting "HTML" S-expressions

Postby arvid » Fri May 04, 2012 7:08 pm

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
arvid
 
Posts: 3
Joined: Sat Mar 07, 2009 8:23 am

Re: Indenting "HTML" S-expressions

Postby arvid » Sun Jun 17, 2012 9:33 am

arvid
 
Posts: 3
Joined: Sat Mar 07, 2009 8:23 am


Return to Emacs

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

cron