Behavior that can "type"?

71 views
Skip to first unread message

Chris Bourke

unread,
Nov 1, 2017, 1:18:41 PM11/1/17
to Light Table Discussion

I've been trying to find ways that I can autosave a file on every keystroke (or every n keystrokes).  I've not been able to find a way to do this, but I thought I could by changing the keybindings:

[:editor "space" :save]

Which will work (every time I hit space, it saves, so after every word I type it would save), but of course that means I can no longer type an actual space.

Is there a behavior that would allow me to do this in succession or at least retain and combine the original behavior?  Something like

[:editor "space" :save :type-space]

or 

[:editor "space" :save :insert " "]

I've not been able to figure out a way to achieve this...

Chris Bourke

unread,
Nov 1, 2017, 11:11:32 PM11/1/17
to Light Table Discussion
Update:

So I've been reading more and I'm able to define a command in the user.cljs and then get the command to execute with a key binding.  But I'm not too familiar with clojure script or how to "print" to the current editor.

I can get it to print "foo" (or just a space) to the console, but not back to the current editor.  Any ideas?

Chris Bourke

unread,
Nov 2, 2017, 12:30:16 AM11/2/17
to Light Table Discussion
Okay, so I think I have a solution, but it doesn't seem ideal.  I'm posting the solution for others, but I would welcome feedback on better solutions.

First, I've defined a new command in user.cljs:

(cmd/command {:command :user.insert-space
              :desc "Insert a space character"
              :exec (fn []
                      (let [ed (lt.objs.editor.pool/last-active)]
                        (lt.objs.editor/insert-at-cursor ed " ")))}) 

After evaluating this, the command is available and I add the following key binding:

[:editor.markdown "space" :save :user.insert-space ]

in user.keymap

It seems to work, but if I type quickly, the save command does not seem to execute every time I hit space, but enough that I can use it. 


AT

unread,
Dec 5, 2017, 6:21:05 PM12/5/17
to Light Table Discussion
Why would you ever want this? ...
Reply all
Reply to author
Forward
0 new messages