* help with font locking
@ 2006-01-12 0:20 Mark P
2006-01-12 17:31 ` Kevin Rodgers
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Mark P @ 2006-01-12 0:20 UTC (permalink / raw)
I'm trying to edit my .emacs file so that in c++-mode a frequently used
user-defined type "Coord" is highlighted like any built-in type (int,
bool, etc.) I searched around for a while but found only very limited
information. The best I could produce was the following:
;; customize font-locking
(font-lock-add-keywords
'c++-mode
'(("\\<\\(Coord\\)" 1 font-lock-type-face)
) )
This sort of works. In a statement like:
Coord fcn (Coord x);
"Coord" is highlighted twice, but neither "fcn" nor "x" is. In a normal
statement like:
int fcn (int x)
"int" is highlighted as are "fcn" and "x".
Can anyone suggest a way to make the behavior for Coord match that for
int. Any links to detail documentation on how this works would also be
appreciated. (For example, why all the quotes and slashes in the .emacs
code?)
Thanks,
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: help with font locking
2006-01-12 0:20 help with font locking Mark P
@ 2006-01-12 17:31 ` Kevin Rodgers
2006-01-12 20:06 ` Alan Mackenzie
[not found] ` <mailman.847.1137087711.26925.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2006-01-12 17:31 UTC (permalink / raw)
Mark P wrote:
> I'm trying to edit my .emacs file so that in c++-mode a frequently used
> user-defined type "Coord" is highlighted like any built-in type (int,
> bool, etc.) I searched around for a while but found only very limited
> information. The best I could produce was the following:
>
> ;; customize font-locking
> (font-lock-add-keywords
> 'c++-mode
> '(("\\<\\(Coord\\)" 1 font-lock-type-face)
> ) )
>
> This sort of works. In a statement like:
>
> Coord fcn (Coord x);
>
> "Coord" is highlighted twice, but neither "fcn" nor "x" is. In a normal
> statement like:
>
> int fcn (int x)
>
> "int" is highlighted as are "fcn" and "x".
>
> Can anyone suggest a way to make the behavior for Coord match that for
> int. Any links to detail documentation on how this works would also be
> appreciated. (For example, why all the quotes and slashes in the .emacs
> code?)
Maybe http://simon.nitro.dk/dotfiles/emacs/ctypes.el is what you need:
(autoload 'ctypes-define-type "ctypes"
"Add a new TYPE to current major mode and inform font-lock." t)
(add-hook 'c++-mode-hook
(lambda ()
(ctypes-define-type "Coord")))
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: help with font locking
2006-01-12 0:20 help with font locking Mark P
2006-01-12 17:31 ` Kevin Rodgers
@ 2006-01-12 20:06 ` Alan Mackenzie
2006-01-13 0:27 ` Mark P
[not found] ` <mailman.847.1137087711.26925.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 5+ messages in thread
From: Alan Mackenzie @ 2006-01-12 20:06 UTC (permalink / raw)
In gnu.emacs.help Mark P <usenet@fall2005remove.fastmailcaps.fm> wrote:
> I'm trying to edit my .emacs file so that in c++-mode a frequently used
> user-defined type "Coord" is highlighted like any built-in type (int,
> bool, etc.) I searched around for a while but found only very limited
> information. The best I could produce was the following:
[ .... ]
> Can anyone suggest a way to make the behavior for Coord match that for
> int. Any links to detail documentation on how this works would also be
> appreciated. (For example, why all the quotes and slashes in the .emacs
> code?)
In CC Mode 5.30, the new variable c++-font-lock-extra-types was
introduced to do exactly what you want. Chances are, you've only got CC
Mode 5.28 (do M-x c-version). In that case, download the latest version
(5.31.1) from <http://cc-mode.sourceforge.net/release.php>. The variable
is documented on page "Font Locking Preliminaries" of the manual
distributed with the release.
> Thanks,
> Mark
--
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: help with font locking
[not found] ` <mailman.847.1137087711.26925.help-gnu-emacs@gnu.org>
@ 2006-01-12 20:28 ` Mark P
0 siblings, 0 replies; 5+ messages in thread
From: Mark P @ 2006-01-12 20:28 UTC (permalink / raw)
Kevin Rodgers wrote:
> Mark P wrote:
>
>> I'm trying to edit my .emacs file so that in c++-mode a frequently
>> used user-defined type "Coord" is highlighted like any built-in type
>> (int, bool, etc.) I searched around for a while but found only very
>> limited information. The best I could produce was the following:
>>
>> ;; customize font-locking
>> (font-lock-add-keywords
>> 'c++-mode
>> '(("\\<\\(Coord\\)" 1 font-lock-type-face)
>> ) )
>>
>> This sort of works. In a statement like:
>>
>> Coord fcn (Coord x);
>>
>> "Coord" is highlighted twice, but neither "fcn" nor "x" is. In a
>> normal statement like:
>>
>> int fcn (int x)
>>
>> "int" is highlighted as are "fcn" and "x".
>>
>> Can anyone suggest a way to make the behavior for Coord match that for
>> int. Any links to detail documentation on how this works would also
>> be appreciated. (For example, why all the quotes and slashes in the
>> .emacs code?)
>
>
> Maybe http://simon.nitro.dk/dotfiles/emacs/ctypes.el is what you need:
>
> (autoload 'ctypes-define-type "ctypes"
> "Add a new TYPE to current major mode and inform font-lock." t)
>
> (add-hook 'c++-mode-hook
> (lambda ()
> (ctypes-define-type "Coord")))
>
That worked! Thanks!
-Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: help with font locking
2006-01-12 20:06 ` Alan Mackenzie
@ 2006-01-13 0:27 ` Mark P
0 siblings, 0 replies; 5+ messages in thread
From: Mark P @ 2006-01-13 0:27 UTC (permalink / raw)
Alan Mackenzie wrote:
> In gnu.emacs.help Mark P <usenet@fall2005remove.fastmailcaps.fm> wrote:
>
>>I'm trying to edit my .emacs file so that in c++-mode a frequently used
>>user-defined type "Coord" is highlighted like any built-in type (int,
>>bool, etc.) I searched around for a while but found only very limited
>>information. The best I could produce was the following:
>
>
> [ .... ]
>
>
>>Can anyone suggest a way to make the behavior for Coord match that for
>>int. Any links to detail documentation on how this works would also be
>>appreciated. (For example, why all the quotes and slashes in the .emacs
>>code?)
>
>
> In CC Mode 5.30, the new variable c++-font-lock-extra-types was
> introduced to do exactly what you want. Chances are, you've only got CC
> Mode 5.28 (do M-x c-version). In that case, download the latest version
> (5.31.1) from <http://cc-mode.sourceforge.net/release.php>. The variable
> is documented on page "Font Locking Preliminaries" of the manual
> distributed with the release.
>
Great tip, thanks! Not only does it solve my problem, it also improves
the font-lock behavior quite generally.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-01-13 0:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-12 0:20 help with font locking Mark P
2006-01-12 17:31 ` Kevin Rodgers
2006-01-12 20:06 ` Alan Mackenzie
2006-01-13 0:27 ` Mark P
[not found] ` <mailman.847.1137087711.26925.help-gnu-emacs@gnu.org>
2006-01-12 20:28 ` Mark P
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).