Skip to content

Instantly share code, notes, and snippets.

@rundis
Created December 29, 2015 22:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rundis/53d3228eb1c6e94d85b2 to your computer and use it in GitHub Desktop.
Save rundis/53d3228eb1c6e94d85b2 to your computer and use it in GitHub Desktop.
Reload Namespace in Light Table
; add this to hook up your custom behavior
[:editor.clojure :lt.plugins.user/reload-ns]
(ns lt.plugins.user
(:require [lt.object :as object]
[lt.objs.command :as cmd]
[lt.objs.editor.pool :as pool])
(:require-macros [lt.macros :refer [defui behavior]]))
(defn create-reload-ns-op [ed]
(str
"(require 'lighttable.nrepl.eval)\n"
"(require (symbol (lighttable.nrepl.eval/file->ns \"" (-> @ed :info :path) "\")) :reload-all)"))
(behavior ::reload-ns
:triggers #{:reload-ns}
:reaction (fn [ed ]
(let [op (create-reload-ns-op ed)]
(object/raise ed
:eval.custom
op
;; :no-op swallows any return value, you may want to hook it up to a behavior
;; see https://github.com/rundis/clj-light-refactor/blob/master/src/lt/plugins/cljrefactor/macroexpand.cljs#L41 for ecample on how to do that
{:result-type :no-op
:verbatim true}))))
(cmd/command {:command :reload-ns
:desc "Clojure: Reload namespace"
:hidden true
:exec (fn []
(when-let [ed (pool/last-active)]
(object/raise ed :reload-ns)))})
; whatever shortcut you prefer
[:editor.clojure "alt-shift-r" :reload-ns]
Copy link

ghost commented May 15, 2016

Thank you for providing this -- a question: how does it differ from "Cmd-Shift-Enter" which seems to also reload everything?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment