Emacs: Set tab indent for just one file on the fly

前端 未结 6 1612
无人及你
无人及你 2021-02-01 17:02

I work on an open source project where the creator sets his tab-indents to 2 spaces.

I\'d like to just enable it on the fly for the one file I work on and not other fil

6条回答
  •  长情又很酷
    2021-02-01 18:08

    I use a snippet of code in my init.el that tries to auto-detect files that use 2-space indents, and switch Emacs's indentation for that file to 2 spaces when it sees such files:

    (add-hook 'js-mode-hook
              (lambda ()
                (when (string-match-p "^  [A-Za-z]" (buffer-string))
                  (make-variable-buffer-local 'js-indent-level)
                  (set-variable 'js-indent-level 2))))
    

提交回复
热议问题