all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Fontifying function calls in emacs-lisp-mode
@ 2007-04-24 15:47 Nordlöw
  2007-04-24 16:46 ` Peter Tury
  0 siblings, 1 reply; 6+ messages in thread
From: Nordlöw @ 2007-04-24 15:47 UTC (permalink / raw)
  To: help-gnu-emacs

Hey there, Emacs Lovers!

I am trying to fontify function calls in emacs-lisp-mode and have come
up with the following code. It however replaces fontification of
keyword statements, such as defun, defface, etc, eventhough i use
"keep".

How can I avoid this?

;; Function call face
(defface font-lock-function-call-face	;function-call
  '((((class color)) (:inherit font-lock-function-name-face :bold
nil)))
  "Font Lock mode face used to highlight function calls.")

;; Emacs LISP Extra Font Locking

(defun pnw-emacs-lisp-mode-extra-font-locking ()
  (font-lock-add-keywords
   nil
   (list
    ;; special constants nil and t
    (cons (concat "\\<" "\\(" "nil" "\\|" "t" "\\)" "\\>")
	  '(1 'font-lock-number-literal-face keep))
    ;; function calls
    (cons (concat "(" "[\t ]*" "\\(" "\\w+" "\\)")
 	  '(1 'font-lock-function-call-face keep))
    )))

(add-hook 'emacs-lisp-mode-hook 'pnw-emacs-lisp-mode-extra-font-
locking)


Thanks in advance,
Nordlöw

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

* Re: Fontifying function calls in emacs-lisp-mode
  2007-04-24 15:47 Nordlöw
@ 2007-04-24 16:46 ` Peter Tury
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Tury @ 2007-04-24 16:46 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> I am trying to fontify function calls in emacs-lisp-mode and have come
> up with the following code. It however replaces fontification of
> keyword statements, such as defun, defface, etc, eventhough i use
> "keep".

I think defun, defface, etc. are just the same kind of function calls
what you want to fontify. Indeed they are implemented in the same way
in .el files as your own functions...

Have you played with `prepend'?

Maybe your fontification is interpreted first, so "default" settings
will appear only if they are defined as override=t -- what is not
probable.

Maybe you should protect those "keywords" by more precise regexps??

> (defun pnw-emacs-lisp-mode-extra-font-locking ()
>   (font-lock-add-keywords
>    nil
>    (list
>     ;; special constants nil and t
>     (cons (concat "\\<" "\\(" "nil" "\\|" "t" "\\)" "\\>")

      (cons "\\<\\(nil\\|t\\)\\>"

> 	  '(1 'font-lock-number-literal-face keep))
>     ;; function calls
>     (cons (concat "(" "[\t ]*" "\\(" "\\w+" "\\)")

      (cons "([\t ]*\\(defun\\|defface\\|etc\\)\\(\\w+\\)" and fontify
      only 2nd group??

\bye
P

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

* Re: Fontifying function calls in emacs-lisp-mode
@ 2007-04-25  6:36 martin rudalics
  0 siblings, 0 replies; 6+ messages in thread
From: martin rudalics @ 2007-04-25  6:36 UTC (permalink / raw)
  To: per.nordlow; +Cc: help-gnu-emacs

(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

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

* Re: Fontifying function calls in emacs-lisp-mode
       [not found] <mailman.2492.1177484258.7795.help-gnu-emacs@gnu.org>
@ 2007-04-26  9:21 ` Nordlöw
  2007-07-03 13:12   ` rjp
       [not found]   ` <mailman.3007.1183472059.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Nordlöw @ 2007-04-26  9:21 UTC (permalink / raw)
  To: help-gnu-emacs

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.


Thanks,

Nordlöw

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

* Re: Fontifying function calls in emacs-lisp-mode
  2007-04-26  9:21 ` Nordlöw
@ 2007-07-03 13:12   ` rjp
       [not found]   ` <mailman.3007.1183472059.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: rjp @ 2007-07-03 13:12 UTC (permalink / raw)
  To: Help-gnu-emacs


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.
> 
> 
> Thanks,
> 
> Nordlöw
> 
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> 
> 

-- 
View this message in context: http://www.nabble.com/Fontifying-function-calls-in-emacs-lisp-mode-tf3639819.html#a11411888
Sent from the Emacs - Help mailing list archive at Nabble.com.

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

* Re: Fontifying function calls in emacs-lisp-mode
       [not found]   ` <mailman.3007.1183472059.32220.help-gnu-emacs@gnu.org>
@ 2007-07-04  9:10     ` Tim X
  0 siblings, 0 replies; 6+ messages in thread
From: Tim X @ 2007-07-04  9:10 UTC (permalink / raw)
  To: help-gnu-emacs

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

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

end of thread, other threads:[~2007-07-04  9:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-25  6:36 Fontifying function calls in emacs-lisp-mode martin rudalics
     [not found] <mailman.2492.1177484258.7795.help-gnu-emacs@gnu.org>
2007-04-26  9:21 ` 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
  -- strict thread matches above, loose matches on Subject: below --
2007-04-24 15:47 Nordlöw
2007-04-24 16:46 ` Peter Tury

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.