I would like to save nicely formatted Clojure code. Eclipse can format code every time a file is saved. It would be nice to have the same in Light Table. Manually, I can do it by selecting all (ctrl+a), then running (ctrl+space) Editor: Smart indent line(s)
. Is there a way to do it automatically every time a file is saved?
Asked
Active
Viewed 1,351 times
4

Alex Miller
- 69,183
- 25
- 122
- 167

Igor Kuzmitshov
- 98
- 1
- 6
2 Answers
6
You can override key bindings for save in Settings: User keymap
like:
{:+ {:editor {"ctrl-s" [:editor.select-all
:smart-indent-selection
:editor.selection.clear
:save]}}}
But you will lost cursor position (it will jump to the end of file). This can be handled with Marks
plugin. Install the plugin and add command :lt.plugins.marks/jump-to-large-move-mark
onto last position of commands vector.

Aleš Roubíček
- 5,198
- 27
- 29
-
2Thanks, @Aleš! At the end I decided to use a separate key binding for re-indenting, because with this solution you cannot undo the formatting if you don't want it (and save the file). In Eclipse, when auto-format on save is used, if you press ctrl+s, then the code is formatted and saved. If you press ctrl+z after that, formatting will be undone and the file will be saved again. Another way is to put `:save` first in the list of commands: this will save and format after, then you can press ctrl+s again to save the formatted version or ctrl+z to undo the formatting (file will be saved still). – Igor Kuzmitshov Jul 02 '14 at 15:53
3
new Keymap-Style in actual Lighttable (0.7.2)
Press (ctrl+space) -> enter "keymap" and select "User keymap"
[:editor "ctrl-s" :editor.select-all :smart-indent-selection :editor.selection.clear :save]
or with marks plugin
[:editor "ctrl-s" :editor.select-all :smart-indent-selection
:editor.selection.clear :save :lt.plugins.marks/jump-to-large-move-mark]

Erik255
- 1,463
- 1
- 11
- 13