How to set indent-line-function variable for buffer local
The indent-line-function variable decide how Emacs will do indentation. I always use indent-relative. If you want to indent relatively in current buffer, execute
M-x set-variable RET indent-line-function RET indent-relative
The indent-relative always indent to previous line's first nonblank character. In LISP mode, this variable is set as buffer local variable and the value is lisp-indent-line:
(setq-local indent-line-function 'lisp-indent-line)
This statement is defined in function lisp-mode-variables. And executed each time the LISP buffer is created, I have to execute set-variable each time which is cumbersome.
The first solution is setq the variable in Emacs init file. But the setq-local will override global setting, so the following configuration in .emacs does not work
(setq indent-line-function 'indent-relative)
I tried another way like this
(add-hook 'lisp-mode-hook (lambda () (setq-local indent-line-function 'indent-relative) ) )
Still don't work.
After a bit try, I figure out the right way to do it
(add-hook 'emacs-lisp-mode-hook (function (lambda () (setq-local indent-line-function 'indent-relative) ) ))
I am curious about the difference between lisp-mode-hook and emacs-lisp-mode-hook.
Turns out there are two kinds of LISP in Emacs: the Emacs LISP and general purpose LISP like Common LISP. The file name extension of Emacs LISP is .el and other LISP is .l or .lsp, .lisp.
Emacs
Search in Emacs
Configuring Emacs
Editing in Emacs
Basic Editings