ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Mojca Miklavec <mojca.miklavec.lists@gmail.com>
Subject: Re: TeX + Metapost syntax highlighting in Vim
Date: Tue, 12 Jul 2005 15:38:39 +0200	[thread overview]
Message-ID: <6faad9f00507120638824a479@mail.gmail.com> (raw)
In-Reply-To: <20050708213205.GB5397@puritan.pnetwork>

Nikolai Weibull wrote:

> I don't want to be a party-pooper, but I have already commited support
> for the context file-type to vim7 CVS.  Perhaps you can look over my
> version and make suggestions?

That's great! I didn't know that. Some time ago some people were
asking about ConTeXt support for vim, but I don't remember any
responses.

I like the "contains=@NoSpell" syntax and there are much more
highlights in your code.

Quite some pieces of code can still be added of course, but writing a
good syntax highlighting scheme may become almost as is almost as
tricky as writing a compiler for it :)

\title, \subject, ... can be added
Maybe some more extensive support for math as well ...

> It doesn't use the rather bloated LaTeX/Plain TeX syntax definition,
> but my own blend,

Probably the opinions on what "bloated" means differ at that point. I
find it very useful if wrong brackets or any other suspicious code is
marked as an error before the compiler has to tell me that (and for an
unexperienced user it is very difficult to find such a mistake from
compiler messages). I'm very glad that your code got rid of LaTeX
commands, but I find it great if we keep extending the code.

Moreover, I even wanted to have command-specific code highlighting.
ConTeXt has a big advantage over LaTeX: the central development. So
theoretically it would be possible to highlight any known command
different as the unknown (user-defined or misspelled) ones. PostScript
syntax highlighting script in vim does exactly that for example.

I wanted to suggest to make a cont-en.vim (cont-nl.vim, ..., maybe
also tex-plain.vim) file with all the known ConTeXt commands. I don't
know vim that well. I can imagine that this would cause some problems
on slower machines, but including it would only be left as an option.

> (Sorry for responding to two separate mails, I'm a bit rushed, going on
> a three-day holiday.)
> 
> Hans Hagen wrote:
> 
> > Mojca Miklavec wrote:
> 
> > > If you have something like
> > > \startMPpage
> > > draw ...
> > > \stopMPpage,
> > > it will do the syntax highligting for metapost inside the \start-\stop
> > > pair.
> 
> That's a great idea, I'll add that to my version

I made some corrections to it (off-list), but it is still far away
from being perfect. If you know how to correct some pecculiarities
mentioned in the comments, please do so and then adapt the code to fit
into your highlighting script.

It would be great if someone could give some hints about which
commands switch the mode of typesetting:

- startformula ... \stopformula
- startbuffer ... \stopbuffer (I would highlight the content for
"buffer" as a string)
- \start???MP??? ...\stop???MP???
- start???XML??? ... \stop???XML???

> Version 7 has a spell-checker built in.

I noticed that. But I suppose I'll wait for an official version of Vim
to come out. "contains=@NoSpell" should probably also be added to
mp.vim and mf.vim.

> > > I was astonished as I saw autocomplete work. There are only a couple of
> > > lines with an extraordinary functionality. I think that if someone
> > > writes a good script to convert texshow to vim syntax highlighting
> > > script, than autocomplete will be able to provide good hints for all the
> > > existing commands in ConTeXt and the corresponding parameters. I'll try
> > > to see what I can do, but please don't excpect any results too soon.
> 
> There's always the ever-simple CTRL-P/CTRL-N as well.

I just noticed that autocomplete is in no way as clever as
syntax-highlighting is. It would be great if there would exist a
similar support as the one for Java in Eclipse (only the keywords that
make sense in the current context are offered for autocompletion). An
example would be: if someone writes
    \adaptlayout[<ctrl-something>
only the options height= and lines= would be offered.
But at that point I have to answer to myself: "dream on!" It is
probably possible, but too complex at this moment.

> > What is the syntax? I can exten ctstools to spit out a vim keyword table;
> > it already handles scite, jedit and bbedit so adding vim is not undoable
> 
> Download vim and run :help syntax.  But the short version is
> 
> syn keyword contextKeyword  ...
>             ^-- group name  ^-- keywords
> 
> But that won't work for stuff beginning with \\.  Then you'll have to
> use regexes and
> 
> syn match   contextKeyword  ...
>                             ^-- regex
> 
> Exactly what kind of keyword table are we talking about?,

My most optimistic version: [all] of the commands defined in ConTeXt
(see also the comments above), together with some additional checking
if \start-s have their corresponding \stop-s and if parameters in the
brackets are applicable for the command they belong too.
    \adaptlayout[lines=30,somestupidparameter=1]
would thus highlight the valid "lines=" different from "somestupidparameter=1"
    \setupblackrules[alternative=c]
would mark "c" as invalid (only a and b are possible).

And already the first obstacle I came across: How can I define a
regexp matching the
    [ ... ]
area? Note that \firstcommand[ command={\secondcommand[x]}, text=$]$ ]

Quite some work to do ... but perhaps doable one day unless Vim is too
slow to process all that. No other highlighting script is as huge is
this one would be.


The first and most primitive step towards this is (as Nikolai wrote)
simply listing:
syn match   contextKeyword  ...
                            ^-- regex
for every ConTeXt command.
mf.vim and mp.vim are both defined that way. They only highlight the
keywords, they don't care about the syntax.

Mojca

  reply	other threads:[~2005-07-12 13:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-08 16:10 Mojca Miklavec
2005-07-08 17:48 ` Thomas A. Schmitz
2005-07-08 22:14   ` VnPenguin
2005-07-14 14:50   ` Christopher Creutzig
2005-07-14 16:16     ` Thomas A. Schmitz
2005-07-08 17:53 ` Hans Hagen
2005-07-08 21:32   ` Nikolai Weibull
2005-07-12 13:38     ` Mojca Miklavec [this message]
2005-07-08 21:28 ` Nikolai Weibull
2005-07-14 19:19   ` VnPenguin
2005-07-15 16:01     ` Nikolai Weibull
2005-09-24 21:41     ` Nikolai Weibull

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6faad9f00507120638824a479@mail.gmail.com \
    --to=mojca.miklavec.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).