Fork me on GitHub
#clojure
<
2024-02-24
>
Karol Wójcik09:02:16

Question: How can I make the symbols from user.clj accessible in every Clojure namespace?

Karol Wójcik10:02:26

Perfect! Thank you so much!

😊 1
danieroux11:02:28

We do it this way: In user.clj we have:

(load "monkey_patch_clojure_core")
Then in monkey-patch-clojure-core we have (amongst other things) this
(ns monkey-patch-clojure-core
  (:require
   [taoensso.timbre :as log]))

(log/info "Monkey patching clojure.core, adding:")
(log/info (str "  " 'pbcopy))
(log/info (str "  " 'pbcopy-pr))

(ns clojure.core)

(defmacro pbcopy
  "OSX Super convenience: The result of form will be in the OSX paste buffer.

  Assumes string."
  [& body]
  `(clojure.java.shell/sh "pbcopy" :in ~@body))

(defmacro pbcopy-pr
  "OSX Super convenience: The result of form will be in the OSX paste buffer, after pr-str

  A cleverer thing can happen here: `:in` could be `*out*`. Later."
  [& body]
  `(clojure.java.shell/sh "pbcopy" :in (pr-str ~@body)))

danieroux11:02:03

This is our current monkey patches, and would love comments on it: https://gist.github.com/danieroux/dfb277f47b74fc61c87a92d47edd8c5a

Mario Trost07:03:25

@U9E8C7QRJ I’m too much of a beginner to comment on your monkey patches, but I’m glad I found it and will shamelessly steal it if that’s okay 🙂

danieroux14:03:23

Steal and remix 😄

🙏 1
vlaaad13:02:23

Wow, it's been 5 years since Maybe Not...

rich 20
jjttjj21:02:30

I'm trying to figure out how to "kill" a remote-prepl loop that I want to "manage" the input of in my own code rather than using *in*. My example [edit: code in 🧵] is slightly modified from https://github.com/Olical/how-to-be-a-repl-sorcerer/blob/b6bd530f3d0c6b165248d980d7ce6cd28e8da51f/src/sorcery/main.clj#L20. It basically sends a command to a remote prepl and returns the first value the out-fn receives. My thinking is that if I have code that want's to run eval once on a remote-prepl, I want to make sure it doesn't just keep spawning threads each time. My expectation is that closing the reader should stop the remote prepl process. How can I kill a remote prepl like this? Should I not care that I'm spawning endless new remote-prepl threads? (I have a hunch this is related to https://clojure.atlassian.net/browse/CLJ-2509 but I'm not positive)

jjttjj21:02:51

How can I get "DONE" to print?

(ns prepl
  (:require [clojure.core.server :as server])
  (:import [java.io PipedReader PipedWriter]))

(def srv
  (server/start-server {:accept 'clojure.core.server/io-prepl
                        :port   0
                        :name   "srv"}))

(defn remote-eval [code]
  (with-open [reader (PipedReader.)
              writer (PipedWriter.)]
    (.connect reader writer)
    (let [result! (promise)]
      (future
        (server/remote-prepl
          "localhost" (.getLocalPort srv)
          reader
          (fn [msg]
            (deliver result! msg)))
        (println "DONE"))
      (.write writer code)
      (.flush writer)
      @result!

      ;; doesn't print "DONE"
      (let [r @result!]
        (.close reader)
        (.close writer)

        ;;(.write writer ":repl/quit\n") ;; also tried this
        ;;(.flush writer)

        r))))

(remote-eval "(+ 1 2 3)")

J21:02:45

Hi! How use username/password with a :mvn/repos in deps.edn?