Why does emacs put an empty (ns ) definition at the beginning of any newly created *.clj file? Can it be overridden? Version: GNU Emacs 26.3 (build 1, x86_64-slackware-linux-gnu, GTK+ Version 3.18.9) of 2019-08-29
@jr0cket it is not always populated. If you create a empty folder and add a core.clj
file in there, it will create the (ns )
I believe the plugin needs to find a "valid" project structure (either deps or lein) so it can work properly.
@iagwanderson that makes sense, if you dont have a valid project structure you dont get a valid namespace definition. It seems I've always used valid projects 🙂 Do people still use core.clj, I though that convention had been dropped a long time ago?
lein new <projName>
still creates the core.clj
file by default
Thank you for all the responses. I sent the clojure-mode maintainer an email; he pointed me to the clj-refactor functions and hooks. Since I was creating the new file in elisp, I shadowed the cljr-add-ns-to-blank-clj-files variable in a let* block.
@jr0cket I have leinengen 2.9.1, and it still creates core modules.
This is done by clj-refactor
(and if you use clojure-lsp
)
You can disable it for clj-refactor
setting
(setq cljr-add-ns-to-blank-clj-files nil)
and for clojure-lsp
adding to your config.edn
:
{:auto-add-ns-to-new-files? false}
clj-refactor has always added a populated namespace definition when used without clojure-lsp Is there some conflict here between the two?
if you have enabled both flags, it will add duplicated ns, that's why we added to clojure-lsp
the flag to disable it too
Yeah, that is definitely not stock Emacs doing that for you, for sure. Mine doesn't.