Fork me on GitHub
#emacs
<
2024-08-02
>
jumar05:08:03

How can I customize the default template used when a new clojure file is created? Right now, when I create a new file myapp/src/package/a.clj, it simply creates this

(ns package.a)
I would like to add (set! *warn-on-reflection* true) to it
(ns package.a)

(set! *warn-on-reflection* true)

hiredman05:08:19

If you are using clojure-lsp that is likely what is adding the initial ns form and I don't believe it is configurable

jumar06:08:12

That's good to know but I don't use clojure-lsp 🙂

jumar06:08:24

I think it's cljr-add-ns-to-blank-clj-files that causes it, in my case.

vemv12:08:02

cljr--add-ns-if-blank-clj-file is very simple to understand Currently it doesn't have a place to add that PR welcome for allowing a defcustom specifying arbitrary contents after the ns. Could be a lambda taking a hashmap as arguments (currently with only one key, namely is-test-ns)

vemv12:08:55

Or simply advice-add that function if you'd prefer the ghetto approach

Ed20:08:34

No idea if this is useful for anyone, but I just cobbled together something for testing things mentioned in org docs. Given something like this in an org file

#+name: My Test
#+begin_src clojure -t :results silent
  (+ 1 2)
  ;; =>
  5
#+end_src
a quick one-liner of
awk 'BEGIN { P=0 ; NAME="" } { if (tolower($0) ~ /^..name: /) {split($0,a,":") ; NAME=a[2] } else { if (tolower($0) ~ /^..begin_src *clojure.*-t/) { P=1 } else { if ($0 ~ /^..end_src/) { if (P > 0) { print "(if (not= *1 *2) (throw (new AssertionError (str \"FAIL" NAME " expected: \\n\" (pr-str *1) \"\\n\\nactual:\n\" (pr-str *2) \"\\n\\n\"))))\n\n" } ; P=0 ; NAME="" } ; if (P > 0) { print $0 } } } } ' `find . -iname '*.org'` | clojure >/dev/null
spits out error messages like
Execution error (AssertionError) at user/eval3 (REPL:1).
FAIL My Test expected: 
5

actual:
3
Not made it actually fail the build yet, but I'm sure that'll not be too hard. Is anyone else doing something better than this for keeping docs up to date?

1
👍 1