all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to enable font lock for functions called by other functions
@ 2008-08-11 10:13 doyoucy
  2008-08-11 18:19 ` Colin S. Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: doyoucy @ 2008-08-11 10:13 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

I noticed that the "Font Lock Function Name Face" just enables the
font lock for function name when I decalare new function. But other
functions called by this outer function don't have any color.

For example:
void foo1()
{
    foo2();
}

The function foo1 has font-lock enabled and function foo2 is just
plain text.
So, is there any options to enable the font lock for inside fuunctions
(foo2)?

I'm using GNU Emacs 22.2.1, thanks!





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

* Re: How to enable font lock for functions called by other functions
  2008-08-11 10:13 How to enable font lock for functions called by other functions doyoucy
@ 2008-08-11 18:19 ` Colin S. Miller
  2008-08-11 20:03 ` Nikolaj Schumacher
       [not found] ` <mailman.16402.1218485044.18990.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Colin S. Miller @ 2008-08-11 18:19 UTC (permalink / raw)
  To: help-gnu-emacs

doyoucy@gmail.com wrote:
> Hi all,
> 
> I noticed that the "Font Lock Function Name Face" just enables the
> font lock for function name when I decalare new function. But other
> functions called by this outer function don't have any color.
> 
> For example:
> void foo1()
> {
>     foo2();
> }
> 
> The function foo1 has font-lock enabled and function foo2 is just
> plain text.
> So, is there any options to enable the font lock for inside fuunctions
> (foo2)?
> 
> I'm using GNU Emacs 22.2.1, thanks!
> 
> 
> 

M-x font-lock-mode
will turn on fontifcation (syntax highlighting) for the current buffer,
assuming there is a syntax table. For most programming modes (including C and C++)
there is.

M-x font-lock-fontify-buffer
will force emacs to refontify the buffer. This normally happens automatically,
but emacs can get confused when you comment out a section of code (or uncomment it).
Emacs will also refuse to automatically fontify large files, this command will force
emacs to do so.

HTH,
Colin S. Miller


-- 
Replace the obvious in my email address with the first three letters of the hostname to reply.


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

* Re: How to enable font lock for functions called by other functions
  2008-08-11 10:13 How to enable font lock for functions called by other functions doyoucy
  2008-08-11 18:19 ` Colin S. Miller
@ 2008-08-11 20:03 ` Nikolaj Schumacher
       [not found] ` <mailman.16402.1218485044.18990.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Nikolaj Schumacher @ 2008-08-11 20:03 UTC (permalink / raw)
  To: doyoucy; +Cc: help-gnu-emacs

doyoucy@gmail.com wrote:

> For example:
> void foo1()
> {
>     foo2();
> }
>
> The function foo1 has font-lock enabled and function foo2 is just
> plain text.
> So, is there any options to enable the font lock for inside fuunctions
> (foo2)?

You can use the following in your `c-mode-common-hook', though I'm sure
it breaks down in same cases.

(font-lock-add-keywords
   nil `(("\\([[:alpha:]_][[:alnum:]_]*\\)("  1 font-lock-function-name-face)))


regards,
Nikolaj Schumacher




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

* Re: How to enable font lock for functions called by other functions
       [not found] ` <mailman.16402.1218485044.18990.help-gnu-emacs@gnu.org>
@ 2008-08-12  2:03   ` doyoucy
  2008-08-13 11:53     ` Nikolaj Schumacher
       [not found]     ` <mailman.16566.1218628405.18990.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: doyoucy @ 2008-08-12  2:03 UTC (permalink / raw)
  To: help-gnu-emacs


> (font-lock-add-keywords
>    nil `(("\\([[:alpha:]_][[:alnum:]_]*\\)("  1 font-lock-function-name-face)))


Thanks guys!

I think coloring the inner function name is common practice for many
code navigation tools, the code above works, but it also applys
function name face to the keywords like "if" "while".

I'm wondering why emacs don't have an option to enable it.


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

* Re: How to enable font lock for functions called by other functions
  2008-08-12  2:03   ` doyoucy
@ 2008-08-13 11:53     ` Nikolaj Schumacher
       [not found]     ` <mailman.16566.1218628405.18990.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Nikolaj Schumacher @ 2008-08-13 11:53 UTC (permalink / raw)
  To: doyoucy; +Cc: help-gnu-emacs

doyoucy@gmail.com wrote:

>> (font-lock-add-keywords
>>    nil `(("\\([[:alpha:]_][[:alnum:]_]*\\)("  1 font-lock-function-name-face)))
>
> I think coloring the inner function name is common practice for many
> code navigation tools, the code above works, but it also applys
> function name face to the keywords like "if" "while".

I hope I mentioned it was a hack? :)
It works for me, because I put spaces before if and while.

(font-lock-add-keywords
 nil `(("\\([[:alpha:]_][[:alnum:]_]*\\)("
        1 font-lock-function-name-face)) t)

could fix this particular issue.

> I'm wondering why emacs don't have an option to enable it.

Most likely the answer to such questions is:  Because nobody has
implemented it.

Doing it properly would probably require Emacs to parse the language,
which it doesn't.  And hacks such as mine fail on many borderline cases
like operator().



regards,
Nikolaj Schumacher




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

* Re: How to enable font lock for functions called by other functions
       [not found]     ` <mailman.16566.1218628405.18990.help-gnu-emacs@gnu.org>
@ 2008-08-18  5:14       ` doyoucy
  0 siblings, 0 replies; 6+ messages in thread
From: doyoucy @ 2008-08-18  5:14 UTC (permalink / raw)
  To: help-gnu-emacs

Nikolaj,

Your hack now works fine for my C code navigaion.

Thanks, Its really helpful!


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

end of thread, other threads:[~2008-08-18  5:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-11 10:13 How to enable font lock for functions called by other functions doyoucy
2008-08-11 18:19 ` Colin S. Miller
2008-08-11 20:03 ` Nikolaj Schumacher
     [not found] ` <mailman.16402.1218485044.18990.help-gnu-emacs@gnu.org>
2008-08-12  2:03   ` doyoucy
2008-08-13 11:53     ` Nikolaj Schumacher
     [not found]     ` <mailman.16566.1218628405.18990.help-gnu-emacs@gnu.org>
2008-08-18  5:14       ` doyoucy

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.