help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fontifying function calls in emacs-lisp-mode


From: Tim X
Subject: Re: Fontifying function calls in emacs-lisp-mode
Date: Wed, 04 Jul 2007 19:10:16 +1000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

rjp <richard.pauls@itt.com> writes:

> Hi Guys, I found this thread through a google search and it sounds very
> similar to what I need to do.
>
> I am trying to make all function calls blue in xemacs. I have already
> changed the face for function names, but this only affects the function
> definition line. I want to colorize the function call line as well. I am not
> very familiar with customizing emacs but it sounds like this LISP code
> discussed here is trying to do the same thing. Is this correct? Can you give
> me something that I can just paste into my init.el file to do the trick?
>
> Thanks very much,
>
> Rich
>
> Nordlöw wrote:
>> 
>> On 25 Apr, 08:36, martin rudalics <rudal...@gmx.at> wrote:
>>> (defun pnw-emacs-lisp-mode-extra-font-locking ()
>>>    (font-lock-add-keywords
>>>     nil
>>>     (list
>>>      ...
>>>     t)) ; Try to assign the third argument HOW here to anything but 'set
>> 
>> Brilliant!
>> 
>> I had forgot about that argument...
>> 
>> It just realized that my regexp does not correctly fontify quoted
>> constructs. I guess you need a full emacs-lisp parser to do that. But
>> it works good enough for my needs.
>> 

I think you may need to re-think what you are trying to do. Syntax highlighting
is supposed to provide additional clues regarding your code and not just make
things look pretty. However, in a language like lisp that is so function
oriented, what will having function names in a different colour really give
you? Essentially, the first element of a list is either a function or special
form (unless the list is quoted). So, there isn't much added by being in a
different colour that isn't already fairly clear by the position relative to
the parenthesis. As emacs font-lockinig is regexp based, you also have no way
of distinguishing between functions and special forms. 

I guess you could have all built-in function coloured differently from user
defined functions (or more precisely, functions that are not part of the
standard). However, to do this, you would need to create a large regexp due to
the number of built-in functions in most lisp dialects. This is likely to make
font-lock a bit slow. 

A more useful approach would be to font-lock things that are not functions in
different colours (i.e. strings, symbols, numbers etc), but I think the various
lisp modes already do this fairly well. 

To set up customized font-locking I'd suggest looking at the relevant section
of the elisp manual. You will need to be fairly good at regular expressions to
do this. Looking at a simple mode will probably help. I'd recommend looking at
the emacs wiki and reading the sections on adding additional font-lock keywords
and the sections on deriving a new mode as they both have pretty good examples.
simple modes, like sql mode is also a good place to see how this is
implemented. 

the emacs wiki is at http://www.emacswiki.org

HTH

Tim



-- 
tcross (at) rapttech dot com dot au


reply via email to

[Prev in Thread] Current Thread [Next in Thread]