How to keep dir-local variables when switching major modes?

前端 未结 3 1433
北恋
北恋 2020-12-03 09:10

I\'m committing to a project where standard indentations and tabs are 3-chars wide, and it\'s using a mix of HTML, PHP, and JavaScript. Since I use Emacs for everything, and

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 09:42

    Be warned that I have not tried this, so it may produce undesired results ranging from your dir-local variables not being applied, to Emacs attempting to strangle your cat; by any sensible definition of how Emacs should behave, this is almost certainly cheating. On the other hand, it's all in the standard library, so it can't be that much of a sin. (I hope.)

    Evaluate the following:

    (add-hook 'after-change-major-mode-hook
              'hack-dir-local-variables-non-file-buffer)
    

    From then on, when you change major modes, dir-local variables should (I think) be reapplied immediately after the change.

    If it doesn't work or you don't like it, you can undo it without restarting Emacs by replacing 'add-hook' with 'remove-hook' and evaluating the form again.

提交回复
热议问题