From ed1a701cf51c30552e802f21e3cc9dac2b17de53 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Fri, 20 Jan 2012 16:28:04 +0100 Subject: [PATCH] org.el: `org-context' now returns :clocktable and :src-block. * org.el (org-in-src-block-p): New function. (org-context): Return new contexts :clocktable and :src-block. --- lisp/org.el | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index 87b2c3ed8..b204b0b47 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19504,6 +19504,14 @@ and end of string." "Is S an ID created by UUIDGEN?" (string-match "\\`[0-9a-f]\\{8\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{4\\}-[0-9a-f]\\{12\\}\\'" (downcase s))) +(defun org-in-src-block-p nil + "Whether point is in a code source block." + (let (ov) + (when (setq ov (overlays-at (point))) + (memq 'org-block-background + (overlay-properties + (car ov)))))) + (defun org-context () "Return a list of contexts of the current cursor position. If several contexts apply, all are returned. @@ -19522,8 +19530,10 @@ contexts are: :table in an org-mode table :table-special on a special filed in a table :table-table in a table.el table +:clocktable in a clocktable +:src-block in a source block :link on a hyperlink -:keyword on a keyword: SCHEDULED, DEADLINE, CLOSE,COMMENT, QUOTE. +:keyword on a keyword: SCHEDULED, DEADLINE, CLOSE, COMMENT, QUOTE. :target on a <> :radio-target on a <<>> :latex-fragment on a LaTeX fragment @@ -19534,6 +19544,7 @@ faces as a help to recognize the following contexts: :table-special, :link, and :keyword." (let* ((f (get-text-property (point) 'face)) (faces (if (listp f) f (list f))) + (case-fold-search t) (p (point)) clist o) ;; First the large context (cond @@ -19568,6 +19579,23 @@ and :keyword." (push (list :table-table) clist))) (goto-char p) + ;; New the "medium" contexts: clocktables, source blocks + (cond ((org-in-clocktable-p) + (push (list :clocktable + (and (or (looking-at "#\\+BEGIN: clocktable") + (search-backward "#+BEGIN: clocktable" nil t)) + (match-beginning 0)) + (and (re-search-forward "#\\+END:?" nil t) + (match-end 0))) clist)) + ((org-in-src-block-p) + (push (list :src-block + (and (or (looking-at "#\\+BEGIN_SRC") + (search-backward "#+BEGIN_SRC" nil t)) + (match-beginning 0)) + (and (search-forward "#+END_SRC" nil t) + (match-beginning 0))) clist))) + (goto-char p) + ;; Now the small context (cond ((org-at-timestamp-p)