Fork me on GitHub
#emacs
<
2020-12-27
>
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

ericdallo20:12:17

This is done by clj-refactor (and if you use clojure-lsp)

ericdallo20:12:46

You can disable it for clj-refactor setting

(setq cljr-add-ns-to-blank-clj-files nil)

ericdallo20:12:33

and for clojure-lsp adding to your config.edn :

{:auto-add-ns-to-new-files? false}

practicalli-johnny23:12:16

clj-refactor has always added a populated namespace definition when used without clojure-lsp Is there some conflict here between the two?

ericdallo23:12:59

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

andy.fingerhut23:12:13

Yeah, that is definitely not stock Emacs doing that for you, for sure. Mine doesn't.

bartuka17:12:08

@U05254DQM it is not always populated. If you create a empty folder and add a core.cljfile in there, it will create the (ns )

bartuka17:12:36

I believe the plugin needs to find a "valid" project structure (either deps or lein) so it can work properly.

practicalli-johnny17:12:00

@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
bartuka17:12:51

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.

3