Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

highlighting let+

38 views
Skip to first unread message

Tamas Papp

unread,
Jan 22, 2012, 8:45:07 AM1/22/12
to
Hi,

How can I highlight the symbol `let+' in Emacs (SLIME etc, standard setup)?

I tried

(font-lock-add-keywords nil
'(("let+" . font-lock-keyword-face)))

but the `+' isn't highlighted, only the `let'.

Best,

Tamas

Tim Bradshaw

unread,
Jan 22, 2012, 9:02:33 AM1/22/12
to
This is really an Emacs question: I don't know if there are still
active Emacs newsgroups. But I'm guessing that the keyword is a regexp
so "+" is special, and what you've probably defined is a pattern which
will highlight "lett", "lettt" & so on. Probably you want "let\\+" or
"let[+]" or something like that.

Tamas Papp

unread,
Jan 22, 2012, 9:22:37 AM1/22/12
to
On Sun, 22 Jan 2012 14:02:33 +0000, Tim Bradshaw wrote:

> On 2012-01-22 13:45:07 +0000, Tamas Papp said:
>
>> Hi,
>>
>> How can I highlight the symbol `let+' in Emacs (SLIME etc, standard
>> setup)?
>>
>> I tried
>>
>> (font-lock-add-keywords nil
>> '(("let+" . font-lock-keyword-face)))
>>
>> but the `+' isn't highlighted, only the `let'.
>>
>> Best,
>>
>> Tamas
>
> This is really an Emacs question: I don't know if there are still active

You are right, but Emacs is one of the most important IDEs for CL, so
I thought I would try here, because I expect that very few languages
have keywords that have characters like + in them so lispers are most
likely to have run into this problem.

> Emacs newsgroups. But I'm guessing that the keyword is a regexp so "+"
> is special, and what you've probably defined is a pattern which will
> highlight "lett", "lettt" & so on. Probably you want "let\\+" or
> "let[+]" or something like that.

Strangely, it is the opposite: in Emacs regexps, + does what you
describe when you escape it.

I have also tried

(font-lock-add-keywords nil
'(("\\<\\(let+\\)" 1 font-lock-keyword-face t)))

which at least doesn't interfere with flet & similar, but the + is
still not highlighted.

Best,

Tamas

Joerg Mertens

unread,
Jan 22, 2012, 9:54:11 AM1/22/12
to
"let\\+" works here. But nil means, that it's only set for
the current buffer. If you want to set the keyword for example for
lisp-mode, you have to replace nil with 'lisp-mode.

Regards

Joerg

Tim Bradshaw

unread,
Jan 22, 2012, 10:34:02 AM1/22/12
to
On 2012-01-22 14:22:37 +0000, Tamas Papp said:

> Strangely, it is the opposite: in Emacs regexps, + does what you
> describe when you escape it.

No.

ELISP> (string-match "let+" "lettt")
0
ELISP> (string-match "let\\+" "lettt")
nil
ELISP> (string-match "let\\+" "let")
nil
ELISP> (string-match "let\\+" "let+")
0

You may be getting confused by the number of backslashes: "let+" is the
same as "let\+" because of string syntax in elisp.

Tamas Papp

unread,
Jan 22, 2012, 11:02:22 AM1/22/12
to
Thanks. I don't know where I got that idea... Now

(font-lock-add-keywords nil
'(("\\<\\(let\\+\\)" 1 font-lock-keyword-face t)))

does what I wanted.

I knew I had to come to c.l.l with this question :-) *ducks*

Best,

Tamas

Tim Bradshaw

unread,
Jan 22, 2012, 11:28:08 AM1/22/12
to
On 2012-01-22 16:02:22 +0000, Tamas Papp said:
> Thanks. I don't know where I got that idea... Now
>
> (font-lock-add-keywords nil
> '(("\\<\\(let\\+\\)" 1 font-lock-keyword-face t)))
>
> does what I wanted.
>

It kind of might be the case that you want something like "let." so you
can match let, let*, and so on. I guess that will match some things
you don't want, not sure.

Raffaele Ricciardi

unread,
Jan 22, 2012, 6:33:32 PM1/22/12
to
On 01/22/2012 04:02 PM, Tamas Papp wrote:
> (font-lock-add-keywords nil
> '(("\\<\\(let\\+\\)" 1 font-lock-keyword-face t)))

That would highlight let+ at the beginning of a symbol too, as in
let+foo. To avoid it, add a \> at the end of the pattern, like this:
0 new messages