unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* set font for TODO
@ 2013-06-03  6:54 Luca Ferrari
  2013-06-03 12:43 ` Tim Visher
  0 siblings, 1 reply; 4+ messages in thread
From: Luca Ferrari @ 2013-06-03  6:54 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,
this could be trivial but I cannot find a solution: I'd like to
emphasize some warning/todo words with a special font, so in the
beginning I did:

(custom-set-faces
 '(font-lock-warning-face ((t (:foreground "Yellow" :weight bold  )))) )

(defun fluca1978/fontify-fixme ()
  (font-lock-add-keywords
   nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\|XXX\\)[ \t\s\n:]*"
          1 font-lock-warning-face t))))


but of course this has the side effect to fontify also every other
string that emacs applies warning-face to. So how can I isolate my
keyword list from the emacs one?

Thanks,
Luca



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

* Re: set font for TODO
  2013-06-03  6:54 set font for TODO Luca Ferrari
@ 2013-06-03 12:43 ` Tim Visher
  2013-06-03 13:11   ` Luca Ferrari
       [not found]   ` <mailman.925.1370265110.22516.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Tim Visher @ 2013-06-03 12:43 UTC (permalink / raw)
  To: Luca Ferrari; +Cc: help-gnu-emacs

On Mon, Jun 3, 2013 at 2:54 AM, Luca Ferrari <fluca1978@infinito.it> wrote:
> this could be trivial but I cannot find a solution: I'd like to
> emphasize some warning/todo words with a special font, so in the
> beginning I did:
>
> (custom-set-faces
>  '(font-lock-warning-face ((t (:foreground "Yellow" :weight bold  )))) )
>
> (defun fluca1978/fontify-fixme ()
>   (font-lock-add-keywords
>    nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\|XXX\\)[ \t\s\n:]*"
>           1 font-lock-warning-face t))))
>
>
> but of course this has the side effect to fontify also every other
> string that emacs applies warning-face to. So how can I isolate my
> keyword list from the emacs one?

You'll probably need to define your own custom face, maybe having it
inherit from font-lock-warning-face, and then have font-lock apply
your new face rather than the old face to your keywords.

--

In Christ,

Timmy V.

http://blog.twonegatives.com/
http://five.sentenc.es/ -- Spend less time on mail



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

* Re: set font for TODO
  2013-06-03 12:43 ` Tim Visher
@ 2013-06-03 13:11   ` Luca Ferrari
       [not found]   ` <mailman.925.1370265110.22516.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Luca Ferrari @ 2013-06-03 13:11 UTC (permalink / raw)
  To: Tim Visher; +Cc: help-gnu-emacs

On Mon, Jun 3, 2013 at 2:43 PM, Tim Visher <tim.visher@gmail.com> wrote:

> You'll probably need to define your own custom face, maybe having it
> inherit from font-lock-warning-face, and then have font-lock apply
> your new face rather than the old face to your keywords.
>


I need a little help here, I'm not getting how to do it:

(defface fluca1978-programming-fixme-face
  '((t (:inherit font-lock-warning-face)))
  "Face used to emphasize fixme words" )

(defun fluca1978/fontify-fixme ()
  (font-lock-add-keywords
   nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\|XXX\\)[ \t\s\n:]*"
          1 fluca1978-programming-fixme-face t))))

The result is that nothing is emphasized. Moreover if I write, for
instance, FIXME (without the colon) I get the following words
un-fontified, as if the regular expression was wrong. What am I
missing?

Thanks,
Luca



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

* Re: set font for TODO
       [not found]   ` <mailman.925.1370265110.22516.help-gnu-emacs@gnu.org>
@ 2013-06-13 14:44     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-06-13 14:44 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun fluca1978/fontify-fixme ()
>   (font-lock-add-keywords
>    nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\|XXX\\)[ \t\s\n:]*"
>           1 fluca1978-programming-fixme-face t))))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This part of a font-lock-keyword is supposed to be an expression that,
when evaluated, returns the face to use.  So it will signal an error
"fluca1978-programming-fixme-face is void" because there is no
fluca1978-programming-fixme-face variable.
IOW you need to add a quote in front of it.

> The result is that nothing is emphasized. Moreover if I write, for
> instance, FIXME (without the colon) I get the following words
> un-fontified, as if the regular expression was wrong. What am I
> missing?

When this happens, check your *Messages* buffer.  It will probably
contain the error message.

The best way to debug those things is:

   (setq font-lock-support-mode nil)
   (setq debug-on-error t)

and then try again (turning font-lock-mode off and then back on after
applying the setting).  This will make font-lock happen "synchronously"
rather than via jit-lock, so it will signal errors which debug-on-error
can catch.


        Stefan


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

end of thread, other threads:[~2013-06-13 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-03  6:54 set font for TODO Luca Ferrari
2013-06-03 12:43 ` Tim Visher
2013-06-03 13:11   ` Luca Ferrari
     [not found]   ` <mailman.925.1370265110.22516.help-gnu-emacs@gnu.org>
2013-06-13 14:44     ` 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).