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

前端 未结 3 1426
北恋
北恋 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:44

    My take on this:

    (add-hook 'after-change-major-mode-hook #'hack-local-variables)
    

    and either

    (defun my-normal-mode-advice
        (function &rest ...)
      (let ((after-change-major-mode-hook
             (remq #'hack-local-variables after-change-major-mode-hook)))
        (apply function ...)))
    

    if you can live with the annoying

    Making after-change-major-mode-hook buffer-local while locally let-bound!

    message or

    (defun my-normal-mode-advice
        (function &rest ...)
      (remove-hook 'after-change-major-mode-hook #'hack-local-variables)
      (unwind-protect
          (apply function ...)
        (add-hook 'after-change-major-mode-hook #'hack-local-variables)))
    

    otherwise and finally

    (advice-add #'normal-mode :around #'my-normal-mode-advice)
    

提交回复
热议问题