* syntax table entries for comments
@ 2003-09-08 5:39 Arjan Bos
2003-09-09 13:34 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Arjan Bos @ 2003-09-08 5:39 UTC (permalink / raw)
Hi all,
First of, many thanks to those who answered my question about info for
major-mode writers. The mode tutorial on emacs wiki was most
enlightning. In fact it was so helpful, that I decided to completely
rewrite the major-mode for NetRexx. When it's done I'll post it in
gnu.emacs.sources.
But before that can happen, I'll need some clues. NetRexx is a
programming language that contains two types of comments. The first is
for large blocks and is the familiar /* */ construction. This I can do
by looking at the examples. The second one is a single-line comment that
consists of two hyphens, like:
-- this is a comment.
Based on the major mode tutorial I did put the following code in:
(defvar nrx-mode-syntax-table nil
"Syntax table in use in NRX-mode buffers.")
(defun nrx-create-syntax-table ()
(if nrx-mode-syntax-table
()
(setq nrx-mode-syntax-table (make-syntax-table))
(modify-syntax-entry ?. "." nrx-mode-syntax-table)
(modify-syntax-entry ?- ". 12b" nrx-mode-syntax-table)
(modify-syntax-entry ?/ ". 14" nrx-mode-syntax-table)
(modify-syntax-entry ?* ". 23" nrx-mode-syntax-table)
(modify-syntax-entry ?\n "> b" nrx-mode-syntax-table)
(modify-syntax-entry ?\' "\"" nrx-mode-syntax-table))
(set-syntax-table nrx-mode-syntax-table))
This works but also renders the combination -* and *- as comment start
and end, which is wrong. Could anyone please tell me what I'm missing?
TIA,
Arjan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax table entries for comments
2003-09-08 5:39 syntax table entries for comments Arjan Bos
@ 2003-09-09 13:34 ` Stefan Monnier
2003-09-10 13:35 ` Arjan Bos
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2003-09-09 13:34 UTC (permalink / raw)
> language that contains two types of comments. The first is for large blocks
> and is the familiar /* */ construction. This I can do by looking at the
> examples. The second one is a single-line comment that consists of two
> hyphens, like:
> -- this is a comment.
Emacs does not properly support this, as you've discovered.
> (defvar nrx-mode-syntax-table nil
> "Syntax table in use in NRX-mode buffers.")
> (defun nrx-create-syntax-table ()
> (if nrx-mode-syntax-table
> ()
> (setq nrx-mode-syntax-table (make-syntax-table))
> (modify-syntax-entry ?. "." nrx-mode-syntax-table)
> (modify-syntax-entry ?- ". 12b" nrx-mode-syntax-table)
> (modify-syntax-entry ?/ ". 14" nrx-mode-syntax-table)
> (modify-syntax-entry ?* ". 23" nrx-mode-syntax-table)
> (modify-syntax-entry ?\n "> b" nrx-mode-syntax-table)
> (modify-syntax-entry ?\' "\"" nrx-mode-syntax-table))
> (set-syntax-table nrx-mode-syntax-table))
Could you tell me the place from which this code was inspired so we can
fix it ? It should look like:
(defvar nrx-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ...)
(modify-syntax-entry ...)
...
st))
and the `set-syntax-table' is commonly done implicitly by
`define-derived-mode'.
> This works but also renders the combination -* and *- as comment start and
> end, which is wrong. Could anyone please tell me what I'm missing?
Nothing, really, other than the fact that it's a limitation of current
syntax-tables. You can either hack on src/syntax.c to add support for
such cases, or use font-lock-syntactic-keywords to recognize `--'
and mark it as a comment starter.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax table entries for comments
2003-09-09 13:34 ` Stefan Monnier
@ 2003-09-10 13:35 ` Arjan Bos
2003-09-10 15:04 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Arjan Bos @ 2003-09-10 13:35 UTC (permalink / raw)
Cc: monnier
Stefan Monnier wrote:
>> The second one is a single-line comment that consists of two
>>hyphens, like:
>> -- this is a comment.
>
>
> Emacs does not properly support this, as you've discovered.
To bad. At least I won't have to look for it in the docs anymore.
>
>
>>(defvar nrx-mode-syntax-table nil
>> "Syntax table in use in NRX-mode buffers.")
>
>
>>(defun nrx-create-syntax-table ()
>> (if nrx-mode-syntax-table
>> ()
>> (setq nrx-mode-syntax-table (make-syntax-table))
>> (modify-syntax-entry ?. "." nrx-mode-syntax-table)
>> (modify-syntax-entry ?- ". 12b" nrx-mode-syntax-table)
>> (modify-syntax-entry ?/ ". 14" nrx-mode-syntax-table)
>> (modify-syntax-entry ?* ". 23" nrx-mode-syntax-table)
>> (modify-syntax-entry ?\n "> b" nrx-mode-syntax-table)
>> (modify-syntax-entry ?\' "\"" nrx-mode-syntax-table))
>
>
>> (set-syntax-table nrx-mode-syntax-table))
>
>
> Could you tell me the place from which this code was inspired so we can
> fix it ? It should look like:
>
> (defvar nrx-mode-syntax-table
> (let ((st (make-syntax-table)))
> (modify-syntax-entry ...)
> (modify-syntax-entry ...)
> ...
> st))
>
> and the `set-syntax-table' is commonly done implicitly by
> `define-derived-mode'.
I found it via Emacs Wiki. On page
http://www.emacswiki.org/cgi-bin/wiki/ModeTutorial, they link to the
following mode tutorial:
http://two-wugs.net/emacs/mode-tutorial.html
which I followed and used as an inspiration.
Could you please enlighten me as to why your way is better? I'm no
(e)lisp expert, but I'm doing allright with a bit of voodoo programming[1].
>
>
>>This works but also renders the combination -* and *- as comment start and
>>end, which is wrong. Could anyone please tell me what I'm missing?
>
>
> Nothing, really, other than the fact that it's a limitation of current
> syntax-tables. You can either hack on src/syntax.c to add support for
> such cases, or use font-lock-syntactic-keywords to recognize `--'
> and mark it as a comment starter.
I tried the latter, but then strings within the `--' comment will undo
the comment highlighting. So I'll try to voodoo hack src/syntax.c
Thanks a lot,
Arjan Bos
[1] voodoo programming: Change something and see if it works. Keep on
changing things until it does what you want.
This way I can change most sources with only a minimum of knowledge
about the language it's written in, by repeating the constructs already
used. Downside is of course that you don't learn new language
constructs. ;-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax table entries for comments
2003-09-10 13:35 ` Arjan Bos
@ 2003-09-10 15:04 ` Stefan Monnier
2003-09-11 5:48 ` Arjan Bos
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2003-09-10 15:04 UTC (permalink / raw)
>>> (defvar nrx-mode-syntax-table nil
>>> "Syntax table in use in NRX-mode buffers.")
>>
>>> (defun nrx-create-syntax-table ()
>>> (if nrx-mode-syntax-table
>>> ()
>>> (setq nrx-mode-syntax-table (make-syntax-table))
>>> (modify-syntax-entry ?. "." nrx-mode-syntax-table)
>>> (modify-syntax-entry ?- ". 12b" nrx-mode-syntax-table)
>>> (modify-syntax-entry ?/ ". 14" nrx-mode-syntax-table)
>>> (modify-syntax-entry ?* ". 23" nrx-mode-syntax-table)
>>> (modify-syntax-entry ?\n "> b" nrx-mode-syntax-table)
>>> (modify-syntax-entry ?\' "\"" nrx-mode-syntax-table))
>>
>>> (set-syntax-table nrx-mode-syntax-table))
>> Could you tell me the place from which this code was inspired so we can
>> fix it ? It should look like:
>> (defvar nrx-mode-syntax-table
>> (let ((st (make-syntax-table)))
>> (modify-syntax-entry ...)
>> (modify-syntax-entry ...)
>> ...
>> st))
>> and the `set-syntax-table' is commonly done implicitly by
>> `define-derived-mode'.
> I found it via Emacs Wiki. On page
> http://www.emacswiki.org/cgi-bin/wiki/ModeTutorial, they link to the
> following mode tutorial:
> http://two-wugs.net/emacs/mode-tutorial.html
> which I followed and used as an inspiration.
> Could you please enlighten me as to why your way is better? I'm no (e)lisp
> expert, but I'm doing allright with a bit of voodoo programming[1].
Advantages are:
- shorter.
- less memory used since the code that sets up the table can be discarded
after the table is setup, whereas in your case, the function
nrx-create-syntax-table needs to be kept around in case someone wants
to call it.
- no temporary stage where nrx-mode-syntax-table holds a value that is
not a syntax-table (or that is a syntax-table but that is not yet
properly initialized): either it's there and initialized or it's not
there at all.
>>> This works but also renders the combination -* and *- as comment start and
>>> end, which is wrong. Could anyone please tell me what I'm missing?
>> Nothing, really, other than the fact that it's a limitation of current
>> syntax-tables. You can either hack on src/syntax.c to add support for
>> such cases, or use font-lock-syntactic-keywords to recognize `--'
>> and mark it as a comment starter.
> I tried the latter, but then strings within the `--' comment will undo the
> comment highlighting.
I suspect you used font-lock-keywords rather than
font-lock-syntactic-keywords.
> So I'll try to voodoo hack src/syntax.c
That would be wonderful.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: syntax table entries for comments
2003-09-10 15:04 ` Stefan Monnier
@ 2003-09-11 5:48 ` Arjan Bos
0 siblings, 0 replies; 5+ messages in thread
From: Arjan Bos @ 2003-09-11 5:48 UTC (permalink / raw)
Stefan Monnier wrote:
<snip>code snippet</snip>
>>Could you please enlighten me as to why your way is better? I'm no (e)lisp
>>expert, but I'm doing allright with a bit of voodoo programming[1].
>
>
> Advantages are:
> - shorter.
> - less memory used since the code that sets up the table can be discarded
> after the table is setup, whereas in your case, the function
> nrx-create-syntax-table needs to be kept around in case someone wants
> to call it.
> - no temporary stage where nrx-mode-syntax-table holds a value that is
> not a syntax-table (or that is a syntax-table but that is not yet
> properly initialized): either it's there and initialized or it's not
> there at all.
Sounds good to me, thanks!
>
>
<snip/>
>>
>>I tried the latter, but then strings within the `--' comment will undo the
>>comment highlighting.
>
>
> I suspect you used font-lock-keywords rather than
> font-lock-syntactic-keywords.
You're right, I'll look up the docs for that then.
>
>
>>So I'll try to voodoo hack src/syntax.c
>
>
> That would be wonderful.
>
Don't get your hopes up to high yet. The amount of constants in syntax.c
and my lack of c knowlegde will make this hard. (Were it COBOL though...
:-). I do happen to have a fairly recent CVS snapshot though, so I'll
try it.
Arjan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-09-11 5:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-08 5:39 syntax table entries for comments Arjan Bos
2003-09-09 13:34 ` Stefan Monnier
2003-09-10 13:35 ` Arjan Bos
2003-09-10 15:04 ` Stefan Monnier
2003-09-11 5:48 ` Arjan Bos
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).