Created
March 14, 2026 08:44
-
-
Save greglook/4a083039bb7a6a4a4263c77e7a7bd6da to your computer and use it in GitHub Desktop.
Clojure editor input example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns edit.example | |
| (:require | |
| [clojure.java.io :as io] | |
| [clojure.java.process :as proc] | |
| [clojure.string :as str]) | |
| (:import | |
| java.io.File)) | |
| (defn editor-input | |
| [] | |
| (let [tmp-file (File/createTempFile "edit.example." ".md")] | |
| (println "Wrote temp file" (str tmp-file)) | |
| (try | |
| (spit tmp-file "Editor Test\n===========\n\nHello, editor!\n\n## An H2\nAhoy\n") | |
| (let [pre-time (.lastModified tmp-file) | |
| editor (proc/start {:in :inherit, :out :inherit, :err :inherit} "nvim" (str tmp-file)) | |
| exit-code @(proc/exit-ref editor) | |
| post-time (.lastModified tmp-file)] | |
| (cond | |
| (not= 0 exit-code) | |
| (println "Editor exited with error:" exit-code) | |
| (= pre-time post-time) | |
| (println "File not modified by user") | |
| :else | |
| (println "Read:\n" (slurp tmp-file)))) | |
| (finally | |
| (.delete tmp-file))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment