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.
29 Hook that is run after `org-cycle' has changed the buffer visibility.
30 The function(s) in this hook must accept a single argument which indicates
31 the new state that was set by the most recent `org-cycle' command. The
32 argument is a symbol. After a global state change, it can have the values
33 `overview', `content', or `all'. After a local state change, it can have
34 the values `folded', `children', or `subtree'.
36 ** =org-insert-heading-hook=
39 Hook being run after inserting a new heading.
44 Hook that is run after `org-occur' has constructed a sparse tree.
45 This can be used to recenter the window to show as much of the structure
48 ** =org-make-link-description-function=
51 Function to use to generate link descriptions from links. If
52 nil the link location will be used. This function must take two
53 parameters; the first is the link and the second the description
54 org-insert-link has generated, and should return the description
57 ** =org-link-translation-function=
60 Function to translate links with different syntax to Org syntax.
61 This can be used to translate links created for example by the Planner
62 or emacs-wiki packages to Org syntax.
63 The function must accept two parameters, a TYPE containing the link
64 protocol name like \"rmail\" or \"gnus\" as a string, and the linked path,
65 which is everything after the link protocol. It should return a cons
66 with possibly modified values of type and path.
67 Org contains a function for this, so if you set this variable to
68 `org-translate-link-from-planner', you should be able follow many
69 links created by planner.
71 ** =org-follow-link-hook=
74 Hook that is run after a link has been followed.
76 ** =org-confirm-shell-link-function=
79 Non-nil means, ask for confirmation before executing shell links.
80 Shell links can be dangerous: just think about a link
82 [[shell:rm -rf ~/*][Google Search]]
84 This link would show up in your Org-mode document as \"Google Search\",
85 but really it would remove your entire home directory.
86 Therefore we advise against setting this variable to nil.
87 Just change it to `y-or-n-p' of you want to confirm with a
88 single keystroke rather than having to type \"yes\".
90 ** =org-confirm-elisp-link-function=
93 Non-nil means, ask for confirmation before executing Emacs Lisp links.
94 Elisp links can be dangerous: just think about a link
96 [[elisp:(shell-command \"rm -rf ~/*\")][Google Search]]
98 This link would show up in your Org-mode document as \"Google Search\",
99 but really it would remove your entire home directory.
100 Therefore we advise against setting this variable to nil.
101 Just change it to `y-or-n-p' of you want to confirm with a
102 single keystroke rather than having to type \"yes\".
104 ** =org-after-todo-state-change-hook=
107 Hook which is run after the state of a TODO item was changed.
108 The new state (a string with a TODO keyword, or nil) is available in the
109 Lisp variable `state'.
111 ** =org-after-tags-change-hook=
114 Hook that is run after the tags in a line have changed.
116 ** =org-columns-modify-value-for-display-function=
119 Function that modifies values for display in column view.
120 For example, it can be used to cut out a certain part from a time stamp.
121 The function must take 2 arguments:
123 column-title The title of the column (*not* the property name)
124 value The value that should be modified.
126 The function should return the value that should be displayed,
127 or nil if the normal value should be used.
129 ** =org-finish-function=
132 Function to be called when `C-c C-c' is used.
133 This is for getting out of special buffers like remember.
138 Mode hook for Org-mode, run after the mode was turned on.
140 ** =org-font-lock-hook=
143 Functions to be called for special font lock stuff.
145 ** =org-store-link-functions=
148 List of functions that are called to create and store a link.
149 Each function will be called in turn until one returns a non-nil
150 value. Each function should check if it is responsible for creating
151 this link (for example by looking at the major mode).
152 If not, it must exit and return nil.
153 If yes, it should return a non-nil value after a calling
154 `org-store-link-props' with a list of properties and values.
155 Special properties are:
157 :type The link prefix. like \"http\". This must be given.
158 :link The link, like \"http://www.astro.uva.nl/~dominik\".
159 This is obligatory as well.
160 :description Optional default description for the second pair
161 of brackets in an Org-mode link. The user can still change
162 this when inserting this link into an Org-mode buffer.
164 In addition to these, any additional properties can be specified
165 and then used in remember templates.
167 ** =org-create-file-search-functions=
170 List of functions to construct the right search string for a file link.
171 These functions are called in turn with point at the location to
172 which the link should point.
174 A function in the hook should first test if it would like to
175 handle this file type, for example by checking the major-mode or
176 the file extension. If it decides not to handle this file, it
177 should just return nil to give other functions a chance. If it
178 does handle the file, it must return the search string to be used
179 when following the link. The search string will be part of the
180 file link, given after a double colon, and `org-open-at-point'
181 will automatically search for it. If special measures must be
182 taken to make the search successful, another function should be
183 added to the companion hook `org-execute-file-search-functions',
186 A function in this hook may also use `setq' to set the variable
187 `description' to provide a suggestion for the descriptive text to
188 be used for this link when it gets inserted into an Org-mode
189 buffer with \\[org-insert-link].
191 ** =org-execute-file-search-functions=
194 List of functions to execute a file search triggered by a link.
196 Functions added to this hook must accept a single argument, the
197 search string that was part of the file link, the part after the
198 double colon. The function must first check if it would like to
199 handle this search, for example by checking the major-mode or the
200 file extension. If it decides not to handle this search, it
201 should just return nil to give other functions a chance. If it
202 does handle the search, it must return a non-nil value to keep
203 other functions from trying.
205 Each function can access the current prefix argument through the
206 variable `current-prefix-argument'. Note that a single prefix is
207 used to force opening a link in Emacs, so it may be good to only
208 use a numeric or double prefix to guide the search function.
210 In case this is needed, a function in this hook can also restore
211 the window configuration before `org-open-at-point' was called using:
213 (set-window-configuration org-window-config-before-follow-link)
215 ** =org-blocker-hook=
218 Hook for functions that are allowed to block a state change.
220 Each function gets as its single argument a property list, see
221 `org-trigger-hook' for more information about this list.
223 If any of the functions in this hook returns nil, the state change
226 ** =org-trigger-hook=
229 Hook for functions that are triggered by a state change.
231 Each function gets as its single argument a property list with at least
232 the following elements:
234 (:type type-of-change :position pos-at-entry-start
235 :from old-state :to new-state)
237 Depending on the type, more properties may be present.
239 This mechanism is currently implemented for:
243 :type todo-state-change
244 :from previous state (keyword as a string), or nil
245 :to new state (keyword as a string), or nil
247 ** =org-after-todo-statistics-hook=
250 Hook that is called after a TODO statistics cookie has been updated.
251 Each function is called with two arguments: the number of not-done entries
252 and the number of done entries.
254 For example, the following function, when added to this hook, will switch
255 an entry to DONE when all children are done, and back to TODO when new
256 entries are set to a TODO status. Note that this hook is only called
257 when there is a statistics cookie in the headline!
259 (defun org-summary-todo (n-done n-not-done)
260 \"Switch entry to DONE when all subentries are done, to TODO otherwise.\"
261 (let (org-log-done org-log-states) ; turn off logging
262 (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\"))))
264 ** =org-finalize-agenda-hook=
265 Defined in: /org-agenda.el/
267 Hook run just before displaying an agenda buffer.
269 ** =org-agenda-mode-hook=
270 Defined in: /org-agenda.el/
272 Hook for org-agenda-mode, run after the mode is turned on.
274 ** =org-agenda-skip-function=
275 Defined in: /org-agenda.el/
277 Function to be called at each match during agenda construction.
278 If this function returns nil, the current match should not be skipped.
279 Otherwise, the function must return a position from where the search
281 This may also be a Lisp form, it will be evaluated.
282 Never set this variable using `setq' or so, because then it will apply
283 to all future agenda commands. Instead, bind it with `let' to scope
284 it dynamically into the agenda-constructing command. A good way to set
285 it is through options in org-agenda-custom-commands.
287 ** =org-agenda-after-show-hook=
288 Defined in: /org-agenda.el/
290 Normal hook run after an item has been shown from the agenda.
291 Point is in the buffer where the item originated.
293 ** =org-clock-heading-function=
294 Defined in: /org-clock.el/
296 When non-nil, should be a function to create `org-clock-heading'.
297 This is the string shown in the mode line when a clock is running.
298 The function is called with point at the beginning of the headline.
300 ** =org-export-preprocess-hook=
301 Defined in: /org-exp.el/
303 Hook for preprocessing an export buffer.
304 Pretty much the first thing when exporting is running this hook.
306 ** =org-export-preprocess-after-include-files-hook=
307 Defined in: /org-exp.el/
309 Hook for preprocessing an export buffer.
310 This is run after the contents of included files have been inserted.
312 ** =org-export-preprocess-after-tree-selection-hook=
313 Defined in: /org-exp.el/
315 Hook for preprocessing an export buffer.
316 This is run after selection of trees to be exported has happened.
317 This selection includes tags-based selection, as well as removal
318 of commented and archived trees.
320 ** =org-export-preprocess-before-backend-specifics-hook=
321 Defined in: /org-exp.el/
323 Hook run before backend-specific functions are called during preprocessing.
325 ** =org-export-preprocess-final-hook=
326 Defined in: /org-exp.el/
328 Hook for preprocessing an export buffer.
329 This is run as the last thing in the preprocessing buffer, just before
330 returning the buffer string to the backend.
332 ** =org-before-save-iCalendar-file-hook=
333 Defined in: /org-exp.el/
335 Hook run before an iCalendar file has been saved.
336 This can be used to modify the result of the export.
338 ** =org-after-save-iCalendar-file-hook=
339 Defined in: /org-exp.el/
341 Hook run after an iCalendar file has been saved.
342 The iCalendar buffer is still current when this hook is run.
343 A good way to use this is to tell a desktop calendar application to re-read
346 ** =org-mouse-context-menu-function=
347 Defined in: /org-mouse.el/
349 Function to create the context menu.
350 The value of this variable is the function invoked by
351 `org-mouse-context-menu' as the context menu.
353 ** =org-publish-before-export-hook=
354 Defined in: /org-publish.el/
356 Hook run before export on the Org file.
357 If the functions in this hook modify the original Org buffer, the
358 modified buffer will be used for export, but the buffer will be
359 restored and saved back to its initial state after export.
361 ** =org-publish-after-export-hook=
362 Defined in: /org-publish.el/
364 Hook run after export on the exported buffer.
365 If functions in this hook modify the buffer, it will be saved.
367 ** =org-remember-before-finalize-hook=
368 Defined in: /org-remember.el/
370 Hook that is run right before a remember process is finalized.
371 The remember buffer is still current when this hook runs.
373 ** =org-remember-mode-hook=
374 Defined in: /org-remember.el/
376 Hook for the minor `org-remember-mode'.
378 * Examples for using hooks
380 Feel free to give example of how do you use these hooks. Ideas for
381 other hooks are also welcome.
383 ** org-follow-link-hook :bzg:
385 If you want to display dormant article when following Gnus articles:
387 #+BEGIN_SRC emacs-lisp
388 (add-hook 'org-follow-link-hook
389 (lambda () (if (eq major-mode 'gnus-summary-mode)
390 (gnus-summary-insert-dormant-articles))))