From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo de Moraes Serpa Subject: [hack/extension] org-mode/emacs regexp Date: Mon, 16 Nov 2009 12:10:03 -0600 Message-ID: <1e5bcefd0911161010w448c73d6yb2082b49348c4ea6@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1352187081==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NA61k-0005ub-5l for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 13:10:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NA61f-0005my-GR for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 13:10:11 -0500 Received: from [199.232.76.173] (port=42254 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NA61e-0005mO-89 for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 13:10:06 -0500 Received: from mail-px0-f192.google.com ([209.85.216.192]:43856) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NA61d-0005Ly-NE for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 13:10:06 -0500 Received: by pxi30 with SMTP id 30so69245pxi.14 for ; Mon, 16 Nov 2009 10:10:03 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode --===============1352187081== Content-Type: multipart/alternative; boundary=0016e64c3d982c55ca047880eb1b --0016e64c3d982c55ca047880eb1b Content-Type: text/plain; charset=ISO-8859-1 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. --0016e64c3d982c55ca047880eb1b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 fr= om the org-action-verb.el by Tim O'Calaghan, basically using the same s= tructure since my elisp knowledge is very basic. I have managed to get it t= o work to a basic level, but it is applying the face to the whole tree inst= ead of applying to only one item.

(defface org-gtd-default-category-face
=A0 '((((class color) (ba= ckground light)) (:foreground "purple" :bold t :underline t))
= =A0=A0=A0 (((class color) (background dark)) (:foreground "purple"= ; :bold t :underline t))
=A0=A0=A0 (t (:bold t :underline t)))
=A0 "Used by org-color-by-tag= for items tagged with :CATEGORY:")

(defface org-gtd-default-pr= oject-face
=A0 '((((class color) (background light)) (:foreground &q= uot;purple" :bold t :underline t))
=A0=A0=A0 (((class color) (background dark)) (:foreground "purple"= ; :bold t :underline t))
=A0=A0=A0 (t (:bold t :underline t)))
=A0 &q= uot;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)
=A0 "Add the faces t= o corresponding items depending on the TAG."
=A0 (let (rtn a)
= =A0=A0=A0 ;; check variable is set, and buffer left to search
=A0=A0=A0 = (when (and (not rtn) org-gtd-tags)
=A0=A0=A0=A0=A0 ;; for each todo/action verb set
=A0=A0=A0=A0=A0 (dolist= (tag org-gtd-tags)
=A0=A0=A0=A0=A0=A0=A0 ;; build regexps
=A0=A0=A0= =A0=A0=A0=A0 (let ((tag-keywords-regexp
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (regexp-opt (cdr tag) 'word)))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0 ;; = while we can find a todo keyword
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (while (re-= search-forward ":PROJECT:" limit t)
=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 ;; check for action verb

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ;; apply new overlay
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (let ((overlay (make-ov= erlay (match-beginning 1) (match-end 1) nil t nil)))
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (overlay-put overlay 'face '= ;org-gtd-default-project-face)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 ;;(overlay-put overlay 'mouse-face mouse-face)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (overlay-put over= lay 'org-action-overlay t)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 (overlay-put overlay 'evaporate t)
=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (overlay-put overlay 'hel= p-echo "mouse-2: correct word at point")
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 overlay)
=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ;; reset search point?=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (backward-char 1)))))
=A0=A0=A0 rtn)= )

(org-font-lock-add-tag-faces 10)

(defun org-mode-color-by-t= ag-hook ()
=A0 "Initalise org-color-by-tag."
=A0 (interactive)
=A0 (f= ont-lock-add-keywords nil '((org-font-lock-add-tag-faces)))
=A0 )
;; Turn on action verb font locking.
(add-hook 'org-mode-hook &= #39;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 tryin= g 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:

"^\\*+[ =A0=A0=A0 ]+"

Was used here:
=A0=A0=A0=A0= =A0=A0=A0 (let ((todo-keywords-regexp
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 (concat "^\\*+[ =A0=A0=A0 ]+"
=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (regexp-opt (car todo) 'w= ords)))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (todo-action-verbs-regex= p
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (concat "[ =A0=A0=A0 ]+&quo= t; (regexp-opt (cdr todo) 'words))))


And:=A0 "[ =A0=A0= =A0 ]+\\(\\<\\w\\w+\\>\\)"

Used in: (looking-at "[ = =A0=A0=A0 ]+\\(\\<\\w\\w+\\>\\)")

What I want to do is: Search for items tagged as PROJECT or CATEGORY an= d apply the corresponding face to them.

If someone could explain me = the role of=A0 "[=A0=A0=A0 ]", and w, I would be grateful :)
<= br>Thanks,

Marcelo.

--0016e64c3d982c55ca047880eb1b-- --===============1352187081== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --===============1352187081==--