From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo de Moraes Serpa Subject: Re: [hack/extension] org-mode/emacs regexp Date: Mon, 16 Nov 2009 13:45:27 -0600 Message-ID: <1e5bcefd0911161145ubdb4cc6w3ea40bcfcdeeb225@mail.gmail.com> References: <1e5bcefd0911161010w448c73d6yb2082b49348c4ea6@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0150914240==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NA7W1-0008S9-TR for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 14:45:34 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NA7Vw-0008Px-Ud for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 14:45:33 -0500 Received: from [199.232.76.173] (port=53469 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NA7Vw-0008Pr-MK for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 14:45:28 -0500 Received: from mail-pz0-f181.google.com ([209.85.222.181]:44387) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NA7Vw-0003Eu-3c for emacs-orgmode@gnu.org; Mon, 16 Nov 2009 14:45:28 -0500 Received: by pzk11 with SMTP id 11so3630336pzk.14 for ; Mon, 16 Nov 2009 11:45:27 -0800 (PST) In-Reply-To: <1e5bcefd0911161010w448c73d6yb2082b49348c4ea6@mail.gmail.com> 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 --===============0150914240== Content-Type: multipart/alternative; boundary=0016e64d956c530c7b0478824064 --0016e64d956c530c7b0478824064 Content-Type: text/plain; charset=ISO-8859-1 Ok, I'm sorry, I actually had to research a little bit more before posting :) Well, what I need to know now is how to make the overlay work. The code to match is working, but I'm receiving the following error: Error during redisplay: (wrong-number-of-arguments match-beginning 0) Here's the full code: http://pastie.org/701448 (Thanks to Tim O'Calaghan for the original contribution) Marcelo. Also, how can I debug it? I tried debug-on-entry but it is not working :S On Mon, Nov 16, 2009 at 12:10 PM, Marcelo de Moraes Serpa < celoserpa@gmail.com> wrote: > 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. > > --0016e64d956c530c7b0478824064 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Ok, I'm sorry, I actually had to research a little bit more before post= ing :)

Well, what I need to know now is how to make the overlay work= . The code to match is working, but I'm receiving the following error:<= br>
Error during redisplay: (wrong-number-of-arguments match-beginning 0)
Here's the full code: http:/= /pastie.org/701448

(Thanks to Tim O'Calaghan for the origin= al contribution)

Marcelo.

Also, how can I debug it? I tried debug-on-entry but it= is not working :S


On Mon, Nov 16, 20= 09 at 12:10 PM, Marcelo de Moraes Serpa <celoserpa@gmail.com> wrote:
Hello,

I s= tarted writing an extension to org that actually applies a custom face to a= n 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 t= o 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.


--0016e64d956c530c7b0478824064-- --===============0150914240== 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 --===============0150914240==--