emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [hack/extension] org-mode/emacs regexp
@ 2009-11-16 18:10 Marcelo de Moraes Serpa
  2009-11-16 19:45 ` Marcelo de Moraes Serpa
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo de Moraes Serpa @ 2009-11-16 18:10 UTC (permalink / raw)
  To: Org Mode


[-- Attachment #1.1: Type: text/plain, Size: 3386 bytes --]

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.

[-- Attachment #1.2: Type: text/html, Size: 4041 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-17 11:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-16 18:10 [hack/extension] org-mode/emacs regexp Marcelo de Moraes Serpa
2009-11-16 19:45 ` Marcelo de Moraes Serpa
2009-11-17 11:49   ` Tim O'Callaghan

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).