Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to smart-indent files automatically on save in Light Table

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?

like image 447
Igor Kuzmitshov Avatar asked Jan 11 '23 08:01

Igor Kuzmitshov


2 Answers

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.

like image 99
Aleš Roubíček Avatar answered May 11 '23 15:05

Aleš Roubíček


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]
like image 26
Erik255 Avatar answered May 11 '23 15:05

Erik255