regexreplaceclojurefindlighttable

How to tie a string replace to a command in Light Table


My work wants us to use left and right double quotes while typing documentation. I want to use the LaTeX style ones because I write papers in LaTeX often and I already type them automatically.

I am new to clojure but did manage to find this:

(def mystring "``quoted string''")
(clojure.string/replace mystring #"``|''" {"``" "“" "''" "”"})

This will output:

“quoted string”

So I want to tie this functionality to a command using keybindings. I was going to ask how to tie the above command. But then I read this bit on how standard clojure libraries don't integrate so well with LightTable: How to integrate libraries (clojars) into Lightable plugins

I keep reading about regexs. Is there a way to apply a regex across an entire file?

What I'm thinking is I will type up the document and then at some point, hit (ctrl-i) or whatever and have it automatically replace the LaTeX characters with my work's desired characters.

If it was possible to have something auto-replace them while I type, that would be amazing. But I'm new to this so going with baby steps.


Solution

  • The solution I ended up using is the following key binding:

    [:editor "ctrl-shift-q" (:editor.open-pair "“”")]
    

    When I press my key combo, in this case control-shift-q, it drops the left-double-quote and right-double-quote into the document with my cursor in the middle.

    I would still prefer to have something that replaced any double backtick "``" with a left-double-quote and any double apostrophe "''" with a right-double-quote but This works great for now.