Fork me on GitHub
#cider
<
2024-07-04
>
Oscar Vargas Torres10:07:55

Continuing this conversation here at #C0617A8PQ.

vemv14:07:44

Try setting cider-clojure-cli-aliases to ":dev/reload" Delete the code that touches cider-clojure-cli-global-options , I think it's a confusing defcustom, it got deprecated and then introduced again

Oscar Vargas Torres14:07:38

Do I need to explicitly add

io.github.tonsky/clj-reload {:mvn/version "0.7.1"}
to my project deps.edn? With @U04V70XH6’s https://github.com/seancorfield/deps-new?tab=readme-ov-file#create-an-application template, it seems that clj-reload from my global ~/.config/clojure/deps.edn is ignored...

vemv14:07:47

Yes you do need it Try the simplest thing first (adding it to the project's deps.edn), if it works, then experiment with a global setup

awesome 1
thanks3 1
Oscar Vargas Torres14:07:14

How can I tell emacs to reload my project definition after I change something in deps.edn?

Oscar Vargas Torres14:07:26

For example, after adding a dependency?

vemv14:07:04

M-x sesman-restart performs jack-in again in a given project I don't use it a lot but I think it works correctly! (clojure 1.12 has a new feature for deps reloading, for now I'd stick to what we know that works)

Oscar Vargas Torres00:07:25

I wrote some elisp code that works. Pasting here just in case someone else find it useful.

(require 'projectile)
(require 'parseedn)

(defun get-project-root ()
  "Get the root directory of the current project."
  (if (projectile-project-p)
      (projectile-project-root)
    default-directory))

(defun extract-ns-default (deps-file)
  "Extract the ns-default from the :run-x alias in deps.edn."
  (with-temp-buffer
    (insert-file-contents deps-file)
    (goto-char (point-min))
    (let* ((deps-data (parseedn-read-str (buffer-string)))
           (aliases (gethash :aliases deps-data))
           (run-x (gethash :run-x aliases)))
      (gethash :ns-default run-x))))

(defun set-cider-repl-init-code ()
  (let ((ns (extract-ns-default (concat (get-project-root) "deps.edn"))))
    (if ns
        (list (format "(in-ns '%s)" ns))
      (list))))  ;; return an empty string if no namespace is found

;; Hook into CIDER's jack-in hook to set the init code dynamically
(with-eval-after-load 'cider
  (setq cider-repl-init-code (set-cider-repl-init-code)))
This works with the assumption the deps.edn file lives at the root of the project (found with projectile), and that it has a structure like:
{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.11.3"}
        io.github.tonsky/clj-reload {:mvn/version "0.7.1"}}
 :aliases
 {:run-m {:main-opts ["-m" "oscarvarto.hello-world"]}
  :run-x {:ns-default oscarvarto.hello-world
          :exec-fn greet
          :exec-args {:name "Clojure"}}
  :build {:deps {io.github.clojure/tools.build
                 {:mvn/version "0.10.3"}}
          :ns-default build}
  :test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
                      io.github.cognitect-labs/test-runner
                      {:git/tag "v0.5.1" :git/sha "dfb30dd"}}}}}
(this was generated from the https://github.com/seancorfield/deps-new?tab=readme-ov-file#create-an-application)

Oscar Vargas Torres00:07:51

I wrote the code going backwards. Checked that the final

(with-eval-after-load 'cider
  (setq cider-repl-init-code (set-cider-repl-init-code)))
worked first with a hard-coded namespace/ cider-repl-init-code, then checked the other functions, fixing one by one. LLM helped me a bit, but a lot of suggestions were wrong. However, little by little, I could fix stuff, by checking the error messages and looking at the docs.

vemv00:07:48

Nice to hear, great work! emacs-spin

Oscar Vargas Torres00:07:50

I think this exercise helped me a lot. Hopefully I got a little bit more of understanding of what interactive development means.

vemv00:07:53

Yes Emacs is a prime example of interactive development, and also of creating self-documenting systems Suerte con todo compadre

❤️ 1
cider 1
emacs-spin 1
Oscar Vargas Torres03:07:53

Could anybody take a look at my initialization code for CIDER nREPL, and suggest an improvement/fix? This is not working:

(defun set-cider-repl-init-code ()
  (let ((ns (extract-ns-default (concat (get-project-root) "deps.edn"))))
    (if ns
        ;;(list (format "(in-ns '%s)" ns)) ;; <== This works. But below initialization to load/require namespaces don't.
        (list (format "(in-ns '%s)
(do (require '[clojure.core :as c]
             '[clojure.repl :as r])
    (println \"Required namespaces loaded.\"))
" ns))
      (list))))  ;; return an empty string if no namespace is found

vemv09:07:35

What does "not working" mean? Try putting dummy code like (spit "a" "a") , does it get run?

matt20:08:50

Anyone else running into problems with cider's docstring stuff breaking completions in emacs? Not sure if this is a bug or not. Ran into this using corfu with docs always displayed in corfu-popupinfo, but the problem was reproducible with : 1. emacs -Q 2. M-x package-install cider 3. I opened a clojure file, did cider-connect-clj to a running repl 4. M-x toggle-debug-on-error 5. run complete-symbol with M-tab on a completion that includes a namespace or otherwise doesn't have its own docstring. Specifically I typed '(h' and hit M-tab` a couple times Backtrace

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  replace-regexp-in-string("\n  " "\n" nil)
  cider-docstring--format(nil)
  cider-eldoc-format-variable("ha" ("ns" nil "class" nil "symbol" ".nil" "arglists" nil "docstring" nil "doc-fragments" nil "doc-first-sentence-fragments" nil "doc-block-tags-fragments" nil "type" "variable"))
  cider-eldoc(#f(compiled-function (string &rest plist) #))
  eldoc-documentation-default()
  eldoc--invoke-strategy(nil)
  eldoc-print-current-symbol-info()
  #()
  apply(# nil)
  timer-event-handler([t 0 0 500000 nil # nil idle 0 nil])
emacs version is 29.4 on opensuse tumbleweed

vemv21:08:36

There was nil fix for cider-docstring--format . Are you on cider master / latest unstable?

matt22:08:39

master, repl reads CIDER 1.15.1 (Cogne). Tried an older version too and got the same result.

vemv22:08:28

Please create an issue and we'll attend it asap

vemv22:08:48

(indicate exact version for master, e.g. git sha)

matt22:08:31

Thanks, will do

Oscar Vargas Torres03:07:53

Could anybody take a look at my initialization code for CIDER nREPL, and suggest an improvement/fix? This is not working:

(defun set-cider-repl-init-code ()
  (let ((ns (extract-ns-default (concat (get-project-root) "deps.edn"))))
    (if ns
        ;;(list (format "(in-ns '%s)" ns)) ;; <== This works. But below initialization to load/require namespaces don't.
        (list (format "(in-ns '%s)
(do (require '[clojure.core :as c]
             '[clojure.repl :as r])
    (println \"Required namespaces loaded.\"))
" ns))
      (list))))  ;; return an empty string if no namespace is found