Skip to content

Instantly share code, notes, and snippets.

@wpcarro
Created August 4, 2019 20:25
Show Gist options
  • Select an option

  • Save wpcarro/a6650d0a43933627add311aa57413ec7 to your computer and use it in GitHub Desktop.

Select an option

Save wpcarro/a6650d0a43933627add311aa57413ec7 to your computer and use it in GitHub Desktop.
More ergonomic way to add before-save-hook in ELisp
;; This macro hopefully provides a more ergonomic way to add mode-specific hooks before buffer save events.
;;
;; In ELisp you might see docs that tell you to write the following:
;; (add-hook 'reason-mode-hook (lambda () (add-hook 'before-save-hook #'refmt-before-save)))
;;
;; Instead of writing this, use this macro to write:
;; (add-hook-before-save 'reason-mode-hook #'refmt-before-save)
(defmacro add-hook-before-save
(mode f)
`(add-hook ,mode
(lambda ()
(add-hook 'before-save-hook ,f))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment