unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Add font-lock pattern to all modes in Emacs 22.x
@ 2007-02-22 21:13 Scott Frazer
  2007-02-22 21:28 ` Scott Frazer
  2007-02-23 17:31 ` Stefan Monnier
  0 siblings, 2 replies; 3+ messages in thread
From: Scott Frazer @ 2007-02-22 21:13 UTC (permalink / raw)
  To: help-gnu-emacs

I'd like to add a font-lock pattern that will show up in all modes.
It highlights TODO/FIXME strings in comments only ... here's what I
have that works in Emacs 21.x:

(custom-set-faces
 '(my-todo-face ((((class color)) (:weight bold :foreground
"firebrick2" :background "yellow"))) t))

(defun my-font-lock-mode-hook ()
  (font-lock-add-keywords
   nil
   (list (cons (concat "^.*" (replace-regexp-in-string "[ \t]+$" ""
comment-start)
                       ".*?\\(TODO\\|todo\\|Todo\\|FIXME\\|fixme\\|
Fixme\\)")
               (list '(1 'my-todo-face t))))
   'add-to-end))

(add-hook 'font-lock-mode-hook 'my-font-lock-mode-hook)

Yeah, yeah, it won't work in the middle of multi-line comments, but
does for 99% of cases I usually see.  As I said, it works in 21.x, but
in 22.x it seems like comment-start may not be set before font-lock-
mode-hook gets run.  If I run the function after the mode has been
loaded, it's fine.  I'm running Emacs under WinXP if that matters ...

Scott

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

* Re: Add font-lock pattern to all modes in Emacs 22.x
  2007-02-22 21:13 Add font-lock pattern to all modes in Emacs 22.x Scott Frazer
@ 2007-02-22 21:28 ` Scott Frazer
  2007-02-23 17:31 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Scott Frazer @ 2007-02-22 21:28 UTC (permalink / raw)
  To: help-gnu-emacs

On Feb 22, 4:13 pm, "Scott Frazer" <frazer.sc...@gmail.com> wrote:
> I'd like to add a font-lock pattern that will show up in all modes.
> It highlights TODO/FIXME strings in comments only ... here's what I
> have that works in Emacs 21.x:

Fixed it myself.  There is all sorts of crazy fontifying going on with
22.x (minibuffer, etc.) and that was breaking things.  I just wrapped
the font-lock-add-keywords in a (when comment-start (font-lock-add-
keywords ...

Scott

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

* Re: Add font-lock pattern to all modes in Emacs 22.x
  2007-02-22 21:13 Add font-lock pattern to all modes in Emacs 22.x Scott Frazer
  2007-02-22 21:28 ` Scott Frazer
@ 2007-02-23 17:31 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2007-02-23 17:31 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun my-font-lock-mode-hook ()
>   (font-lock-add-keywords
>    nil
>    (list (cons (concat "^.*" (replace-regexp-in-string "[ \t]+$" ""
> comment-start)
>                        ".*?\\(TODO\\|todo\\|Todo\\|FIXME\\|fixme\\|
> Fixme\\)")
>                (list '(1 'my-todo-face t))))
>    'add-to-end))

Try:

(defun my-font-lock-mode-hook ()
  (font-lock-add-keywords
   nil
   '(("\\<\\(TODO\\|[tT]odo\\|FIXME\\|[fF]ixme\\)\\>"
      (1 (if (eq (get-text-property (point) 'face) 'font-lock-comment-face)
             'my-todo-face))))
   'append))

It will also work in multiline comments ;-)


        Stefan


PS: Guaranteed 100% pure untested code only, of course.

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

end of thread, other threads:[~2007-02-23 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-22 21:13 Add font-lock pattern to all modes in Emacs 22.x Scott Frazer
2007-02-22 21:28 ` Scott Frazer
2007-02-23 17:31 ` Stefan Monnier

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).