unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: Fontifying function calls in emacs-lisp-mode
Date: Wed, 04 Jul 2007 19:10:16 +1000	[thread overview]
Message-ID: <87ps38pm9z.fsf@lion.rapttech.com.au> (raw)
In-Reply-To: mailman.3007.1183472059.32220.help-gnu-emacs@gnu.org

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

  parent reply	other threads:[~2007-07-04  9:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.2492.1177484258.7795.help-gnu-emacs@gnu.org>
2007-04-26  9:21 ` Fontifying function calls in emacs-lisp-mode Nordlöw
2007-07-03 13:12   ` rjp
     [not found]   ` <mailman.3007.1183472059.32220.help-gnu-emacs@gnu.org>
2007-07-04  9:10     ` Tim X [this message]
2007-04-25  6:36 martin rudalics
  -- strict thread matches above, loose matches on Subject: below --
2007-04-24 15:47 Nordlöw
2007-04-24 16:46 ` Peter Tury

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ps38pm9z.fsf@lion.rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).