8
votes

This question is a follow up to How does one pre-load a clojure file in the leiningen repl?.

My ~/.lein/profiles.clj looks as follows:

{  
  :user {:source-paths ["C:/Users/username/.lein/src"] }
}

My ~/.lein/src/user.clj might look as follows:

(ns user)

(println "user file loaded")  

When I run lein repl within a folder containing a project.clj, then the user.clj file is executed, but when I run lein repl from another folder it doesn't load my user profile. Is there a workaround for this or is this behavior by design? In fact, I know that Leinigen is indeed loading my profile.clj (even when there is no project.clj) because there are also other things inside (taken from the excellent pimp my repl article). Leinigen is just having problems with my additional source-paths setting.

One other question related to this is the fact that I need to specify the full path of the folder for my user.clj file : "C:/Users/username/.lein/src". When I change that to "~/.lein/src" leiningen fails to load my file.

1
Do you see anything in the documentation to suggest that ~ in a source-path should work? In general tilde expansion only works in Linux shells - I wouldn't expect it to work from within Java, or on a Windows platform.Alex
Good catch: Replaced it with {:source-paths [~(str (System/getProperty "user.home") "/.lein/src")]} and it works. But I still can't use it from a folder without a project.clj inside it.shaft

1 Answers

8
votes

It sounds like you just want some code loaded for your lein repl sessions. This is done with the :init key of the :repl-options in your profiles.clj. You can load-file other files in init if you want to organize in that fashion.

{:user 
  {:repl-options 
    {:init (load-file "path-to-file/user.clj")} 
     ...}} 

Note: If you are using Windows-style path delimiters /, you'll need to escape them //.