bhauman / rebel-readline

Terminal readline library for Clojure dialects
Eclipse Public License 1.0
680 stars 37 forks source link

:init in project.clj #157

Open bkovitz opened 6 years ago

bkovitz commented 6 years ago

How, with the rebel-REPL (aka the rebl), do you set some initialization function to run when the REPL begins?

For example, to do this with the Leiningen REPL, I have this in my current project's project.clj:

:repl-options {:init (do (use 'farg.model1) (require '[farg.graphs :as g]))}

This way, I don't have to remember to manually set up those namespace aliases every time I start the REPL.

metametadata commented 5 years ago

I wonder about it too now since in a new project my custom REPL setup is not in user ns, but in repl.user.

metametadata commented 5 years ago

I think I've come up with a solution by replacing rebel-readline.main with a custom ns. It allows passing init-ns as a CLI argument. See https://gist.github.com/metametadata/c11044a5d490eac7158ae535c10ce45c.

The relevant lines:

(defn -main
  [& [init-ns]]
  (rebel-core/ensure-terminal
    (rebel-clj-main/repl*
      {:init (fn []
               (when (some? init-ns)
                 (let [init-ns (symbol init-ns)]
                   (require init-ns)
                   (in-ns init-ns))))
pmonks commented 2 years ago

A command line argument, similar to clojure.main's -i path/to/file.clj, might be worth considering as part of this.