leo aware vim syntax highlighting

31 views
Skip to first unread message

Matt Wilkie

unread,
Dec 2, 2010, 5:25:33 AM12/2/10
to leo-e...@googlegroups.com
Hi All,

I've taken a crack at creating a syntax file for vim which demphasizes
Leo's metadata chatter without detracting (much) from the information
contained in the headline comments. It's crude but effective. I could
use help with tuning the pattern match expressions (for example html
files aren't working, though they were a few hours ago), see comments.

Save the attached filetype.vim in ~/.vim/after/ (linux) or
%userprofile%\_vim\after\ (windows, going from memory). It's not
necessary to restart vim, thought you do need to switch to another
file (buffer) and back again to force a refresh.

cheers,

--
-matt

vim-leo-filetype.png
filetype.vim

Edward K. Ream

unread,
Dec 4, 2010, 9:25:53 AM12/4/10
to leo-e...@googlegroups.com
On Thu, Dec 2, 2010 at 4:25 AM, Matt Wilkie <map...@gmail.com> wrote:
> Hi All,
>
> I've taken a crack at creating a syntax file for vim which demphasizes
> Leo's metadata chatter without detracting (much) from the information
> contained in the headline comments.

Many thanks for this work. I have long dreamed of something like
this. I had thought that it would be good to have emacs or vim simply
not show sentinels, but now I'm not so sure. Your way is brilliantly
simple, and in some ways is superior to hiding sentinels completely.

This is great work. Thanks for doing it.

Edward

Matt Wilkie

unread,
Dec 4, 2010, 5:22:47 PM12/4/10
to leo-e...@googlegroups.com
Thank you for the kind words Edward.
I guess sometimes it helps to be a newbie,
"simple" is all I could figure out. ;-)

After more hours troubleshooting than I care to think about, I've
finally managed to get branch pushed to Launchpad for this:
http://bazaar.launchpad.net/~maphew/leo-editor/stuff/files

cheers,

-matt

> --
> You received this message because you are subscribed to the Google Groups "leo-editor" group.
> To post to this group, send email to leo-e...@googlegroups.com.
> To unsubscribe from this group, send email to leo-editor+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.
>
>

--
-matt

Ville M. Vainio

unread,
Dec 5, 2010, 5:25:57 AM12/5/10
to leo-e...@googlegroups.com
On Sun, Dec 5, 2010 at 12:22 AM, Matt Wilkie <map...@gmail.com> wrote:

> After more hours troubleshooting than I care to think about, I've
> finally managed to get branch pushed to Launchpad for this:
> http://bazaar.launchpad.net/~maphew/leo-editor/stuff/files

Why not put it to the "contrib" branch?

--
Ville M. Vainio @@ Forum Nokia

Matt Wilkie

unread,
Dec 5, 2010, 7:27:48 PM12/5/10
to leo-e...@googlegroups.com
> Why not put it to the "contrib" branch?

because "You cannot upload to this branch. Members of The Leo editor
team can upload to this branch." :)

-matt

Offray Vladimir Luna Cárdenas

unread,
Dec 9, 2010, 4:18:00 PM12/9/10
to leo-e...@googlegroups.com
Hi Matt,

El 02/12/10 05:25, Matt Wilkie escribi�:

I'm just curious about this deemphasizing. How you see the normal
comments in python versus the comments of Leo metadata inside this
Python file. For example if we have:

# This is a test file of python that has some commented code
#@<leo-metadata>

This two lines should be seen different in vim using your syntax file?

Cheers,

Offray

Matt Wilkie

unread,
Dec 12, 2010, 3:04:17 AM12/12/10
to leo-e...@googlegroups.com
> I'm just curious about this deemphasizing. How you see the normal comments
>  in python versus the comments of Leo metadata inside this Python file. For
> example if we have:
>
> # This is a test file of python that has some commented code
> #@<leo-metadata>
>
> This two lines should be seen different in vim using your syntax file?

Yes that's right, the two lines are treated differently. Basically the
syntax file scans for any occurrence of "@@" or "@+" or "@-" within
the first 5 characters of a Comment line. If found the line is called
a "leoSentinel" and changed to lightgrey. Each leoSentinel line is
further scanned for the right most asterisk "*", and the contents to
the right of that revert back to the normal Comment colour.

That's the theory anyway. For some reason it doesn't work with html
files, though it did at an earlier point in my experiments. A new
update is forthcoming which should make it a little more reliable.

cheers,

-matt

Matt Wilkie

unread,
Dec 12, 2010, 4:59:42 AM12/12/10
to leo-e...@googlegroups.com
> That's the theory anyway. For some reason it doesn't work with html
> files, though it did at an earlier point in my experiments. A new
> update is forthcoming which should make it a little more reliable.

A new version (r7) has been uploaded to
https://code.launchpad.net/~maphew/leo-editor/stuff. Changes:

- two files are now needed, both in ~/.vim/after. Previously the
highlighting was working ing Cream+gvim but not stock (g)vim. Now it
works for (g)vim (and is broken in Cream, *sigh*, but much as I like
Cream, it's not the primary target).

- Leo sentinel regex now looks in all defined syntax names not just
comments to identify a sentinel line. This will make the addon easier
to maintain. Previously one would have to add "xxxComment" every time
a new language syntax was added.

It's possible this change will have a performance impact on very large
files or slow machines. My test workstation is fairly old though and I
noticed no difference.


--
-matt

Matt Wilkie

unread,
Feb 8, 2011, 10:23:00 AM2/8/11
to leo-e...@googlegroups.com
> A new version (r7) has been uploaded to
> https://code.launchpad.net/~maphew/leo-editor/stuff.

Now merged with lp:~leo-editor-team/leo-editor/contrib. This is the
first time I've merged branches, so may have not done it correctly,
please vet.

cheers,

--
-matt

Edward K. Ream

unread,
Feb 8, 2011, 10:54:11 AM2/8/11
to leo-e...@googlegroups.com

The .leo file loads correctly, so all looks good. It would be cleaner
if the .leo file were in the vim-syntax folder...

Edward

Matt Wilkie

unread,
Feb 8, 2011, 1:14:52 PM2/8/11
to leo-e...@googlegroups.com
> The .leo file loads correctly, so all looks good.  It would be cleaner
> if the .leo file were in the vim-syntax folder...

done.

I also found and fixed a serious mistake that caused data loss: I was
using clones and @file nodes to mirror the vim syntax files from the
project working directory to the vim profile directory. This appeared
to work just fine... until I started using the same setup on multiple
computers.

My workflow is (supposed to be) pull changes from bzr or dropbox to
the working dir, open the .leo file, do stuff, then save, which
mirrors changes from working to $home/vim/after/. However it turns out
what *actually* happens is that the most recently read @file wins,
updating the clones in the other @file nodes. So each time I switched
computers the older vim profile syntax files, which are later in the
outline tree, were overwriting the new work. (It's good to know I
wasn't just imagining making the same changes over and over!)

The fix is to use @file nodes for the code files and @auto nodes for
the one-way mirror files, now committed in r6.

I'd have cottoned on to the real problem sooner if I hadn't ignored
the recovered nodes tree Leo created. I thought I was just seeing this
bug[1] again so didn't pay attention, once again proving the adage
that assumptions make an ass of u and me, though mostly just me ;-)

[1] https://bugs.launchpad.net/leo-editor/+bug/683867

cheers,

--
-matt

Reply all
Reply to author
Forward
0 new messages