How to indent clojure code in Emacs

308 views
Skip to first unread message

tao

unread,
Jan 3, 2014, 4:12:54 AM1/3/14
to clo...@googlegroups.com

I have installed this plugin, but I don’t know how to indent clojure code, when I already selected a region. In Vim, I can do this using “=“, just a simple key stroke.

This a problem when I copy some clojure code from other place, not typed in.

I already read this tutorial (http://www.unexpected-vortices.com/clojure/10-minute-emacs-for-clojure.html), but I cannot found the method.

sorry for disturb. :)

-- 
tao
Sent with Sparrow

tao

unread,
Jan 3, 2014, 4:16:07 AM1/3/14
to clo...@googlegroups.com

C-x h selects the entire buffer. C-M-\ reindents the selected region.


sorry, I have found the answer.

-- 
tao
Sent with Sparrow

dennis zhuang

unread,
Jan 3, 2014, 4:16:28 AM1/3/14
to Clojure
use the 'indent-region' function.You can define a function to indent the whole buffer:

(defun indent-buffer ()
  "Indent whole buffer"
  (interactive)
  (indent-region (point-min) (point-max))
  (message "format successfully"))


Then bind the function to a key, i bound it to F7 for me:

(global-set-key [f7] 'indent-buffer)

Also, you can indent-buffer before saving file:

(defun indent-file-when-save ()
  "indent file when save."
  (make-local-variable 'after-save-hook)
  (add-hook 'after-save-hook
(lambda ()
 (if (buffer-file-name)
 (indent-buffer))
 (save-buffer))))
(add-hook 'clojure-mode-hook 'indent-file-when-save)



2014/1/3 tao <tao.zh...@gmail.com>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
庄晓丹
Email:        killm...@gmail.com xzh...@avos.com
Site:           http://fnil.net
Twitter:      @killme2008


Stefan Kamphausen

unread,
Jan 3, 2014, 7:33:34 AM1/3/14
to clo...@googlegroups.com
Hi,

FWIW, I prefer M-C-q with the cursor on the opening paren of a form.

Cheers,
Stefan

Reply all
Reply to author
Forward
0 new messages