I have a project where I want to disable format-all-mode
for all my python files. I can do this manually by running M-x format-all-mode
every time I open up a python file for that project.
I tried automating this by setting my .dir-locals.el
to this:
((python-mode
(eval . (progn
(make-local-variable 'format-all-mode)
(setq format-all-mode nil)))
))
I've also tried:
((python-mode
(eval . (progn
(format-all-mode nil)))
))
but format-all-mode
continues to be t
every time I open a python file. I've confirmed that my .dir-locals.el
settings are otherwise working, because when I add something like (setq blah "asdf")
inside the progn
function, I see that variable in my buffer.
What am I missing in order to configure the buffer-local format-all-mode
variable?
Here are the docs when I describe this format-all-mode
variable:
format-all-mode is a buffer-local variable defined in format-all.el.
Value in #<buffer my-file.py>
t
Buffer values Global value Toggle Set
Documentation
Non-nil if Format-All mode is enabled.
Use the command format-all-mode to change this variable.
Key Bindings
This command is not in any keymaps.
References
References in format-all.el:
(define-minor-mode format-all-mode ...) 2 references
Find all references
Update
I should've mentioned that I'm using Doom emacs, which has modified the format-all-mode so that it cannot be disabled with the usual (format-all-mode -1)
.
I followed these instructions: https://docs.doomemacs.org/latest/modules/editor/format/
and got it working with the following value in my .dir-locals.el
:
((python-mode
(eval . (progn
;; this doesn't work, because we're using doom emacs:
;; (format-all-mode -1)
;;
;; https://docs.doomemacs.org/latest/modules/editor/format/
;; TODO: add python-mode to the list, instead of overwriting the whole list
(setq +format-on-save-enabled-modes
'(not python-mode sql-mode org-mode emacs-lisp-mode))
))
))
It's a hack though, since +format-on-save-enabled-modes
isn't buffer local. I'm not sure if there's a better way - any help is appreciated!
((python-mode (eval . (format-all-mode -1))))
. I didn't check the syntax though.Non-nil if Format-All mode is enabled.
(I referenced the output above)format-all-mode
with a negative argument. If the mode is disabled, then the variableformat-all-mode
should automatically be set tonil
. Setting the variable does not disable the mode in general. So try this: open a python file, check the variable (which should bet
if the mode is automatically enabled); then doM-: (format-all-mode -1)
to disable the mode and check the variable again: it should now benil
. If that's all as it should be, then you have to make sure that the syntax of your entry in the.dir-locals.el
file is correct.