leinigen repl with profile
Asked Answered
S

1

8

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.

Sitdown answered 15/4, 2014 at 14:9 Comment(2)
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.Wintertide
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.Sitdown
V
10

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 //.

Vivacity answered 15/4, 2014 at 15:32 Comment(2)
Thanks, exactly what I was looking for. The following snippet works for me, including the loading of scripts relative to my home dir: {:user {:repl-options {:init (load-file (str (System/getProperty "user.home") "/.lein/src/user.clj"))}}}Sitdown
Ah, I'm working via Cygwin on Windows, kind of assumed you were too with the "~/" path references.Vivacity

© 2022 - 2024 — McMap. All rights reserved.