From d43f5f9e89b4cbc5beb203c314816c6fe3f7874d Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Wed, 22 Jan 2020 18:41:25 +0900 Subject: [PATCH] Add after-first-visit-hook --- emacs.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/emacs.el b/emacs.el index 1f9867b..180fe83 100644 --- a/emacs.el +++ b/emacs.el @@ -23,6 +23,22 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Some macros for internals +(defvar after-first-visit-hook nil + "Run only once at the first visit of file.") + +(defvar after-first-visit-hook--done nil + "Non-nil when `after-first-visit-hook' has already been called.") + +(defun after-first-visit-hook-run () + "Run `after-first-visit-hook' and clear its config." + (when (not after-first-visit-hook--done) + (run-hooks 'after-first-visit-hook)) + (setq after-first-visit-hook--done t) + (remove-hook 'find-file-hook + 'after-first-visit-hook-run)) +(add-hook 'find-file-hook + 'after-first-visit-hook-run) + (defmacro eval-after-init (&rest body) "If `after-init-hook' has been run, run BODY immediately. Otherwize hook it."