unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* prevent part of user var highlighted as keyword in new lang mode
@ 2008-11-19  2:37 Xah
  2008-11-19 13:31 ` Scott Frazer
  0 siblings, 1 reply; 6+ messages in thread
From: Xah @ 2008-11-19  2:37 UTC (permalink / raw)
  To: help-gnu-emacs

in writing a new language mode, how do i prevent part of variable that
gets highlighted as keyword? e.g. the “for” in “inform”.

i'm using
(setq font-lock-defaults '((xlsl-font-lock-keywords) nil nil))

Thanks.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: prevent part of user var highlighted as keyword in new lang mode
  2008-11-19  2:37 prevent part of user var highlighted as keyword in new lang mode Xah
@ 2008-11-19 13:31 ` Scott Frazer
  2008-11-19 13:53   ` Xah
  0 siblings, 1 reply; 6+ messages in thread
From: Scott Frazer @ 2008-11-19 13:31 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
> in writing a new language mode, how do i prevent part of variable that
> gets highlighted as keyword? e.g. the “for” in “inform”.
> 
> i'm using
> (setq font-lock-defaults '((xlsl-font-lock-keywords) nil nil))
> 

You need to wrap your regexp with markers that indicate the beginning/end
of the empty string or symbol, e.g. these are the symbol ones:

(concat "\\_<\\(" (regexp-opt '("form" "foo" "bar")) "\\)\\_>")

See the "Backslash constructs in regular expressions" section in the
Elisp manual.

Scott


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

* Re: prevent part of user var highlighted as keyword in new lang mode
  2008-11-19 13:31 ` Scott Frazer
@ 2008-11-19 13:53   ` Xah
  2008-11-19 17:56     ` Drew Adams
  2008-11-19 18:11     ` Scott Frazer
  0 siblings, 2 replies; 6+ messages in thread
From: Xah @ 2008-11-19 13:53 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 19, 5:31 am, Scott Frazer <frazer.sc...@gmail.com> wrote:
> Xah wrote:
> > in writing a new language mode, how do i prevent part of variable that
> > gets highlighted as keyword? e.g. the “for” in “inform”.
>
> > i'm using
> > (setq font-lock-defaults '((xlsl-font-lock-keywords) nil nil))
>
> You need to wrap your regexp with markers that indicate the beginning/end
> of the empty string or symbol, e.g. these are the symbol ones:
>
> (concat "\\_<\\(" (regexp-opt '("form" "foo" "bar")) "\\)\\_>")
>
> See the "Backslash constructs in regular expressions" section in the
> Elisp manual.
>
> Scott

i'm not sure what's wrong.

Here's my code:

(defvar xlsl-keywords-regexp (regexp-opt xlsl-keywords 'word))
(defvar xlsl-type-regexp (regexp-opt xlsl-types 'words))
(defvar xlsl-constant-regexp (regexp-opt xlsl-constants 'words))
(defvar xlsl-event-regexp (regexp-opt xlsl-events 'words))
(defvar xlsl-functions-regexp (regexp-opt xlsl-functions 'words))

(setq xlsl-font-lock-keywords
  `(
    (,xlsl-type-regexp . font-lock-type-face)
    (,xlsl-constant-regexp . font-lock-constant-face)
    (,xlsl-event-regexp . font-lock-builtin-face)
    (,xlsl-functions-regexp . font-lock-function-name-face)
    (,xlsl-keywords-regexp . font-lock-keyword-face)
))

but still, when i type for example “information”, the “for” is
highlighted.

Any other idea?

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: prevent part of user var highlighted as keyword in new lang mode
  2008-11-19 13:53   ` Xah
@ 2008-11-19 17:56     ` Drew Adams
  2008-11-19 18:11     ` Scott Frazer
  1 sibling, 0 replies; 6+ messages in thread
From: Drew Adams @ 2008-11-19 17:56 UTC (permalink / raw)
  To: 'Xah', help-gnu-emacs

> (defvar xlsl-keywords-regexp (regexp-opt xlsl-keywords 'word))
> (setq xlsl-font-lock-keywords
>   `(... (,xlsl-keywords-regexp . font-lock-keyword-face)))
> 
> when i type ... "information", the "for" is highlighted.

Sounds like there might be interference among the patterns. Try just one of the
regexps at a time, commenting out the others. But you didn't show any of the
regexps you use, so it's hard to guess. ;-)

It might also be that you need to specify the group of the regexp that you want
to highlight. Here's an example that highlights a group (first regexp line) and
entire matches (other two regexp lines). The `1' says to use whatever the first
group matches.

(defvar shell-font-lock-keywords
  '(("[ \t]\\([+-][^ \t\n]+\\)" 1 font-lock-comment-face)
    ("^[^ \t\n]+:.*" . font-lock-string-face)
    ("^\\[[1-9][0-9]*\\]" . font-lock-string-face))
  "Additional expressions to highlight in Shell mode.")





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

* Re: prevent part of user var highlighted as keyword in new lang mode
  2008-11-19 13:53   ` Xah
  2008-11-19 17:56     ` Drew Adams
@ 2008-11-19 18:11     ` Scott Frazer
  2008-11-20  2:41       ` Xah
  1 sibling, 1 reply; 6+ messages in thread
From: Scott Frazer @ 2008-11-19 18:11 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
> On Nov 19, 5:31 am, Scott Frazer <frazer.sc...@gmail.com> wrote:
>> Xah wrote:
> 
> i'm not sure what's wrong.
> 
> Here's my code:
> 
> (defvar xlsl-keywords-regexp (regexp-opt xlsl-keywords 'word))

You're missing an 's' there at the end ... it should be 'words


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

* Re: prevent part of user var highlighted as keyword in new lang mode
  2008-11-19 18:11     ` Scott Frazer
@ 2008-11-20  2:41       ` Xah
  0 siblings, 0 replies; 6+ messages in thread
From: Xah @ 2008-11-20  2:41 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 19, 10:11 am, Scott Frazer <frazer.sc...@gmail.com> wrote:
> Xah wrote:
> > On Nov 19, 5:31 am, Scott Frazer <frazer.sc...@gmail.com> wrote:
> >> Xah wrote:
>
> > i'm not sure what's wrong.
>
> > Here's my code:
>
> > (defvar xlsl-keywords-regexp (regexp-opt xlsl-keywords 'word))
>
> You're missing an 's' there at the end ... it should be 'words

Hot damn.

Thanks Drew too.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-11-20  2:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19  2:37 prevent part of user var highlighted as keyword in new lang mode Xah
2008-11-19 13:31 ` Scott Frazer
2008-11-19 13:53   ` Xah
2008-11-19 17:56     ` Drew Adams
2008-11-19 18:11     ` Scott Frazer
2008-11-20  2:41       ` Xah

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