This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-28
Channels
- # announcements (5)
- # babashka (7)
- # beginners (101)
- # biff (9)
- # calva (46)
- # cider (6)
- # clj-yaml (2)
- # cljsrn (13)
- # clojure (11)
- # clojure-europe (43)
- # clojure-nl (13)
- # clojure-norway (22)
- # clojurescript (20)
- # conjure (1)
- # cursive (7)
- # data-science (2)
- # datomic (26)
- # emacs (38)
- # graphql (27)
- # gratitude (5)
- # hoplon (8)
- # hugsql (22)
- # humbleui (2)
- # hyperfiddle (6)
- # introduce-yourself (8)
- # joyride (3)
- # lsp (79)
- # malli (6)
- # nbb (67)
- # portal (16)
- # rdf (27)
- # reagent (42)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (36)
- # test-check (17)
- # tools-deps (1)
- # xtdb (15)
I am a total noob when it comes to emacs lisp, but I want to read a projects deps.edn and extract its aliases and present to ciders jack in
I'm not sure if cider already have the capacity to do something like that, but you might want to look at https://github.com/clojure-emacs/parseedn to get data out of deps.edn
You could also shell out to babashka and write normal clojure :) I normally work with EDN like that.
This was actually my first thought, call a script and reach for the result in emacs
I‘m looking for the how to do that atm since my emacs foo is lacking 😅
Haha, exactly… :rolling_on_the_floor_laughing:
Oh, didn’t know that… will have a look there
Just found it in the docs. Cider jack in cljs does parse it from the shadow-Cluster file
Should be similar to this
Sry, this
https://github.com/clojure-emacs/cider/blob/e9324acf81391f089932c657b70031ae3c3d0824/cider.el#L863
as I'm reading my code, I'm realizing that my approach of writing Clojure forms and parsing them as quoted Elisp is probably a very very bad idea. But I promised to post the code, so I'm posting the code 🙂
(require 's)
(defmacro t-comment (&rest _) "Do nothing."
nil)
(defun t-str (&rest xs)
"Join XS into string."
(apply #'s-concat
(mapcar (lambda (s)
(format "%s" s))
xs)))
(defun t-bb-fun (form)
"Convert quoted FORM to Babashka shell invocation."
(t-str "bb -e " "'" form "'"))
;; Example:
;;
;; (t-bb-fun '(assoc *input* :message "Hello!"))
(defmacro t-bb (form)
"Convert FORM to babashka shell invocation."
(list 't-bb-fun (list 'quote form)))
(t-comment
;; here's an example:
(shell-command-to-string
(t-bb (+ 1 2)))
;; => "3\n"
(message
(shell-command-to-string
(t-bb (hash-map :x 1 :y 2))))
;; from *Messages"
;;
;; "{:y 2, :x 1}"
)
thanks!
cider actually uses the same package you recommended for parsing edn 🙂
wohoo…. got it working 🙂
(defun cider--deps-parse-aliases (hash)
(let* ((builds (when (hash-table-p hash)
(gethash :aliases hash)))
(build-keys (when (hash-table-p builds)
(hash-table-keys builds))))
(append build-keys '(:none))))
(defun cider--deps-get-aliases ()
(let ((deps-edn (concat (clojure-project-dir) "deps.edn")))
(when (file-exists-p deps-edn)
(with-temp-buffer
(insert-file-contents deps-edn)
(let ((hash (car (parseedn-read '((map . identity))))))
(cider--deps-parse-aliases hash))))))
(defun cider-get-deps-aliases ()
(interactive)
(let ((options (completing-read "Select alias to run: "
(cider--deps-get-aliases))))))
just in case someone cares 🙂 feedback welcome
(cider--deps-parse-aliases hash)
there is a space too many.
Here is 1 way to put it into a command:
(defun cider--deps-parse-aliases (hash)
(let* ((builds (when (hash-table-p hash)
(gethash :aliases hash)))
(build-keys (when (hash-table-p builds)
(hash-table-keys builds))))
(append build-keys '(:none))))
(defun cider--deps-get-aliases (deps-edn)
(cider--deps-parse-aliases
(car (with-temp-buffer
(insert-file-contents deps-edn)
(parseedn-read '((map . identity)))))))
(defun cider-jack-in-with-an-alias-from-deps ()
(interactive)
(if-let* ((deps-edn (concat (clojure-project-dir) "deps.edn"))
(_ (file-exists-p deps-edn)))
(let* ((my-alias
(completing-read "Select alias to run: " (cider--deps-get-aliases deps-edn)))
(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 updated cider--deps-get-aliases
to be more inside out + and it takes the file as an arg. But your version is fineI made a version using dash
pattern matching
(defun cider--deps-parse-aliases (edn)
(-when-let*
(((m) edn)
((&hash :aliases aliases) m))
(append (hash-table-keys aliases) '(:none))))
(defun cider--deps-get-aliases (deps-edn)
(cider--deps-parse-aliases
(with-temp-buffer
(insert-file-contents deps-edn)
(parseedn-read '((map . identity))))))
Will try this evening to append the result to the jack-in command
The plan is to check the preferred-build tool var, to either parse the project.clj profiles or deps.edn aliases. Check if there’s anything that overrides the default repl command and then do the jack in
But first trying to get the happy path working 😅
As my emacs lisp skills are lacking
Cool! Still haven’t explored the cider code enough 😅
Hi guys, I have a multi repo, and my issue is that subprojects are recognized as projects. If I understand it well this is due to my projectile setting. So all searches are done in the subproject only. I would like to stick to the global mono repo and stop the auto discorvery thing, but I don't know how to do. Can you gave me a clue what's the best option to search, I tried many and failed many times already. If useful, the global repo I want to stick to is a git repo, the subrepo are recognized as clojure projects.
Setting this: https://github.com/lukaszkorecki/command-center/blob/master/settings/lk/navigation.el#L32-L38 made it workable for me - find-file works with in a sub-project and C-c p p
shows a project selector so I can jump between different codebases within a single repo
That’s surprising that projectile is discovering the sub-projects first. Do you have .git
directories in each of the subprojects or something?
One thing you can do is put a .projectile
file in the directory where you want projectile to consider the project.
yes, I don't get the link between the doc I read and the behavior I end up with. Maybe a behavior of setup layers I use: doom + lsp clojure... In anycase, the .projectile solution seems to work. thx @U01ERKW6F18. I keep your solution @U0JEFEZH6 in case the other one is not actually not working. Thanks for the help!