- publishing free software manuals
The Org Mode 7 Reference Manual
by Carsten Dominik and others
Paperback (6"x9"), 282 pages
ISBN 9781906966089
RRP £9.95 ($14.95)

Sales of this book support the Org project! Get a printed copy>>>

16.14 Context-sensitive commands

Org has several commands that act differently depending on context. The most important example it the C-c C-c (see section 16.7 The very busy C-c C-c key). Also the M-cursor and M-S-cursor keys have this property.

Add-ons can tap into this functionality by providing a function that detects special context for that add-on and executes functionality appropriate for the context. Here is an example from Dan Davison's ‘org-R.el’ which allows you to evaluate commands based on the ‘R’ programming language .(144) For this package, special contexts are lines that start with #+R: or #+RR:.

(defun org-R-apply-maybe ()
  "Detect if this is context for org-R and execute R commands."
  (if (save-excursion
        (beginning-of-line 1)
        (looking-at "#\\+RR?:"))
      (progn (call-interactively 'org-R-apply)
             t) ;; to signal that we took action
    nil)) ;; to signal that we did not

(add-hook 'org-ctrl-c-ctrl-c-hook 'org-R-apply-maybe)

The function first checks if the cursor is in such a line. If that is the case, org-R-apply is called and the function returns t to signal that action was taken, and C-c C-c will stop looking for other contexts. If the function finds it should do nothing locally, it returns nil so that other, similar functions can have a try.

ISBN 9781906966089The Org Mode 7 Reference ManualSee the print edition