Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how is emacs lisp syntax colored in emacs-lisp-mode?

210 views
Skip to first unread message

Xah Lee

unread,
Mar 10, 2009, 8:45:03 AM3/10/09
to
when coding elisp, lately i find myself using camelCase style for my
own function and variable names. Because i find that easier to
distinguish from built-in function/var/keywords.

on thinking about this, i thought it would not be necessary if emacs-
lisp-mode would just color all built in functions and variables.
However, the way it is syntax colored seems strange, unlike in most
major modes for langs where each class of keywords gets one color.

for example, these keywords would be colored purple by default:

defun, lambda, while, if, progn, save-restriction, ...

while the following built-in keywords are uncolored (black):
narrow-to-region, mapc, goto-char, point-min, search-forward, car,
nil, replace-match ... etc.

is there a principle of how the keywords are colored?

thanks

Xah
http://xahlee.org/


Tassilo Horn

unread,
Mar 10, 2009, 9:43:31 AM3/10/09
to
Xah Lee <xah...@gmail.com> writes:

Hi Xah,

> on thinking about this, i thought it would not be necessary if emacs-
> lisp-mode would just color all built in functions and variables.
> However, the way it is syntax colored seems strange, unlike in most
> major modes for langs where each class of keywords gets one color.
>
> for example, these keywords would be colored purple by default:
>
> defun, lambda, while, if, progn, save-restriction, ...

That's the case, isn't it?

> while the following built-in keywords are uncolored (black):
> narrow-to-region, mapc, goto-char, point-min, search-forward, car,
> nil, replace-match ... etc.

Function names like the ones you listed aren't colored in function calls
unless they're one of the special forms you mentioned before.

> is there a principle of how the keywords are colored?

Yes, see the elisp manual:

,----[ (info "(elisp)Levels of Font Lock") ]
| Many major modes offer three different levels of fontification. You
| can define multiple levels by using a list of symbols for KEYWORDS in
| `font-lock-defaults'. Each symbol specifies one level of
| fontification; it is up to the user to choose one of these levels,
| normally by setting `font-lock-maximum-decoration' (*note Font Lock:
| (emacs)Font Lock.). The chosen level's symbol value is used to
| initialize `font-lock-keywords'.
|
| Here are the conventions for how to define the levels of
| fontification:
|
| * Level 1: highlight function declarations, file directives (such as
| include or import directives), strings and comments. The idea is
| speed, so only the most important and top-level components are
| fontified.
|
| * Level 2: in addition to level 1, highlight all language keywords,
| including type names that act like keywords, as well as named
| constant values. The idea is that all keywords (either syntactic
| or semantic) should be fontified appropriately.
|
| * Level 3: in addition to level 2, highlight the symbols being
| defined in function and variable declarations, and all builtin
| function names, wherever they appear.
`----

Bye,
Tassilo

Xah Lee

unread,
Mar 10, 2009, 4:59:38 PM3/10/09
to
Xah Lee <xah...@gmail.com> wrote:
> on thinking about this, i thought it would not be necessary if emacs-
> lisp-mode would just color all built in functions and variables.
> However, the way it is syntax colored seems strange, unlike in most
> major modes for langs where each class of keywords gets one color.

> for example, these keywords would be colored purple by default:

> defun, lambda, while, if, progn, save-restriction, ...

> while the following built-in keywords are uncolored (black):
> narrow-to-region, mapc, goto-char, point-min, search-forward, car,
> nil, replace-match ... etc.

On Mar 10, 6:43 am, Tassilo Horn <tass...@member.fsf.org> wrote:
> Function names like the ones you listed aren't colored in function calls
> unless they're one of the special forms you mentioned before.

I see. Thanks.

> > is there a principle of how the keywords are colored?
>
> Yes, see the elisp manual:
>
> ,----[ (info "(elisp)Levels of Font Lock") ]

> | Many major modes offer three different levels of fontification...
> ...

does emacs-lisp-mode support more than level 1?

i have my emacs set to level 2. I tried customize-group on emacs-lisp-
mode but that doesn't seem available. I tried to set font-lock-maximum-
decoration to 3 but that doesn't seems to have effect.

Xah
http://xahlee.org/


W Dan Meyer

unread,
Mar 10, 2009, 6:01:55 PM3/10/09
to
Xah Lee <xah...@gmail.com> writes:

Yes, because font-lock-maximum-decoration is usually set (as for my CVS
Emacs) to t, which indicate the highest possible level.
W Dan

>
> Xah
> ∑ http://xahlee.org/
>
> ☄

Nikolaj Schumacher

unread,
Mar 10, 2009, 4:06:16 PM3/10/09
to Xah Lee, help-gn...@gnu.org
Xah Lee <xah...@gmail.com> wrote:

> for example, these keywords would be colored purple by default:
>
> defun, lambda, while, if, progn, save-restriction, ...
>
> while the following built-in keywords are uncolored (black):
> narrow-to-region, mapc, goto-char, point-min, search-forward, car,
> nil, replace-match ... etc.

Those aren't emacs lisp "keywords". Those are ordinary functions. They
are called "built-in", because they happen to be written in C instead of
Lisp. But that is hardly relevant, and can even change over time.

defun, lambda and while are not functions, but special forms. They are
part of the language.

save-*, with-* and others are macros based on special forms. They
aren't keywords either, but probably colored (and indented) differently
for convenience.


If you want to highlight symbols that are "shipped" with Emacs (to
whatever extend) you'll need to add a matcher function to the font lock
keywords that checks whether, and in which files, symbols have been defined


> is there a principle of how the keywords are colored?


regards,
Nikolaj Schumacher


Johan Bockgård

unread,
Mar 11, 2009, 1:51:38 PM3/11/09
to help-gn...@gnu.org
Nikolaj Schumacher <m...@nschum.de> writes:

> defun, lambda and while are not functions, but special forms.

lambda isn't.

Xah Lee

unread,
Mar 16, 2009, 7:54:08 PM3/16/09
to
On Mar 10, 1:06 pm, Nikolaj Schumacher <m...@nschum.de> wrote:

> If you want to highlight symbols that are "shipped" with Emacs (to
> whatever extend) you'll need to add a matcher function to the font lock
> keywords that checks whether, and in which files, symbols have been defined

doesn't anyone see this as a defect? namely, the fact that only parts
of keywords are syntax colored in emacs-lisp-mode. This behavior is
contrary to all other major modes.

i haven't coded Common or Scheme lisp. Does major modes for those only
color only a subset of the lang's keywords? (i.e. if so, maybe this is
a lisp lang tradition)

Xah
http://xahlee.org/


Xah Lee

unread,
Mar 16, 2009, 10:41:11 PM3/16/09
to
I've cleaned up and placed this writing here:

• Emacs Lisp Mode Syntax Coloring Problem
http://xahlee.org/emacs/modernization_elisp_syntax_color.html

also filed a bug report, #2630.
http://groups.google.com/group/gnu.emacs.bug/browse_frm/thread/76ae27dffbd356a6

Xah
http://xahlee.org/


Nikolaj Schumacher

unread,
Mar 17, 2009, 4:41:59 AM3/17/09
to Xah Lee, help-gn...@gnu.org
Xah Lee <xah...@gmail.com> wrote:

> On Mar 10, 1:06 pm, Nikolaj Schumacher <m...@nschum.de> wrote:
>
>> If you want to highlight symbols that are "shipped" with Emacs (to
>> whatever extend) you'll need to add a matcher function to the font lock
>> keywords that checks whether, and in which files, symbols have been defined
>
> doesn't anyone see this as a defect? namely, the fact that only parts
> of keywords are syntax colored in emacs-lisp-mode. This behavior is
> contrary to all other major modes.

What do you mean?
If I write printf in C-mode, it isn't colored, either.

printf isn't a keyword, it's a library function, just as "message"
is in elisp. Why is it interesting to highlight functions that shipped
with Emacs, say erc-.*?

You use the word "keyword" as in font-lock-keywords, but please not that
the name has additional meanings. In C, reserved words are named
keywords, in Emacs Lisp they are things like :foo and :bar. To avoid
confusion, maybe you should call them symbols.


regards,
Nikolaj Schumacher


Xah Lee

unread,
Mar 17, 2009, 5:53:17 AM3/17/09
to

I think there are 2 basic issues that indicates its' a problem.

A: it seems to be it is not clear, or consist, the way emacs color
some of the lisp symbols but not others.

B: emacs-lisp-mode does not support font-lock-maximum-decoration for
progressive levels of font coloring.

On this elisp manual page:

• What Is a Function - GNU Emacs Lisp Reference Manual
http://xahlee.org/elisp/What-Is-a-Function.html

it lists: function, primitive, lambda expression, special form, macro,
command, and others.

the way emacs-lisp-mode color'd symbols, doesn't seem to me to be a
particular class of the above.

it appears to me, the way it chooses symbol to color, is not based on
some strict technicality, but rather chosen for functions that are
likely to open a significant block of code. e.g. let, lambda, if,
when, while, progn, cond, condition-case, save-excursion, with-
current-buffer. Note that it also colors with-selected-window, with-
output-to-temp-buffer, with-selected-window, unless. Note that it
doesn't color for example: eq, or, setq, cons.

Xah
http://xahlee.org/


0 new messages