unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Syntax highlighting keywords starting with #
@ 2005-11-03 12:11 frodetj
  2005-11-03 16:05 ` frodetj
  2005-11-03 16:12 ` Stefan Monnier
  0 siblings, 2 replies; 7+ messages in thread
From: frodetj @ 2005-11-03 12:11 UTC (permalink / raw)


How do I do that? I have a script language where all the keywords start
with #. I would like to highlight these. The regexp #[A-Z] does not
work. The regexp [R#][A-Z]* will highlight "words" like RA, RAB, RZZ
etc, but not #A or anything else starting with #.

This does not work:

(defconst psc-font-lock-keywords
  (list
   '("\\<[#R][A-Z]*\\>" . font-lock-builtin-face)
   '("\\('\\w*'\\)" . font-lock-variable-name-face))

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

* Re: Syntax highlighting keywords starting with #
  2005-11-03 12:11 Syntax highlighting keywords starting with # frodetj
@ 2005-11-03 16:05 ` frodetj
  2005-11-03 16:12 ` Stefan Monnier
  1 sibling, 0 replies; 7+ messages in thread
From: frodetj @ 2005-11-03 16:05 UTC (permalink / raw)



You stupid man!

Remove the \\< and \\>, and it will work perfectly for you.

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

* Re: Syntax highlighting keywords starting with #
  2005-11-03 12:11 Syntax highlighting keywords starting with # frodetj
  2005-11-03 16:05 ` frodetj
@ 2005-11-03 16:12 ` Stefan Monnier
  2005-11-03 19:55   ` frodetj
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2005-11-03 16:12 UTC (permalink / raw)


> How do I do that? I have a script language where all the keywords start
> with #. I would like to highlight these. The regexp #[A-Z] does not
> work. The regexp [R#][A-Z]* will highlight "words" like RA, RAB, RZZ
> etc, but not #A or anything else starting with #.

> This does not work:

> (defconst psc-font-lock-keywords
>   (list
>    '("\\<[#R][A-Z]*\\>" . font-lock-builtin-face)
>    '("\\('\\w*'\\)" . font-lock-variable-name-face))

No wonder: this only defines a variable.  Where is this variable used?


        Stefan

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

* Re: Syntax highlighting keywords starting with #
  2005-11-03 16:12 ` Stefan Monnier
@ 2005-11-03 19:55   ` frodetj
  2005-11-04  3:43     ` Ian Zimmerman
       [not found]     ` <mailman.13898.1131075812.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: frodetj @ 2005-11-03 19:55 UTC (permalink / raw)



I believe the following code does the trick?

(defun psc-mode ()
  (set (make-local-variable 'font-lock-defaults)
'(psc-font-lock-keywords)))

It was actually working to remove the \\<. But it would be rather neat
have it, so that
#PROCESS
is highlighted, and
CRAP#PROCESS
is not.

I'm not able to make this work for the #, but for other characters it's
working fine.

Any advice?

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

* Re: Syntax highlighting keywords starting with #
  2005-11-03 19:55   ` frodetj
@ 2005-11-04  3:43     ` Ian Zimmerman
       [not found]     ` <mailman.13898.1131075812.20277.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Zimmerman @ 2005-11-04  3:43 UTC (permalink / raw)



frodetj> I'm not able to make this work for the #, but for other
frodetj> characters it's working fine.

Change the syntax table in your mode to give # word or symbol syntax,
maybe.

-- 
A true pessimist won't be discouraged by a little success.
(apologies to Peter Dyballa for my translation from German)

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

* Re: Syntax highlighting keywords starting with #
       [not found]     ` <mailman.13898.1131075812.20277.help-gnu-emacs@gnu.org>
@ 2005-11-04 11:27       ` Frode
  2005-11-22 19:53         ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Frode @ 2005-11-04 11:27 UTC (permalink / raw)


Thanks a lot, Ian. The following code saved my day:

(defvar psc-mode-syntax-table
  (let ((psc-mode-syntax-table (make-syntax-table)))
  (modify-syntax-entry ?# "w" psc-mode-syntax-table)
  psc-mode-syntax-table)
  "Syntax table for PSC mode")

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

* Re: Syntax highlighting keywords starting with #
  2005-11-04 11:27       ` Frode
@ 2005-11-22 19:53         ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2005-11-22 19:53 UTC (permalink / raw)


> (defvar psc-mode-syntax-table
>   (let ((psc-mode-syntax-table (make-syntax-table)))
>   (modify-syntax-entry ?# "w" psc-mode-syntax-table)
>   psc-mode-syntax-table)
>   "Syntax table for PSC mode")

Better not do that.
Similarly, better not set font-lock-keywords (where did this idea come
from?  I'd like to know so I can fix the source of the problem).   Instead,
set font-lock-defaults:

    (set (make-local-variable 'font-lock-defaults)
         '(psc-font-lock-keywords nil nil ((?# . "w"))))

Note how it tells font-lock to (temporarily) treat # as a word component.
As for your main syntax-table, it should probably use something like "'"
rather than "w" for #.


        Stefan

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

end of thread, other threads:[~2005-11-22 19:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-03 12:11 Syntax highlighting keywords starting with # frodetj
2005-11-03 16:05 ` frodetj
2005-11-03 16:12 ` Stefan Monnier
2005-11-03 19:55   ` frodetj
2005-11-04  3:43     ` Ian Zimmerman
     [not found]     ` <mailman.13898.1131075812.20277.help-gnu-emacs@gnu.org>
2005-11-04 11:27       ` Frode
2005-11-22 19:53         ` 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).