1

I'm trying to build a fn that generates a mock from a schema.

Once connected to the REPL in a Clojure project, I want to be able to generate a mock from a Plumatic schema. I'm using a lib that does that already and it's working. The only problem is it only works if I qualify the symbol with the project namespace. For instance, if the symbol-at-point is User which is in namespace contact.models, I need to concat these so that I pass "contact.models/User" to gen/generate.

Also, If I add the namespace by hand the eval works, but it does not print to the REPL. How do I do that?

(defun generate-mock ()
  (interactive)
  (let* ((sym (symbol-at-point))
         (require-code "(require '[my-lib.generator :as gen])")
         (generate (concat "(gen/generate " (symbol-name sym) ")")))
    (cider-nrepl-sync-request:eval require-code)
    (cider-nrepl-sync-request:eval generate)))
4
  • There is no namespace in emacs-lisp. Can you please provide an example of input and actual vs. desired output?
    – Trevoke
    Commented Jul 21, 2023 at 17:16
  • @Trevoke Once connected to the REPL in a Clojure project, I want to be able to generate a mock from a Plumatic schema. I'm using a lib that does that already and it's working. The only problem is it only works if I qualify the symbol with the project namespace. For instance, if the symbol-at-point is User which is in namespace contact.models, I need to concat these so that I pass "contact.models/User" to gen/generate. Commented Jul 21, 2023 at 19:21
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Commented Jul 21, 2023 at 19:29
  • Put all relevant info in the question, not just in comments. Comments can be deleted at any time. Thx.
    – Drew
    Commented Jul 21, 2023 at 19:29

1 Answer 1

1

I managed to get the namespace with cider-current-ns.

(defun generate-mock ()
  (interactive)
  (let* ((sym (symbol-at-point))
         (current-ns (cider-current-ns))
         (require-code "(require '[my-lib.generator :as gen])")
         (generate (concat "(gen/generate " current-ns "/" (symbol-name sym) ")")))
    (cider-nrepl-sync-request:eval require-code)
    (cider-nrepl-sync-request:eval generate)))
1
  • Please don't pose additional questions in your answer. One question per post, one answer per post, please.
    – Drew
    Commented Jul 21, 2023 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.