Hi Tianxiang,
Tianxiang Xiong <[email protected]> writes:
> (add-hook 'org-mode-hook
> (lambda ()
> (add-hook 'after-save-hook 'tangle-init nil t)))
>
> However, when I open my init.org file, I see that the after-save-hook
> variable is nil. If I manually reapply org-mode, however, it works as
> expected.
If you define the hook then kill the buffer containing init.org then
reopens it, you don't need to manually M-x org-mode RET in order for
the hook to be taken into account. IOW: the hook runs fine, it's
just that your buffer was already in org-mode.
Can you confirm this?
To me
(add-hook 'after-save-hook (lambda ()
(when (derived-mode-p 'org-mode)
(tangle-init)))
seems more "natural" anyway.
Thanks,
--
Bastien