1 #+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t TeX:t LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
2 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
3 #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TITLE: List of org-mode hooks - examples of use
6 #+EMAIL: bzg AT altern DOT org
11 # This file is the default header for new Org files in Worg. Feel free
12 # to tailor it to your needs.
14 [[file:index.org][{Back to Worg's index}]]
16 This is the list of Org-mode hooks and function variables, with their
17 documentation strings:
19 * Hooks and Function variables
24 Hook that is run after org.el has been loaded.
26 ** =org-pre-cycle-hook=
29 Hook that is run before visibility cycling is happening.
30 The function(s) in this hook must accept a single argument which indicates
31 the new state that will be set right after running this hook. The
32 argument is a symbol. Before a global state change, it can have the values
33 `overview', `content', or `all'. Before a local state change, it can have
34 the values `folded', `children', or `subtree'.
39 Hook that is run after `org-cycle' has changed the buffer visibility.
40 The function(s) in this hook must accept a single argument which indicates
41 the new state that was set by the most recent `org-cycle' command. The
42 argument is a symbol. After a global state change, it can have the values
43 `overview', `content', or `all'. After a local state change, it can have
44 the values `folded', `children', or `subtree'.
46 ** =org-insert-heading-hook=
49 Hook being run after inserting a new heading.
54 Hook that is run after `org-occur' has constructed a sparse tree.
55 This can be used to recenter the window to show as much of the structure
58 ** =org-make-link-description-function=
61 Function to use to generate link descriptions from links. If
62 nil the link location will be used. This function must take two
63 parameters; the first is the link and the second the description
64 org-insert-link has generated, and should return the description
67 ** =org-link-translation-function=
70 Function to translate links with different syntax to Org syntax.
71 This can be used to translate links created for example by the Planner
72 or emacs-wiki packages to Org syntax.
73 The function must accept two parameters, a TYPE containing the link
74 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
75 which is everything after the link protocol. It should return a cons
76 with possibly modified values of type and path.
77 Org contains a function for this, so if you set this variable to
78 `org-translate-link-from-planner', you should be able follow many
79 links created by planner.
81 ** =org-follow-link-hook=
84 Hook that is run after a link has been followed.
86 ** =org-confirm-shell-link-function=
89 Non-nil means, ask for confirmation before executing shell links.
90 Shell links can be dangerous: just think about a link
92 [[shell:rm -rf ~/*][Google Search]]
94 This link would show up in your Org-mode document as \"Google Search\",
95 but really it would remove your entire home directory.
96 Therefore we advise against setting this variable to nil.
97 Just change it to `y-or-n-p' if you want to confirm with a
98 single keystroke rather than having to type \"yes\".
100 ** =org-confirm-elisp-link-function=
103 Non-nil means, ask for confirmation before executing Emacs Lisp links.
104 Elisp links can be dangerous: just think about a link
106 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
108 This link would show up in your Org-mode document as \"Google Search\",
109 but really it would remove your entire home directory.
110 Therefore we advise against setting this variable to nil.
111 Just change it to `y-or-n-p' if you want to confirm with a
112 single keystroke rather than having to type \"yes\".
114 ** =org-refile-target-verify-function=
117 Function to verify if the headline at point should be a refile target.
118 The function will be called without arguments, with point at the
119 beginning of the headline. It should return t and leave point
120 where it is if the headline is a valid target for refiling.
122 If the target should not be selected, the function must return nil.
123 In addition to this, it may move point to a place from where the search
124 should be continued. For example, the function may decide that the entire
125 subtree of the current entry should be excluded and move point to the end
128 ** =org-after-todo-state-change-hook=
131 Hook which is run after the state of a TODO item was changed.
132 The new state (a string with a TODO keyword, or nil) is available in the
133 Lisp variable `state'.
135 ** =org-blocker-hook=
138 Hook for functions that are allowed to block a state change.
140 Each function gets as its single argument a property list, see
141 `org-trigger-hook' for more information about this list.
143 If any of the functions in this hook returns nil, the state change
146 ** =org-trigger-hook=
149 Hook for functions that are triggered by a state change.
151 Each function gets as its single argument a property list with at least
152 the following elements:
154 (:type type-of-change :position pos-at-entry-start
155 :from old-state :to new-state)
157 Depending on the type, more properties may be present.
159 This mechanism is currently implemented for:
163 :type todo-state-change
164 :from previous state (keyword as a string), or nil, or a symbol
165 'todo' or 'done', to indicate the general type of state.
166 :to new state, like in :from
168 ** =org-read-date-minibuffer-setup-hook=
171 Hook to be used to set up keys for the date/time interface.
172 Add key definitions to `minibuffer-local-map', which will be a temporary
175 ** =org-tags-sort-function=
178 When set, tags are sorted using this function as a comparator
180 ** =org-after-tags-change-hook=
183 Hook that is run after the tags in a line have changed.
185 ** =org-columns-modify-value-for-display-function=
188 Function that modifies values for display in column view.
189 For example, it can be used to cut out a certain part from a time stamp.
190 The function must take 2 arguments:
192 column-title The title of the column (*not* the property name)
193 value The value that should be modified.
195 The function should return the value that should be displayed,
196 or nil if the normal value should be used.
198 ** =org-finish-function=
201 Function to be called when `C-c C-c' is used.
202 This is for getting out of special buffers like remember.
207 Mode hook for Org-mode, run after the mode was turned on.
209 ** =org-font-lock-hook=
212 Functions to be called for special font lock stuff.
214 ** =org-after-demote-entry-hook=
217 Hook run after an entry has been demoted.
218 The cursor will be at the beginning of the entry.
219 When a subtree is being demoted, the hook will be called for each node.
221 ** =org-after-promote-entry-hook=
224 Hook run after an entry has been promoted.
225 The cursor will be at the beginning of the entry.
226 When a subtree is being promoted, the hook will be called for each node.
228 ** =org-after-sorting-entries-or-items-hook=
231 Hook that is run after a bunch of entries or items have been sorted.
232 When children are sorted, the cursor is in the parent line when this
233 hook gets called. When a region or a plain list is sorted, the cursor
234 will be in the first entry of the sorted region/list.
236 ** =org-store-link-functions=
239 List of functions that are called to create and store a link.
240 Each function will be called in turn until one returns a non-nil
241 value. Each function should check if it is responsible for creating
242 this link (for example by looking at the major mode).
243 If not, it must exit and return nil.
244 If yes, it should return a non-nil value after a calling
245 `org-store-link-props' with a list of properties and values.
246 Special properties are:
248 :type The link prefix. like \"http\". This must be given.
249 :link The link, like \"http://www.astro.uva.nl/~dominik\".
250 This is obligatory as well.
251 :description Optional default description for the second pair
252 of brackets in an Org-mode link. The user can still change
253 this when inserting this link into an Org-mode buffer.
255 In addition to these, any additional properties can be specified
256 and then used in remember templates.
258 ** =org-create-file-search-functions=
261 List of functions to construct the right search string for a file link.
262 These functions are called in turn with point at the location to
263 which the link should point.
265 A function in the hook should first test if it would like to
266 handle this file type, for example by checking the major-mode or
267 the file extension. If it decides not to handle this file, it
268 should just return nil to give other functions a chance. If it
269 does handle the file, it must return the search string to be used
270 when following the link. The search string will be part of the
271 file link, given after a double colon, and `org-open-at-point'
272 will automatically search for it. If special measures must be
273 taken to make the search successful, another function should be
274 added to the companion hook `org-execute-file-search-functions',
277 A function in this hook may also use `setq' to set the variable
278 `description' to provide a suggestion for the descriptive text to
279 be used for this link when it gets inserted into an Org-mode
280 buffer with \\[org-insert-link].
282 ** =org-execute-file-search-functions=
285 List of functions to execute a file search triggered by a link.
287 Functions added to this hook must accept a single argument, the
288 search string that was part of the file link, the part after the
289 double colon. The function must first check if it would like to
290 handle this search, for example by checking the major-mode or the
291 file extension. If it decides not to handle this search, it
292 should just return nil to give other functions a chance. If it
293 does handle the search, it must return a non-nil value to keep
294 other functions from trying.
296 Each function can access the current prefix argument through the
297 variable `current-prefix-argument'. Note that a single prefix is
298 used to force opening a link in Emacs, so it may be good to only
299 use a numeric or double prefix to guide the search function.
301 In case this is needed, a function in this hook can also restore
302 the window configuration before `org-open-at-point' was called using:
304 (set-window-configuration org-window-config-before-follow-link)
306 ** =org-after-refile-insert-hook=
309 Hook run after `org-refile' has inserted its stuff at the new location.
310 Note that this is still *before* the stuff will be removed from
313 ** =org-todo-setup-filter-hook=
316 Hook for functions that pre-filter todo specs.
318 Each function takes a todo spec and returns either `nil' or the spec
319 transformed into canonical form." )
321 (defvar org-todo-get-default-hook nil
322 "Hook for functions that get a default item for todo.
324 Each function takes arguments (NEW-MARK OLD-MARK) and returns either
325 `nil' or a string to be used for the todo mark." )
327 (defvar org-agenda-headline-snapshot-before-repeat)
329 (defun org-todo (&optional arg)
330 "Change the TODO state of an item.
331 The state of an item is given by a keyword at the start of the heading,
336 The different keywords are specified in the variable `org-todo-keywords'.
337 By default the available states are \"TODO\" and \"DONE\".
338 So for this example: when the item starts with TODO, it is changed to DONE.
339 When it starts with DONE, the DONE is removed. And when neither TODO nor
340 DONE are present, add TODO at the beginning of the heading.
342 With C-u prefix arg, use completion to determine the new state.
343 With numeric prefix arg, switch to that state.
344 With a double C-u prefix, switch to the next set of TODO keywords (nextset).
345 With a tripple C-u prefix, circumvent any state blocking.
347 For calling through lisp, arg is also interpreted in the following way:
349 \"\"(empty string) -> switch to empty state
350 'done -> switch to DONE
351 'nextset -> switch to the next set of keywords
352 'previousset -> switch to the previous set of keywords
353 \"WAITING\" -> switch to the specified keyword, but only if it
354 really is a member of `org-todo-keywords'.
356 ** =org-after-todo-statistics-hook=
359 Hook that is called after a TODO statistics cookie has been updated.
360 Each function is called with two arguments: the number of not-done entries
361 and the number of done entries.
363 For example, the following function, when added to this hook, will switch
364 an entry to DONE when all children are done, and back to TODO when new
365 entries are set to a TODO status. Note that this hook is only called
366 when there is a statistics cookie in the headline!
368 (defun org-summary-todo (n-done n-not-done)
369 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
370 (let (org-log-done org-log-states) ; turn off logging
371 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
373 ** =org-todo-statistics-hook=
376 Hook that is run whenever Org thinks TODO statistics should be updated.
377 This hook runs even if there is no statisics cookie present, in which case
378 `org-after-todo-statistics-hook' would not run.
380 ** =org-ctrl-c-ctrl-c-hook=
383 Hook for functions attaching themselves to `C-c C-c'.
384 This can be used to add additional functionality to the C-c C-c key which
385 executes context-dependent commands.
386 Each function will be called with no arguments. The function must check
387 if the context is appropriate for it to act. If yes, it should do its
388 thing and then return a non-nil value. If the context is wrong,
389 just do nothing and return nil.
391 ** =org-tab-first-hook=
394 Hook for functions to attach themselves to TAB.
395 See `org-ctrl-c-ctrl-c-hook' for more information.
396 This hook runs as the first action when TAB is pressed, even before
397 `org-cycle' messes around with the `outline-regexp' to cater for
398 inline tasks and plain list item folding.
399 If any function in this hook returns t, not other actions like table
400 field motion visibility cycling will be done.
402 ** =org-tab-after-check-for-table-hook=
405 Hook for functions to attach themselves to TAB.
406 See `org-ctrl-c-ctrl-c-hook' for more information.
407 This hook runs after it has been established that the cursor is not in a
408 table, but before checking if the cursor is in a headline or if global cycling
410 If any function in this hook returns t, not other actions like visibility
411 cycling will be done.
413 ** =org-tab-after-check-for-cycling-hook=
416 Hook for functions to attach themselves to TAB.
417 See `org-ctrl-c-ctrl-c-hook' for more information.
418 This hook runs after it has been established that not table field motion and
419 not visibility should be done because of current context. This is probably
420 the place where a package like yasnippets can hook in.
422 ** =org-metaleft-hook=
425 Hook for functions attaching themselves to `M-left'.
426 See `org-ctrl-c-ctrl-c-hook' for more information.
428 ** =org-metaright-hook=
431 Hook for functions attaching themselves to `M-right'.
432 See `org-ctrl-c-ctrl-c-hook' for more information.
437 Hook for functions attaching themselves to `M-up'.
438 See `org-ctrl-c-ctrl-c-hook' for more information.
440 ** =org-metadown-hook=
443 Hook for functions attaching themselves to `M-down'.
444 See `org-ctrl-c-ctrl-c-hook' for more information.
446 ** =org-shiftmetaleft-hook=
449 Hook for functions attaching themselves to `M-S-left'.
450 See `org-ctrl-c-ctrl-c-hook' for more information.
452 ** =org-shiftmetaright-hook=
455 Hook for functions attaching themselves to `M-S-right'.
456 See `org-ctrl-c-ctrl-c-hook' for more information.
458 ** =org-shiftmetaup-hook=
461 Hook for functions attaching themselves to `M-S-up'.
462 See `org-ctrl-c-ctrl-c-hook' for more information.
464 ** =org-shiftmetadown-hook=
467 Hook for functions attaching themselves to `M-S-down'.
468 See `org-ctrl-c-ctrl-c-hook' for more information.
470 ** =org-metareturn-hook=
473 Hook for functions attaching themselves to `M-RET'.
474 See `org-ctrl-c-ctrl-c-hook' for more information.
476 ** =org-agenda-before-write-hook=
477 Defined in: /org-agenda.el/
479 Hook run in temporary buffer before writing it to an export file.
480 A useful function is `org-agenda-add-entry-text'.
482 ** =org-finalize-agenda-hook=
483 Defined in: /org-agenda.el/
485 Hook run just before displaying an agenda buffer.
487 ** =org-agenda-mode-hook=
488 Defined in: /org-agenda.el/
490 Hook for org-agenda-mode, run after the mode is turned on.
492 ** =org-agenda-skip-function=
493 Defined in: /org-agenda.el/
495 Function to be called at each match during agenda construction.
496 If this function returns nil, the current match should not be skipped.
497 Otherwise, the function must return a position from where the search
499 This may also be a Lisp form, it will be evaluated.
500 Never set this variable using `setq' or so, because then it will apply
501 to all future agenda commands. Instead, bind it with `let' to scope
502 it dynamically into the agenda-constructing command. A good way to set
503 it is through options in org-agenda-custom-commands.
505 ** =org-agenda-cleanup-fancy-diary-hook=
506 Defined in: /org-agenda.el/
508 Hook run when the fancy diary buffer is cleaned up.
510 ** =org-agenda-after-show-hook=
511 Defined in: /org-agenda.el/
513 Normal hook run after an item has been shown from the agenda.
514 Point is in the buffer where the item originated.
516 ** =org-clock-heading-function=
517 Defined in: /org-clock.el/
519 When non-nil, should be a function to create `org-clock-heading'.
520 This is the string shown in the mode line when a clock is running.
521 The function is called with point at the beginning of the headline.
523 ** =org-clock-in-prepare-hook=
524 Defined in: /org-clock.el/
526 Hook run when preparing the clock.
527 This hook is run before anything happens to the task that
528 you want to clock in. For example, you can use this hook
529 to add an effort property.
531 ** =org-clock-in-hook=
532 Defined in: /org-clock.el/
534 Hook run when starting the clock.
536 ** =org-clock-out-hook=
537 Defined in: /org-clock.el/
539 Hook run when stopping the current clock.
541 ** =org-clock-cancel-hook=
542 Defined in: /org-clock.el/
544 Hook run when cancelling the current clock.
546 ** =org-clock-goto-hook=
547 Defined in: /org-clock.el/
549 Hook run when selecting the currently clocked-in entry.
551 ** =org-export-preprocess-hook=
552 Defined in: /org-exp.el/
554 Hook for preprocessing an export buffer.
555 Pretty much the first thing when exporting is running this hook.
557 ** =org-export-preprocess-after-include-files-hook=
558 Defined in: /org-exp.el/
560 Hook for preprocessing an export buffer.
561 This is run after the contents of included files have been inserted.
563 ** =org-export-preprocess-after-tree-selection-hook=
564 Defined in: /org-exp.el/
566 Hook for preprocessing an export buffer.
567 This is run after selection of trees to be exported has happened.
568 This selection includes tags-based selection, as well as removal
569 of commented and archived trees.
571 ** =org-export-preprocess-after-blockquote-hook=
572 Defined in: /org-exp.el/
574 Hook for preprocessing an export buffer.
575 This is run after blockquote/quote/verse/center have been marked
578 ** =org-export-preprocess-before-backend-specifics-hook=
579 Defined in: /org-exp.el/
581 Hook run before backend-specific functions are called during preprocessing.
583 ** =org-export-preprocess-final-hook=
584 Defined in: /org-exp.el/
586 Hook for preprocessing an export buffer.
587 This is run as the last thing in the preprocessing buffer, just before
588 returning the buffer string to the backend.
590 ** =org-feed-after-adding-hook=
591 Defined in: /org-feed.el/
593 Hook that is run after new items have been added to a file.
594 Depending on `org-feed-save-after-adding', the buffer will already
597 ** =org-export-html-after-blockquotes-hook=
598 Defined in: /org-html.el/
600 Hook run during HTML export, after blockquote, verse, center are done.
602 ** =org-before-save-iCalendar-file-hook=
603 Defined in: /org-icalendar.el/
605 Hook run before an iCalendar file has been saved.
606 This can be used to modify the result of the export.
608 ** =org-after-save-iCalendar-file-hook=
609 Defined in: /org-icalendar.el/
611 Hook run after an iCalendar file has been saved.
612 The iCalendar buffer is still current when this hook is run.
613 A good way to use this is to tell a desktop calendar application to re-read
616 ** =org-export-latex-after-blockquotes-hook=
617 Defined in: /org-latex.el/
619 Hook run during LaTeX export, after blockquote, verse, center are done.
621 ** =org-checkbox-statistics-hook=
622 Defined in: /org-list.el/
624 Hook that is run whenever Org thinks checkbox statistics should be updated.
625 This hook runs even if `org-provide-checkbox-statistics' is nil, to it can
626 be used to implement alternative ways of collecting statistics information.
628 ** =org-mouse-context-menu-function=
629 Defined in: /org-mouse.el/
631 Function to create the context menu.
632 The value of this variable is the function invoked by
633 `org-mouse-context-menu' as the context menu.
635 ** =org-publish-before-export-hook=
636 Defined in: /org-publish.el/
638 Hook run before export on the Org file.
639 The hook may modify the file in arbitrary ways before publishing happens.
640 The orgiginal version of the buffer will be restored after publishing.
642 ** =org-publish-after-export-hook=
643 Defined in: /org-publish.el/
645 Hook run after export on the exported buffer.
646 Any changes made by this hook will be saved.
648 ** =org-remember-before-finalize-hook=
649 Defined in: /org-remember.el/
651 Hook that is run right before a remember process is finalized.
652 The remember buffer is still current when this hook runs.
654 ** =org-remember-mode-hook=
655 Defined in: /org-remember.el/
657 Hook for the minor `org-remember-mode'.
659 ** =org-src-mode-hook=
660 Defined in: /org-src.el/
662 Hook run after Org switched a source code snippet to its Emacs mode.
665 - when editing a source code snippet with \"C-c '\".
666 - When formatting a source code snippet for export with htmlize.
668 You may want to use this hook for example to turn off `outline-minor-mode'
669 or similar things which you want to have when editing a source code file,
670 but which mess up the display of a snippet in Org exported files.
674 * Examples for using hooks
676 Feel free to give example of how do you use these hooks. Ideas for
677 other hooks are also welcome.
679 ** org-follow-link-hook :bzg:
681 If you want to display dormant article when following Gnus articles:
683 #+BEGIN_SRC emacs-lisp
684 (add-hook 'org-follow-link-hook
685 (lambda () (if (eq major-mode 'gnus-summary-mode)
686 (gnus-summary-insert-dormant-articles))))
689 ** org-agenda-after-show-hook
691 To get a compact view during follow mode in the agenda, you could try
694 #+begin_src emacs-lisp
695 (defun my-compact-follow ()
696 "Make the view compact, then show the necessary minimum."
699 (while (org-up-heading-safe))
701 (let ((org-show-siblings nil)
702 (org-show-hierarchy-above t))
705 (org-back-to-heading t)
708 (add-hook 'org-agenda-after-show-hook 'my-compact-follow)