Fork me on GitHub
#emacs
<
2022-06-24
>
Benjamin18:06:47

(defun mm/cider-jack-in-with-an-alias-from-deps ()
  (interactive)
  (if-let* ((root (project-root (project-current t)))
	    (_ (file-exists-p (expand-file-name "deps.edn" root))))
      (let* ((default-directory root)
	     (my-alias
	      (completing-read
	       "Cider jack in with alias: "
	       (read-from-string
		(shell-command-to-string
		 (format "bb -e '%s'" (princ '(->> (slurp "\"deps.edn\"") read-string :aliases keys (map name))))))))
	     (cider-clojure-cli-aliases
	      (concat
	       cider-clojure-cli-aliases ":" my-alias)))
	(call-interactively #'cider-jack-in-clj))
    (user-error "no deps.edn file in project")))
I can't be the only one who wanted this

👍 1
mpenet19:06:36

That could be improved to also take into account the other aliases available (user level for instance).

mpenet19:06:51

But that's quite nice already

dpsutton19:06:43

didn’t the clojure cli add a new option to list all aliases?

Alex Miller (Clojure team)19:06:53

clj -X:deps aliases but it's not very data oriented (if needed, would be open to an edn output option too)

dpsutton19:06:21

I remembered I had used it but didn’t find it in clj --help so I got a bit confused

Programs provided by :deps alias:
 -X:deps mvn-install       Install a maven jar to the local repository cache
 -X:deps git-resolve-tags  Resolve git coord tags to shas and update deps.edn
 -X:deps find-versions     Find available versions of a library
 -X:deps prep              Prepare all unprepped libs in the dep tree

Alex Miller (Clojure team)19:06:54

yeah, some of the docs are still lagging the newer stuff

mpenet19:06:46

I personally just set cider-edit-jack-in-command to true

mpenet19:06:16

Yes it was added this week, good point

dpsutton19:06:55

also, does this elisp code allow selecting multiple?

dpsutton19:06:58

(just use a prefix when jacking-in will let you edit the command as well). Or stuffing all of the stuff cider wants into a profile (easily copy from the startup command in the top of the repl) and then just use terminal to start your process clj -M:dev:stuff:cider/nrepl and off you go

👀 1
mpenet19:06:03

It can be done. Stuff like transient menus come to mind

mpenet19:06:52

Also dir-locals can be used

mpenet19:06:24

But in my experience cider-edit-jack-in-command is the least intrusive

mpenet19:06:58

It's just an extra RET when you don't edit the aliases and otherwise you're free to add whatever

👍 1
practicalli-johnny19:06:06

.dir-locals.el works fine for my workflow. I don't understand / relate to a use case for this. Are people frequently changing their aliases that it needs some picker? Is it because lots of different projects are being used and they all use different alias names ? Does this approach have to rely on external tools that may not be installed?

Benjamin09:06:50

for me the use case is when I have build or test aliases and I want to repl. If I have a dev alias it is covered with .dir-locals

practicalli-johnny10:06:27

Is there a reason the test and build aliases cannot be included in the .dir-locals.el configuration and loaded into the REPL on startup? Do they add significant resource overhead? I typically include the dev and test aliases in .dir-locals.el so I can run the cider-test runner (although I often use kaocha in watch mode in a separate terminal as well) I usually build from the command line (assuming I need to manually build at all - build is mostly done by continuous integration server or docker if its a local complex (AWS) environment) Maybe I am missing something...

Benjamin14:06:50

you are right putting all dev aliases in dir-locals would fix it

practicalli-johnny14:06:43

I was curious to know if there were common cases I wasn't aware of. I am aware Calva for VS Code has an alias picker, perhaps because the VS Code doesn't have an equivalent of a .dir-locals.el. Maybe a picker is useful for occasional user level aliases, although I have too many aliases for a checkbox style picker, unless it's coupled with a completion selector - although again it's probably easier to edit the .dir-locals.el

Benjamin06:06:36

I always use completing-read or completing-read-multiple.

mpenet19:06:59

The 2nd one. Usually I use that when working on projects that have different naming conventions for their "dev" profile.

mpenet19:06:50

Which is quite rare indeed