Code reloading with leiningens checkouts feature - clojure

I am using a luminus web project and added a library that I am developing in parallel to it via the checkouts feature of leiningen.
Now, what I want is that the reloading of source files works too for the project that I refer to via the checkouts folder.
Is there way to do that? I have not succeeded so far changing the :reload-paths or wrap-reload options.

Ok, in the end it was pretty easy, however, finding that out, was not.
In core.clj there is this code:
(http-kit/run-server
(if (dev? args) (reload/wrap-reload app) app)
Simply change it to this one:
(http-kit/run-server
(if (dev? args) (reload/wrap-reload app
{:dirs ["src" "checkouts/subproject/src"]}) app)
You can add as many folders you want, all will get watched for source changes.

Related

When using cider-find-var, how to make it jump to the definition on the original file instead of going to the output of lein install on maven folder?

I have been using Clojure, ClojureScript, lein, shadow-cljs, Emacs, and CIDER to work on a Clojure/ClojureScript dynamic web app project.
There is the main repository, let's call it principal. And also a supporting repository, called supporting.
Ok. On my local ~/projects folder, I have ~/projects/principal/ and also ~/projects/supporting.
At some point, after building the project being on ~/projects/principal/, I am using the ClojureScript REPL to invoke a function from one of the dependencies, the supporting repository:
cljs.user> (supporting.core/my-function my-variable)
With the cursor on top of supporting.core/my-function I execute the command cider-find-var (bounded to M-.) . This is a cool command. It allows me to jump to see the definition of the function!
The only problem is where CIDER is pointing me:
Directory /Users/pedro/.m2/repository/supporting/1.2.15/
As you can see, it does not point to the "original source code" of the supporting repo. It actually points to the "compiled version" related to Maven (the output of lein install, if my understanding is correct).
But, as far as I know, it is not appropriate to edit this. I need to edit the original file pre-compile on a different folder.
How to make CIDER jump to the original editable pre-compiled repository?

Automatic Link to GitHub Pages URL from README.md?

Is there a way to create a link to a repository's GitHub page in the repository's README.md (or other Markdown file) without hardcoding the URL?
The use case I'm facing is the result of forking a repository in which the README includes [a link](https://their-org.github.io/repo/), and which I'd rather not have to manually update to [a link](https://my-org.github.io/repo/).
My readme is (repo)/blob/master/README.md
I'm not sure how robust this is, but this test worked for me:
test link: [testlink](../../)
Is that what you were asking for?
Relative links always works on README.md and in every markdown file in your repo. I'm using them to document a personal project and I've never had an issue with that. Take a look at (https://github.com/andreabenini/bM3tal/blob/master/README.md) plenty of relative links in each part of the project. I'm documenting it with md files because I'm lazy and for a bare doc markdown files are qu

Where should the file user.clj go?

I am trying to setup proto-repl atom-editor package and apparently it needs a file user.clj to exist somewhere - which I guess is some leiningen's init file.
Where should I create this file?
Clojure will load the file user.clj from your class path if it is found. In a default leinengen project src/ will be on the class path, so if you create src/user.clj the contents of that file will be loaded in the context of the user namespace.
user is the default namespace for the clojure repl, but some leiningen projects override this. In order to access definitions in user.clj you will need to either pull user into scope (using require or use) or make sure that user is your starting namespace.
See the Proto REPL demo project https://github.com/jasongilman/proto-repl-demo/blob/master/dev/user.clj for an example of how to setup user.clj You should also add a dependency on clojure.tools.namespace in the project.clj https://github.com/jasongilman/proto-repl-demo/blob/master/project.clj
I just pushed some changes to Proto REPL last night to improve this area but you'll still benefit from having one setup.
According to the proto-repl page, it might use some functions from user namespace when reloading code in REPL (reset function) but it shouldn't be required.
You might want to take a look at the proto-repl demo project to see the more advanced setup.

How to reference environmental variable or home dir in project.clj

Is there a way to programmatically insert the name of my home directory into file paths in Leiningen's project.clj?
I run a Leiningen project on different machines, where I have different home directories. The project uses jar files that are not managed by Maven; I download 'em and put them in a directory that's relative to my home directory, or copy them into the Leiningen project. The second option works but is undesirable.
An easy way to use the first option--keeping the jar files somewhere else--is to add a soft link to the "somewhere else" directory in my Leiningen directory. That works, but the link has to be different on each machine, so I can't include the link file in the git repository, and I'd rather include everything in the git repo.
Isn't there a way to use environmental variables, or otherwise refer to my home directory, in my project.clj file? I've gone through the sample project file and have not found a solution, so far.
I thought I could just construct path strings at run time--what's in project.clj is just Clojure code, after all. Since hard-coding my home directory into project.clj works without any trouble:
:resource-paths [/Users/myhomedir/dist/mason/jar/mason.19.jar")]
I figured I could do this:
:resource-paths [(str (System/getenv "HOME") "/dist/mason/jar/mason.19.jar")]
However, Leiningen doesn't like this at all:
java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.PersistentList
Changing [...] to (vector ...) gives the same error but with 'clojure.lang.Symbol` at the end.
In the name of repeatability you'd better have the jar installed in the local maven repository and have it added to the project.clj :dependencies so it's fetched from there. But you said those jars won't be managed by maven, so here we go:
defproject is a macro and it allows to use unquoting to do arbitrary evaluation. It does it by calling the internal fn unquote-project. So you can do the following:
:resource-paths [~(str (System/getenv "HOME") "/dist/mason/jar/mason.19.jar")]

Clojure emacs slime + swank directory question

I'm using emacs with clojure-swank and slime and trying to set my development environment. And I ran into a problem. When I start a repl I'm stuck in an unknown directory preventing me to load my namespace. Because the clojure repl can't find the right file.
Does anyone know how to change the current directory?
PS: I've just started using emacs and slime so I'm a noob.
If you want to change slime's notion of the current directory, press ,cd<CR> (<CR> = Enter) and type in the path.
However, this is not really the proper solution to the problem. The proper solution involves setting up the classpath so that you can (use 'your.namespace). To this end, I wonder if this very long answer I provided to a question about setting up the classpath properly might be helpful... :-)
Incidentally, I somewhat object to solutions involving add-classpath, as that is currently marked as deprecated and was never meant to be relied upon in the first place... Though on the other hand, it certainly may work perfectly well and it's worth knowing about just in case it might come in handy as a quick-and-dirty classpath injection gimmick.
Now if you want a real nice SLIME-based development environment, I'd like to point you to a very nice clojure-project elisp function by Phil Hagelberg which sets up all relevant variables and launches SLIME in the main directory of a project (to be supplied interactively). It's been posted to the Clojure group, in fact here's a link to the Mail Archive's copy of that message. Note there's one thing which needs correction in there -- swank-clojure-jar-path ought to be set to the full path to clojure.jar. Otherwise it's a fantastic tool.
Actually I mentioned that function in this response to a question about managing the classpath when using Clojure and Emacs. The other answers might be interesting as well.
And if you're only just beginning to use SLIME, do watch the SLIME video, linked to from SLIME's homepage which is now available under a link posted by Michiel in the comments. It's a very good introduction. :-)
Leiningen is a new Clojure build tool that worries about classpathing for you. You set up a simple project file in the project's root directory to specify the main class of your project, and it automagically discovers all the JARs in your lib directory and loads them for you.
I now just type "lein swank" at a command line and then M-x slime-connect in Emacs, and everything just works. (This could easily be automated with a little Elisp.)
More info in this blog post.
Short answer:
(load-file "full-path-to-definition")
Long answer:
Here's what my bootstrapping process looks like:
In ~/.clojure/user.clj (this file is auto-run when you boot slime/clojure):
(add-classpath "file://path/to/foo.jar") ; Include these jars in the classpath
(add-classpath "file://path/to/foo2.jar")
(load-file "file://workspace/bootstrap.clj")
In bootstrap.clj:
(compile 'my.package)
Package file(s) is at /workspace/my/package.clj
In package.clj:
(ns my.package)
(defn foo [] (+ 2 2))
The best approach I've found when using Emacs, SLIME and swank-clojure is to use the (Emacs Lisp) function swank-clojure-project. From its documentation:
(swank-clojure-project PATH)
Setup classpath for a clojure project and starts a new SLIME session.
Kills existing SLIME session, if any.
If you do a "M-x swank-clojure-project", it will interactively prompt you for your project directory; once you've selected it, all the jars in a lib subdirectory, as well as the src and classes folder will be added to your classpath. It will also honor a Maven/lein directory structure, in other words: it will usually just work.
If you change something, e.g. add a new jar file, simply do swank-clojure-project again.