* Add after-save-hook to a mode
@ 2012-05-27 22:00 Florian Lindner
2012-05-27 22:11 ` Jambunathan K
2012-05-28 9:08 ` Philipp Haselwarter
0 siblings, 2 replies; 3+ messages in thread
From: Florian Lindner @ 2012-05-27 22:00 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I want to org-mobile-push executed everytime a file in org-mode is
saved. I tried that:
(add-hook 'org-mode-hook
(add-hook 'after-save-hook
(lambda ()
(org-mobile-push)
)))
This seems to war, but the hook is executed regardless of the mode the
file is in. How can I restrict it to org-mode only?
Thanks,
Florian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Add after-save-hook to a mode
2012-05-27 22:00 Add after-save-hook to a mode Florian Lindner
@ 2012-05-27 22:11 ` Jambunathan K
2012-05-28 9:08 ` Philipp Haselwarter
1 sibling, 0 replies; 3+ messages in thread
From: Jambunathan K @ 2012-05-27 22:11 UTC (permalink / raw)
To: Florian Lindner; +Cc: help-gnu-emacs
Florian Lindner <mailinglists@xgm.de> writes:
> Hello,
>
> I want to org-mobile-push executed everytime a file in org-mode is
> saved. I tried that:
>
> (add-hook 'org-mode-hook
> (add-hook 'after-save-hook
> (lambda ()
> (org-mobile-push)
> )))
>
> This seems to war, but the hook is executed regardless of the mode the
> file is in. How can I restrict it to org-mode only?
(add-hook 'after-save-hook
(lambda ()
(when (string= mode-name "Org")
(org-mobile-push))))
> Thanks,
>
> Florian
>
>
--
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Add after-save-hook to a mode
2012-05-27 22:00 Add after-save-hook to a mode Florian Lindner
2012-05-27 22:11 ` Jambunathan K
@ 2012-05-28 9:08 ` Philipp Haselwarter
1 sibling, 0 replies; 3+ messages in thread
From: Philipp Haselwarter @ 2012-05-28 9:08 UTC (permalink / raw)
To: help-gnu-emacs
Your code modifies `after-save-hook', which is a global variable, every
time `org-mode-hook' is run.
`add-hook' also allows to modify hooks buffer-locally. From its
docstring:
> The optional fourth argument, LOCAL, if non-nil, says to modify
> the hook's buffer-local value rather than its global value.
> This makes the hook buffer-local, and it makes t a member of the
> buffer-local value. That acts as a flag to run the hook
> functions of the global value as well as in the local value.
You can use this to change the value of `after-save-hook' only in those
buffers that run the `org-mode-hook'. This should do:
(add-hook
'org-mode-hook
(lambda nil
(add-hook 'after-save-hook
(lambda nil (org-mobile-push))
nil 'local))) ;Only in the current buffer
--
Philipp Haselwarter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-05-28 9:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-27 22:00 Add after-save-hook to a mode Florian Lindner
2012-05-27 22:11 ` Jambunathan K
2012-05-28 9:08 ` Philipp Haselwarter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).