Open VladimirAlexiev opened 4 years ago
@VladimirAlexiev ,
If you want to restrict your hook for saving files in markdown-mode, not all files as your code currently does, you would have to use a 2-step approach like the following:
(add-hook 'markdown-mode-hook
(lambda ()
(add-hook 'before-save-hook #'my-markdown-toc-refresh nil :local)))
The add-hook function has the LOCAL argument which must be set to non-nil to modify the hook's buffer-local value.
Thanks @pierre-rouleau. This works perfectly:
(add-hook 'markdown-mode-hook
(lambda ()
(add-hook 'before-save-hook #'markdown-toc-refresh-toc)
))
I always forget to call markdown-toc-generate-or-refresh-toc before I save (half my commits just say "TOC" ;-))
So I wrote this little function
(Note: #41 mentions
updateOnSave
as a feature of Atom and VSCode)