Every mode in Emacs has its own rules for indentation. I don't want that. How can I disable it and have custom indentation rules for every mode?
-
3Unfortunately, what you seek is impossible -- that is not how Emacs was designed. Each mode that sets buffer-local variables or that alters global variables, will need to be modified by the user with things like major mode hooks -- or by setting variables established by the particular major modes being used. You will probably be happiest with your own major modes, but this will take substantial time to properly configure to your liking. If you have some OCD like me, in the end you will be happy because you can control everything.– lawlistCommented May 8, 2015 at 4:52
-
@lawlist Great! :P– AdamCommented May 8, 2015 at 4:53
-
2It's possible to just rebind TAB and RET everywhere, to functions that just ignore any and all indentation variables. The only difficulty is that you'll have to write your own indentation function, that's what "custom indentation rules" would mean.– MalabarbaCommented May 8, 2015 at 8:20
2 Answers
Here's the docstring for the function indent-according-to-mode
:
Indent line in proper way for current major mode. Normally, this is done by calling the function specified by the variable
indent-line-function
. However, if the value of that variable isindent-relative
orindent-relative-maybe
, handle it specially (since those functions are used for tabbing); in that case, indent by aligning to the previous non-blank line.
If you want to turn off indentation (but why...?) in a particular buffer, you can more or less achieve this via M-: (setf indent-line-function #'indent-relative-maybe)
(but have a look at indent-relative-maybe
's docstring for more information). If you want to make that the default for a given mode, put the line in the mode hook.
If you want to write your own indentation rules, you can (setf indent-line-function #'your-custom-function)
in the mode hook.
Please consider, however, that writing a custom indentation function is a non-trivial amount of work (browse the code for lisp-indent-function
and you'll see what I mean), so unless you have a really compelling reason to deviate from the default indentation style, it's probably not worth the effort. Moreover, it's arguably a bad idea: letting Emacs indent according to the default indentation rules means that your code is more likely to conform to general coding conventions, which will make it easier for other people to read your code.
(defun indent-according-to-mode nil)
There might be some mode-specific indent-functions which still need treatment.