Hello,
I started writing an extension to org that actually applies a custom face to an item tagges as CATEGORY or PROJECT. The thing is I'm really having a hard time understanding the regexp. The code is adapted from the org-action-verb.el by Tim O'Calaghan, basically using the same structure since my elisp knowledge is very basic. I have managed to get it to work to a basic level, but it is applying the face to the whole tree instead of applying to only one item.
(defface org-gtd-default-category-face
'((((class color) (background light)) (:foreground "purple" :bold t :underline t))
(((class color) (background dark)) (:foreground "purple" :bold t :underline t))
(t (:bold t :underline t)))
"Used by org-color-by-tag for items tagged with :CATEGORY:")
(defface org-gtd-default-project-face
'((((class color) (background light)) (:foreground "purple" :bold t :underline t))
(((class color) (background dark)) (:foreground "purple" :bold t :underline t))
(t (:bold t :underline t)))
"Used by org-color-by-tag for items tagged with :PROJECT:")
(defvar org-gtd-tags '("PROJECT" "CATEGORY"))
(defun org-font-lock-add-tag-faces (limit)
"Add the faces to corresponding items depending on the TAG."
(let (rtn a)
;; check variable is set, and buffer left to search
(when (and (not rtn) org-gtd-tags)
;; for each todo/action verb set
(dolist (tag org-gtd-tags)
;; build regexps
(let ((tag-keywords-regexp
(regexp-opt (cdr tag) 'word)))
;; while we can find a todo keyword
(while (re-search-forward ":PROJECT:" limit t)
;; check for action verb
;; apply new overlay
(let ((overlay (make-overlay (match-beginning 1) (match-end 1) nil t nil)))
(overlay-put overlay 'face 'org-gtd-default-project-face)
;;(overlay-put overlay 'mouse-face mouse-face)
(overlay-put overlay 'org-action-overlay t)
(overlay-put overlay 'evaporate t)
(overlay-put overlay 'help-echo "mouse-2: correct word at point")
overlay)
;; reset search point?
(backward-char 1)))))
rtn))
(org-font-lock-add-tag-faces 10)
(defun org-mode-color-by-tag-hook ()
"Initalise org-color-by-tag."
(interactive)
(font-lock-add-keywords nil '((org-font-lock-add-tag-faces)))
)
;; Turn on action verb font locking.
(add-hook 'org-mode-hook 'org-mode-color-by-tag-hook)
As you can see, I'm in the debug phase, and I'm not even using the list of strings (PROJECT CATEGORY) I've created. I'm just trying to search for occurrences of the PROJECT tag and trying to apply the face. I've removed the regexp string that Tim used, which were:
"^\\*+[ ]+"
Was used here:
(let ((todo-keywords-regexp
(concat "^\\*+[ ]+"
(regexp-opt (car todo) 'words)))
(todo-action-verbs-regexp
(concat "[ ]+" (regexp-opt (cdr todo) 'words))))
And: "[ ]+\\(\\<\\w\\w+\\>\\)"
Used in: (looking-at "[ ]+\\(\\<\\w\\w+\\>\\)")
What I want to do is: Search for items tagged as PROJECT or CATEGORY and apply the corresponding face to them.
If someone could explain me the role of "[ ]", and w, I would be grateful :)
Thanks,
Marcelo.