Skip to content

Commit

Permalink
Added custom variable for controlling defroute alignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamp committed Aug 29, 2012
1 parent 75f5202 commit bbdae7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -21,15 +21,20 @@ Forms currently handled:
* loop
* with-open
* literal hashes {}
* defroute

If there are let pairs together on the same line the code will refuse
to align them. For example, the following will not align:

(let [apple 2 pair 3
peach 23] ...)

will not be aligned

will not be aligned.

# Custom variables:

`defroute-columns` The number of columns to align in a defroute form.

# Known limitations:

* This program requires clojure mode to be running in order to
Expand All @@ -42,6 +47,8 @@ following to your .emacs configuration.

(require 'align-cljlet)

Alternatively you may install this package from Marmalade.

# Usage:

To invoke simply position anywhere inside an alignable form and
Expand Down
16 changes: 15 additions & 1 deletion align-cljlet.el
Expand Up @@ -45,6 +45,7 @@
;; 14-Jan-2011 - Initial release
;; 23-Jan-2011 - Bug fixes and code cleanup.
;; 02-Apr-2012 - Package up for Marmalade
;; 30-Aug-2012 - Support for aligning defroute.
;;
;;; Known limitations:
;;
Expand All @@ -67,7 +68,15 @@
;;
;; You may wish to bind this to a specific key.
;;
;; Contains one custom variable called defroute-columns which is
;; used to determine how many columns to align in a defroute call.
;; Defaults to 1.
;;

(defcustom defroute-columns 1
"The number of columns to align in a defroute call"
:type 'integer
:group 'align-cljlet)

(defun acl-found-alignable-form ()
"Check if we are currently looking at a let form"
Expand Down Expand Up @@ -235,14 +244,19 @@ positioned on the defroute form."
(acl-goto-next-pair)))
(indent-region begin (point))))

(defun acl-take-n (n xs)
"Take n elements from a list returning a new list"
(butlast xs (- (length xs) n)))

(defun acl-align-form ()
"Determine what type of form we are currently positioned at and align it"
(if (looking-at "( *defroutes")
(progn
(down-list 1)
(forward-sexp 3)
(backward-sexp) ; this position's us back at the start of the
; first form.
(acl-respace-defroute-form (acl-calc-route-widths)))
(acl-respace-defroute-form (acl-take-n defroute-columns (acl-calc-route-widths))))
(progn
(if (not (looking-at "{"))
;; move to start of [
Expand Down

0 comments on commit bbdae7d

Please sign in to comment.