Skip to content

john2x/repload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

repload

A Clojure utility function to reload all referred vars and aliased namespaces in a REPL.

Motivation

  1. Restarting the REPL is stupid
  2. Manually :reloading referred vars and aliases is a pain
  3. tools.namespace has too much overhead (e.g. state management)

Install

"Leiningen version"

repload was designed to be used in the REPL exclusively. If you are using Leiningen (which you should), you can inject repload into your profiles.clj to make it available in all your REPLs.

Edit your ~/.lein/profiles.clj file:

{:user
 {
   ; ...
   :dependencies [ ; ...
                   [john2x/repload "0.0.3"]]
   :injections   [ ; ...
                   (require 'repload)
                   (require '[repload :refer [repload]])]
  }
 }

Usage

Now open up a new REPL:

$ lein new myproject
$ lein repl

user=> (use 'myproject.core)
nil
user=> (require '[myproject.core :as mp])
nil
user=> (source foo)
(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))
nil
user=> (foo "test")
test Hello, World!
nil
user=> (mp/foo "test")
test Hello, World!
nil

;; make some changes to your project

user=> (repload)
Reloading myproject.core [foo]
Reloading myproject.core with alias mp
nil
user=> (source foo)
(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Goodbye, World!"))
nil
user=> (foo "test")
test Goodbye, World!
nil
user=> (mp/foo "test")
test Goodbye, World!
nil

By default, repload excludes reloading namespaces starting with clojure and repload. You can override these prefixes with the following:

;; add "myproject" as an ignored prefix
user=> (repload/add-exclude-prefix! "myproject")
user=> (repload)
nil  ;; nothing reloaded

;; set "myproject" as the *only* ignored prefix
;; (causing a *lot* of `clojure.core` vars to be reloaded)
;; (*not recommended*)
user=> (repload/set-exclude-prefixes! ["myproject"])

License

Copyright © 2014 John Louis Del Rosario

Distributed under the MIT license.

About

Utility function to reload all referred vars and aliased namespaces in a REPL.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published