unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How do I get emacs to highlight subroutine calls in c-mode.
@ 2003-10-10 20:47 Tom Oswald
       [not found] ` <mailman.1526.1065861258.21628.help-gnu-emacs@gnu.org>
  2003-10-12  1:43 ` jan
  0 siblings, 2 replies; 7+ messages in thread
From: Tom Oswald @ 2003-10-10 20:47 UTC (permalink / raw)


I would like subroutine calls hightlighted.  For example, in 
"callThisSub(param1)" enacs would highlight "callThisSub".

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

* Re: How do I get emacs to highlight subroutine calls in c-mode.
       [not found] ` <mailman.1526.1065861258.21628.help-gnu-emacs@gnu.org>
@ 2003-10-11 12:21   ` lawrence mitchell
  2003-10-12 21:26     ` jan
       [not found]     ` <mailman.1544.1065932192.21628.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: lawrence mitchell @ 2003-10-11 12:21 UTC (permalink / raw)


jan wrote:

[...]

> ;; add it to the font lock tables
> (bind-hook c-mode-hook
   ^^^^^^^^^^^^^^^^^^^^^

You probably meant:

 (add-hook 'c-mode-hook

> 	(font-lock-add-keywords nil
> 		'(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face))) t))


-- 
lawrence mitchell <wence@gmx.li>

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

* Re: How do I get emacs to highlight subroutine calls in c-mode.
  2003-10-10 20:47 How do I get emacs to highlight subroutine calls in c-mode Tom Oswald
       [not found] ` <mailman.1526.1065861258.21628.help-gnu-emacs@gnu.org>
@ 2003-10-12  1:43 ` jan
  1 sibling, 0 replies; 7+ messages in thread
From: jan @ 2003-10-12  1:43 UTC (permalink / raw)
  Cc: help-gnu-emacs


> I would like subroutine calls hightlighted.  For example, in
> "callThisSub(param1)" enacs would highlight "callThisSub".

(require 'font-lock)

;; create a face for function calls
(defface font-lock-function-call-face
  '((t (:foreground "DarkBlue")))
  "Font Lock mode face used to highlight function calls."
  :group 'font-lock-highlighting-faces)
(defvar font-lock-function-call-face 'font-lock-function-call-face)

;; add it to the font lock tables 
(bind-hook c-mode-hook
	(font-lock-add-keywords nil
		'(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face))) t))

try placing this in your .emacs file.

-- 
jan

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

* Re: How do I get emacs to highlight subroutine calls in c-mode.
  2003-10-11 12:21   ` lawrence mitchell
@ 2003-10-12 21:26     ` jan
       [not found]     ` <mailman.1544.1065932192.21628.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: jan @ 2003-10-12 21:26 UTC (permalink / raw)


lawrence mitchell <wence@gmx.li> writes:

> > (bind-hook c-mode-hook
>    ^^^^^^^^^^^^^^^^^^^^^
> You probably meant:
> 
>  (add-hook 'c-mode-hook
> 
> > 	(font-lock-add-keywords nil
> > 		'(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face))) t))

Yes, sorry, I didn't test the code I posted, I just extracted the
relevant looking parts from my init files and accidentally included my
bind-hook macro. Here is a tested version

;; turn on font lock with maximum decoration
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

(require 'font-lock)

;; create a face for function calls
(defface font-lock-function-call-face
  '((t (:foreground "DarkBlue")))
  "Font Lock mode face used to highlight function calls."
  :group 'font-lock-highlighting-faces)
(defvar font-lock-function-call-face 'font-lock-function-call-face)

;; add it to the font lock tables
(add-hook 'c-mode-hook
	  (lambda ()
	    (font-lock-add-keywords
	     nil
	     '(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face)) t)))

-- 
jan

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

* Re: How do I get emacs to highlight subroutine calls in c-mode.
       [not found]     ` <mailman.1544.1065932192.21628.help-gnu-emacs@gnu.org>
@ 2003-10-13 13:44       ` Javier Oviedo
  2003-10-17 17:40         ` jan
  2003-10-16 19:36       ` Tom Oswald
  1 sibling, 1 reply; 7+ messages in thread
From: Javier Oviedo @ 2003-10-13 13:44 UTC (permalink / raw)


This is pretty cool. Could this be adapted to also work for calls through
function pointers? That would be quite nice!!

Example:
(*someStructure.someCallTable->someFunctionPointer)((void *)&test);


Thanks in advance!!

--
Javier


"jan" <janmar@iprimus.com.au> wrote in message
news:mailman.1544.1065932192.21628.help-gnu-emacs@gnu.org...
> lawrence mitchell <wence@gmx.li> writes:
>
> > > (bind-hook c-mode-hook
> >    ^^^^^^^^^^^^^^^^^^^^^
> > You probably meant:
> >
> >  (add-hook 'c-mode-hook
> >
> > > (font-lock-add-keywords nil
> > > '(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face))) t))
>
> Yes, sorry, I didn't test the code I posted, I just extracted the
> relevant looking parts from my init files and accidentally included my
> bind-hook macro. Here is a tested version
>
> ;; turn on font lock with maximum decoration
> (global-font-lock-mode t)
> (setq font-lock-maximum-decoration t)
>
> (require 'font-lock)
>
> ;; create a face for function calls
> (defface font-lock-function-call-face
>   '((t (:foreground "DarkBlue")))
>   "Font Lock mode face used to highlight function calls."
>   :group 'font-lock-highlighting-faces)
> (defvar font-lock-function-call-face 'font-lock-function-call-face)
>
> ;; add it to the font lock tables
> (add-hook 'c-mode-hook
>   (lambda ()
>     (font-lock-add-keywords
>      nil
>      '(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face)) t)))
>
> --
> jan
>
>
>
>

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

* Re: How do I get emacs to highlight subroutine calls in c-mode.
       [not found]     ` <mailman.1544.1065932192.21628.help-gnu-emacs@gnu.org>
  2003-10-13 13:44       ` Javier Oviedo
@ 2003-10-16 19:36       ` Tom Oswald
  1 sibling, 0 replies; 7+ messages in thread
From: Tom Oswald @ 2003-10-16 19:36 UTC (permalink / raw)


jan wrote:
> lawrence mitchell <wence@gmx.li> writes:
> 
> 
>>>(bind-hook c-mode-hook
>>
>>   ^^^^^^^^^^^^^^^^^^^^^
>>You probably meant:
>>
>> (add-hook 'c-mode-hook
>>
>>
>>>	(font-lock-add-keywords nil
>>>		'(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face))) t))
> 
> 
> Yes, sorry, I didn't test the code I posted, I just extracted the
> relevant looking parts from my init files and accidentally included my
> bind-hook macro. Here is a tested version
> 
> ;; turn on font lock with maximum decoration
> (global-font-lock-mode t)
> (setq font-lock-maximum-decoration t)
> 
> (require 'font-lock)
> 
> ;; create a face for function calls
> (defface font-lock-function-call-face
>   '((t (:foreground "DarkBlue")))
>   "Font Lock mode face used to highlight function calls."
>   :group 'font-lock-highlighting-faces)
> (defvar font-lock-function-call-face 'font-lock-function-call-face)
> 
> ;; add it to the font lock tables
> (add-hook 'c-mode-hook
> 	  (lambda ()
> 	    (font-lock-add-keywords
> 	     nil
> 	     '(("\\<\\(\\sw+\\) ?(" 1 font-lock-function-call-face)) t)))
> 

How would I add italic to the display?  At present it displays the function 
names in "DarkBlue".  What would be required to display function names in 
"DarkBlue" plus italics?

Tom

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

* Re: How do I get emacs to highlight subroutine calls in c-mode.
  2003-10-13 13:44       ` Javier Oviedo
@ 2003-10-17 17:40         ` jan
  0 siblings, 0 replies; 7+ messages in thread
From: jan @ 2003-10-17 17:40 UTC (permalink / raw)
  Cc: help-gnu-emacs

"Javier Oviedo" <email_joviedo@yahoo.com> writes:

> This is pretty cool. Could this be adapted to also work for calls
> through function pointers? That would be quite nice!!
> 
> Example:
> (*someStructure.someCallTable->someFunctionPointer)((void *)&test);

("\\<\\(\\sw+\\)[ \t\n)]*(" 1 font-lock-function-call-face)

This version will do the job, however, being more general it also runs
the risk of getting false positive matches. I can't think of any cases
off the top of my head.

You can still get false negatives, for example:

(*someStructure.someCallTable->someFunctionPointer)
     /* comment */
     ((void *)&test);

or

some_function_array[0]();

but I think it's best not to handle those cases unless you actually
write code like that.

The basic problem is that regular expressions aren't powerful enough
to describe a language like C (or almost any other language for that
matter). They cannot be made to understand operator precedence or
remove redundant parenthesis or handle any kind of nesting. In other
words they really have no understanding of the structure of the code
and the font tables are reduced to making guesses by matching against
simple text patterns.

-- 
jan

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

end of thread, other threads:[~2003-10-17 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-10 20:47 How do I get emacs to highlight subroutine calls in c-mode Tom Oswald
     [not found] ` <mailman.1526.1065861258.21628.help-gnu-emacs@gnu.org>
2003-10-11 12:21   ` lawrence mitchell
2003-10-12 21:26     ` jan
     [not found]     ` <mailman.1544.1065932192.21628.help-gnu-emacs@gnu.org>
2003-10-13 13:44       ` Javier Oviedo
2003-10-17 17:40         ` jan
2003-10-16 19:36       ` Tom Oswald
2003-10-12  1:43 ` jan

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