* Temporally/occasionally turn off hooks?
@ 2013-01-29 12:05 Thorsten Jolitz
2013-01-29 19:14 ` Bernt Hansen
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Jolitz @ 2013-01-29 12:05 UTC (permalink / raw)
To: emacs-orgmode
Hi List,
I copied this from Bernt Hansens set-up:
,-----------------------------------------------------------
| org-insert-heading-hook is a variable defined in `org.el'.
| Its value is (bh/insert-heading-inactive-timestamp)
| Original value was nil
`-----------------------------------------------------------
and its often quite usefull to have a timestamp for each newly inserted
todo-item (e.g.). But in other cases, like writing documents or building
Org files programmatically, there is no need for
heading-creation-timestamps, so I would like to turn the timestamp
insertion off.
I could probably use
,-----------------------------------------
| (remove-hook
| 'org-insert-heading-hook
| 'bh/insert-heading-inactive-timestamp
| ’LOCAL)
`-----------------------------------------
to deactivate the behaviour locally, since:
,------------------------------------------------------------------------
| remove-hook is a compiled Lisp function in `subr.el'.
|
| (remove-hook HOOK FUNCTION &optional LOCAL)
|
| Remove from the value of HOOK the function FUNCTION.
| HOOK should be a symbol, and FUNCTION may be any valid function. If
| FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
| list of hooks to run in HOOK, then nothing is done. See `add-hook'.
|
| The optional third argument, LOCAL, if non-nil, says to modify
| the hook's buffer-local value rather than its default value.
`------------------------------------------------------------------------
but this is of course not a very generic solution for a program I want
to share with others, their 'org-insert-heading-hook' might look
different.
Is there a way to inhibit a hook in a program, or to run it only
conditionally in certain situations?
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Temporally/occasionally turn off hooks?
2013-01-29 12:05 Temporally/occasionally turn off hooks? Thorsten Jolitz
@ 2013-01-29 19:14 ` Bernt Hansen
2013-01-30 12:21 ` Thorsten Jolitz
0 siblings, 1 reply; 3+ messages in thread
From: Bernt Hansen @ 2013-01-29 19:14 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
Thorsten Jolitz <tjolitz@googlemail.com> writes:
> I copied this from Bernt Hansens set-up:
>
> ,-----------------------------------------------------------
> | org-insert-heading-hook is a variable defined in `org.el'.
> | Its value is (bh/insert-heading-inactive-timestamp)
> | Original value was nil
> `-----------------------------------------------------------
>
> and its often quite usefull to have a timestamp for each newly inserted
> todo-item (e.g.). But in other cases, like writing documents or building
> Org files programmatically, there is no need for
> heading-creation-timestamps, so I would like to turn the timestamp
> insertion off.
>
> I could probably use
>
> ,-----------------------------------------
> | (remove-hook
<snip>
> but this is of course not a very generic solution for a program I want
> to share with others, their 'org-insert-heading-hook' might look
> different.
>
> Is there a way to inhibit a hook in a program, or to run it only
> conditionally in certain situations?
Hi Thorsten!
I would leave the hook always enabled but make it smart enough to skip
inserting timestamps when you don't want them. Something like the
following:
f9-T will toggle adding the timestamps ON and OFF
f9-t will always insert a timestamp at point
C-RET and M-RET will use the hook which checks if the variable
bh/insert-inactive-timestamps is t before adding the timestamp,
otherwise it does nothing.
--8<---------------cut here---------------start------------->8---
(global-set-key (kbd "<f9> T") 'bh/toggle-insert-inactive-timestamp)
(global-set-key (kbd "<f9> t") 'bh/insert-inactive-timestamp)
(defvar bh/insert-inactive-timestamp t)
(defun bh/toggle-insert-inactive-timestamp ()
(interactive)
(setq bh/insert-inactive-timestamp (not bh/insert-inactive-timestamp))
(message "Heading timestamps are %s" (if bh/insert-inactive-timestamp "ON" "OFF")))
(defun bh/insert-inactive-timestamp ()
(interactive)
(org-insert-time-stamp nil t t nil nil nil))
(defun bh/insert-heading-inactive-timestamp ()
(save-excursion
(when bh/insert-inactive-timestamp
(org-return)
(org-cycle)
(bh/insert-inactive-timestamp))))
(add-hook 'org-insert-heading-hook 'bh/insert-heading-inactive-timestamp 'append)
--8<---------------cut here---------------end--------------->8---
Thanks for this idea :)
Regards,
Bernt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Temporally/occasionally turn off hooks?
2013-01-29 19:14 ` Bernt Hansen
@ 2013-01-30 12:21 ` Thorsten Jolitz
0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Jolitz @ 2013-01-30 12:21 UTC (permalink / raw)
To: emacs-orgmode
Bernt Hansen <bernt@norang.ca> writes:
Hi Bernt,
> I would leave the hook always enabled but make it smart enough to skip
> inserting timestamps when you don't want them. Something like the
> following:
>
> f9-T will toggle adding the timestamps ON and OFF
> f9-t will always insert a timestamp at point
> C-RET and M-RET will use the hook which checks if the variable
> bh/insert-inactive-timestamps is t before adding the timestamp,
> otherwise it does nothing.
great, thank you!
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-01-30 12:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-29 12:05 Temporally/occasionally turn off hooks? Thorsten Jolitz
2013-01-29 19:14 ` Bernt Hansen
2013-01-30 12:21 ` Thorsten Jolitz
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).