all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how is emacs lisp syntax colored in emacs-lisp-mode?
@ 2009-03-10 12:45 Xah Lee
  2009-03-10 13:43 ` Tassilo Horn
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Xah Lee @ 2009-03-10 12:45 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-10 12:45 how is emacs lisp syntax colored in emacs-lisp-mode? Xah Lee
@ 2009-03-10 13:43 ` Tassilo Horn
  2009-03-10 20:59   ` Xah Lee
  2009-03-10 20:06 ` Nikolaj Schumacher
       [not found] ` <mailman.2878.1237105097.31690.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 10+ messages in thread
From: Tassilo Horn @ 2009-03-10 13:43 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@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


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

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-10 12:45 how is emacs lisp syntax colored in emacs-lisp-mode? Xah Lee
  2009-03-10 13:43 ` Tassilo Horn
@ 2009-03-10 20:06 ` Nikolaj Schumacher
  2009-03-11 17:51   ` Johan Bockgård
       [not found] ` <mailman.2878.1237105097.31690.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 10+ messages in thread
From: Nikolaj Schumacher @ 2009-03-10 20:06 UTC (permalink / raw)
  To: Xah Lee; +Cc: help-gnu-emacs

Xah Lee <xahlee@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




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

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-10 13:43 ` Tassilo Horn
@ 2009-03-10 20:59   ` Xah Lee
  2009-03-10 22:01     ` W Dan Meyer
  0 siblings, 1 reply; 10+ messages in thread
From: Xah Lee @ 2009-03-10 20:59 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-10 20:59   ` Xah Lee
@ 2009-03-10 22:01     ` W Dan Meyer
  0 siblings, 0 replies; 10+ messages in thread
From: W Dan Meyer @ 2009-03-10 22:01 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@gmail.com> writes:

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

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/
>
> ☄


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

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-10 20:06 ` Nikolaj Schumacher
@ 2009-03-11 17:51   ` Johan Bockgård
  0 siblings, 0 replies; 10+ messages in thread
From: Johan Bockgård @ 2009-03-11 17:51 UTC (permalink / raw)
  To: help-gnu-emacs

Nikolaj Schumacher <me@nschum.de> writes:

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

lambda isn't.





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

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
       [not found] ` <mailman.2878.1237105097.31690.help-gnu-emacs@gnu.org>
@ 2009-03-16 23:54   ` Xah Lee
  2009-03-17  2:41     ` Xah Lee
                       ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Xah Lee @ 2009-03-16 23:54 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-16 23:54   ` Xah Lee
@ 2009-03-17  2:41     ` Xah Lee
  2009-03-17  8:41     ` Nikolaj Schumacher
       [not found]     ` <mailman.3385.1237279326.31690.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 10+ messages in thread
From: Xah Lee @ 2009-03-17  2:41 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
  2009-03-16 23:54   ` Xah Lee
  2009-03-17  2:41     ` Xah Lee
@ 2009-03-17  8:41     ` Nikolaj Schumacher
       [not found]     ` <mailman.3385.1237279326.31690.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 10+ messages in thread
From: Nikolaj Schumacher @ 2009-03-17  8:41 UTC (permalink / raw)
  To: Xah Lee; +Cc: help-gnu-emacs

Xah Lee <xahlee@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




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

* Re: how is emacs lisp syntax colored in emacs-lisp-mode?
       [not found]     ` <mailman.3385.1237279326.31690.help-gnu-emacs@gnu.org>
@ 2009-03-17  9:53       ` Xah Lee
  0 siblings, 0 replies; 10+ messages in thread
From: Xah Lee @ 2009-03-17  9:53 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 17, 1:41 am, Nikolaj Schumacher <m...@nschum.de> wrote:
> 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.

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/^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-03-17  9:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-10 12:45 how is emacs lisp syntax colored in emacs-lisp-mode? Xah Lee
2009-03-10 13:43 ` Tassilo Horn
2009-03-10 20:59   ` Xah Lee
2009-03-10 22:01     ` W Dan Meyer
2009-03-10 20:06 ` Nikolaj Schumacher
2009-03-11 17:51   ` Johan Bockgård
     [not found] ` <mailman.2878.1237105097.31690.help-gnu-emacs@gnu.org>
2009-03-16 23:54   ` Xah Lee
2009-03-17  2:41     ` Xah Lee
2009-03-17  8:41     ` Nikolaj Schumacher
     [not found]     ` <mailman.3385.1237279326.31690.help-gnu-emacs@gnu.org>
2009-03-17  9:53       ` Xah Lee

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.