emacs: is before-save-hook a local variable?

前端 未结 5 1376
陌清茗
陌清茗 2021-01-02 04:11

how would I figure this out?

I added delete-trailing-whitespace to the before-save-hook in my c-mode-common-hook, but it loo

5条回答
  •  走了就别回头了
    2021-01-02 04:43

    Yes create a .dir-locals.el file in your project root directory with this contents:

    ((c-mode . ((before-save-hook . (lambda() (delete-trailing-whitespace)) )) ))
    

    This will add this hook only to c-mode buffers below this directory.

    But if you only want a specific file and not a whole directory you should be able to add this to top of file using File Local Variables:

    -*- eval: (setq before-save-hook (lambda() (delete-trailing-whitespace))); -*-
    

    or bottom of file like this:

    ;;; Local Variables: ***
    ;;; eval: (setq before-save-hook (lambda() (delete-trailing-whitespace))) ***
    ;;; End: ***
    

提交回复
热议问题