Emacs `align' function customization for Clojure

181 views
Skip to first unread message

Eric Schulte

unread,
Jan 4, 2011, 9:10:36 PM1/4/11
to Clojure
Hi,

I just recently became aware of the built-in `align' [1] function for
Emacs while looking for a nice way to auto-align some hash-maps in my
Clojure code. This was easily done using align with the following piece
of customization.

#+begin_src emacs-lisp
(add-to-list 'align-lisp-modes 'clojure-mode)
(add-to-list 'align-rules-list
'(clojure-keyword-map
(regexp . ":[^\s]+\\(\s+\\).+")
(group . 1)
(modes . align-lisp-modes)))
#+end_src

Then marking the following code and calling `align' will turn this

#+begin_src clojure
{:byte [1 byte]
:char [1 char]
:int16 [2 short]
:uint16 [2 uint16]
:int32 [4 int]
:uint32 [4 uint32]
:int64 [8 long]
:uint64 [8 uint64]
:float32 [4 float]
:float64 [8 double]
}
#+end_src

into this

#+begin_src clojure
{:byte [1 byte]
:char [1 char]
:int16 [2 short]
:uint16 [2 uint16]
:int32 [4 int]
:uint32 [4 uint32]
:int64 [8 long]
:uint64 [8 uint64]
:float32 [4 float]
:float64 [8 double]
}
#+end_src

I wonder if anyone else has written any similar Emacs alignment rules
for Clojure which they would be interested in sharing?

Thanks -- Eric

Footnotes:
[1]

,----
| align is an interactive Lisp function in `align.el.gz'.
|
| (align BEG END &optional SEPARATE RULES EXCLUDE-RULES)
|
| Attempt to align a region based on a set of alignment rules.
| BEG and END mark the region. If BEG and END are specifically set to
| nil (this can only be done programmatically), the beginning and end of
| the current alignment section will be calculated based on the location
| of point, and the value of `align-region-separate' (or possibly each
| rule's `separate' attribute).
|
| If SEPARATE is non-nil, it overrides the value of
| `align-region-separate' for all rules, except those that have their
| `separate' attribute set.
|
| RULES and EXCLUDE-RULES, if either is non-nil, will replace the
| default rule lists defined in `align-rules-list' and
| `align-exclude-rules-list'. See `align-rules-list' for more details
| on the format of these lists.
|
| [back]
`----

Scott Jaderholm

unread,
Jan 5, 2011, 12:29:17 PM1/5/11
to clo...@googlegroups.com
On Tue, Jan 4, 2011 at 9:10 PM, Eric Schulte <schult...@gmail.com> wrote:
> I wonder if anyone else has written any similar Emacs alignment rules
> for Clojure which they would be interested in sharing?

Alignment rules for let and defroutes are at the top of my most wanted list.

(let [n                (count content-divs)
      width            500
      widthpx          (str width "px")
      scrollable-id    (or scrollable-id (str "scrollable" (rand-int 100)))
      scrollable-fname (symbol scrollable-id)]


(defroutes app
      (GET "/"          _       (main-page))
      (GET "/subscribe" _       (slices site-header subscribe-button))
      (GET "/test"      request (slices jquery
                                  (dom (alert ~(:remote-addr request)))
                                  (html [:h1 "Hi"])
                                  (css [:h1 :color "blue"]))))

Glen Stampoultzis

unread,
Jan 11, 2011, 12:32:58 AM1/11/11
to clo...@googlegroups.com
On 6 January 2011 04:29, Scott Jaderholm <jade...@gmail.com> wrote:
On Tue, Jan 4, 2011 at 9:10 PM, Eric Schulte <schult...@gmail.com> wrote:
> I wonder if anyone else has written any similar Emacs alignment rules
> for Clojure which they would be interested in sharing?

Alignment rules for let and defroutes are at the top of my most wanted list.


align-let.el [1] might be a reasonable starting point for someone wanting to create something for clojure.  I have not tried it myself so I have no idea if it even works.



Reply all
Reply to author
Forward
0 new messages