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

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

Re: How to make font lock work with comments?


From: Tim X
Subject: Re: How to make font lock work with comments?
Date: Fri, 31 Dec 2010 08:27:38 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Elena <egarrulo@gmail.com> writes:

> On Dec 29, 9:50 am, rusi <rustompm...@gmail.com> wrote:
>> Im hacking on an apl mode
>>
>>  (let ((st (make-syntax-table))
>>         (comment-char ?\x235d))
>> :
>> :
>>  (modify-syntax-entry comment-char "<" st)
>>
>> This char shows as follows (Dont know if it shows elsewhere..)
>>
>> ⍝ A comment
>>
>> When I put point on the char and call describe-char I get
>>
>> ---------------------------------
>>         character: ⍝ (9053, #o21535, #x235d)
>> preferred charset: unicode (Unicode (ISO10646))
>>        code point: 0x235D
>>            syntax: <         which means: comment
>>          category: .:Base
>>          to input: type "{upshoe-jot}" or "{lamp}" or "{comment}" or
>> "{@}" with apl-ascii
>>       buffer code: #xE2 #x8D #x9D
>>         file code: not encodable by coding system iso-latin-1-unix
>>           display: by this font (glyph code)
>>     xft:-unknown-unifont-normal-normal-normal-*-12-*-*-*-d-0-
>> iso10646-1 (#x2359)
>> ------------------------------
>>
>> In other words emacs sees this as a comment-type char (similar to what
>> it says for semicolon in elisp buffers
>>
>> And yet in an elisp buffer the ; to EOL is red
>> but here it is not.
>>
>> Any clues?
>
> Syntax and font-locking are two different things and are handled
> separately.  Commands look at syntax, humans look at font-locking.
>
> Try typing the string ";" (quotes included) into an Elisp buffer and
> then calling `describe-char' on the semicolon: Emacs will tell you the
> semicolon is a comment char, yet it will be highlighting it as string.
>
> Check out `font-lock-add-keywords'.

The two are not as seperate as implied. The font-lock system can/does
use the syntax table, primarily for comments and strings. See the
section Syntactic Font Lock in the elisp manual (section 23.6.8).

Also note that the development version of Emacs has some changes in this
area i.e. from the NEWS file

,----
| ** New variable syntax-propertize-function to set syntax-table properties.
| Replaces font-lock-syntactic-keywords which are now obsolete.
| This allows syntax-table properties to be set independently from font-lock:
| just call syntax-propertize to make sure the text is propertized.
| Together with this new variable come a new hook
| syntax-propertize-extend-region-functions, as well as two helper functions:
| syntax-propertize-via-font-lock to reuse old font-lock-syntactic-keywords
| as-is; and syntax-propertize-rules which provides a new way to specify
| syntactic rules.
`----

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

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