Fork me on GitHub
Mark Naylor20:12:15

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


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.


@U05254DQM it is not always populated. If you create a empty folder and add a core.cljfile 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.


@UBSREKQ5Q 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?

🙂 3

lein new <projName> still creates the core.clj file by default

😭 3
Mark Naylor22:12:38

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.

👍 6
Mark Naylor18:12:24

@U05254DQM I have leinengen 2.9.1, and it still creates core modules.