Vim syntax highlighting for WML

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
ejls
Inactive Developer
Posts: 1
Joined: November 23rd, 2011, 6:54 pm
Location: Paris

Vim syntax highlighting for WML

Post by ejls »

Hi!

    I wrote a (basic) Vim syntax file for WML. It is far from perfect, but it is better than nothing. :)

Features
    Highlighting of:
  • Standard tags (copied from here)
    Vim WML example: highlighting of tags
    Vim WML example: highlighting of tags
    stdtag.png (3.51 KiB) Viewed 3134 times
  • Lua
    Vim WML example: highlighting of lua
    Vim WML example: highlighting of lua
    lua.png (2.46 KiB) Viewed 3134 times
  • Formula (basic)
    Vim WML example: highlighting of formula
    Vim WML example: highlighting of formula
    formula.png (1.66 KiB) Viewed 3134 times
  • Syntax error (basic)
    Vim WML example: highlighting of errors
    Vim WML example: highlighting of errors
    error.png (1.92 KiB) Viewed 3134 times
    Sadly, the WML schema project seems abandoned, it would have allowed the recognition of valid keys/tags inside the corresponding parent tag. That is why, I have not included highlighting of standard keys since they would always be highlighted.

Install
  • Download vim-wml.tar.gz
  • Extract it in your vim syntax directory
    On Linux/Unix:

    Code: Select all

    $ mkdir -p ~/.vim/syntax && tar xzvf vim-wml.tar.gz -C ~/.vim/syntax
  • You can enable wml highlighting for the current buffer by typing :set syn=wesml
    To enable it automatically for all .cfg files add the following line to your .vimrc:

    Code: Select all

    au BufNewFile,BufRead *.cfg setf wesml
Notes
    Even if there already exist a syntax highlighting for .cfg files, it is very generic, I tried to match WML syntax more closely. Since the name wml is already taken (Website MetaLanguage), I named the syntax file wesml.
    The most recent version of lua.vim (Vim syntax file for Lua) is using TOP everywhere, this cause some bugs with the definition of Lua blocks. To fix this, I included a file named wmllua.vim which is a 2006 version of lua.vim. This version of Lua highlighting is only for Lua 4.0 to Lua 5.1. Since r52914, Lua 5.2 is included in Wesnoth so the highlighting is not perfect. You may try your local lua.vim file by editing wesml.vim (read the comment before the syn include line).
    Lua code is highlighted only when it is in a String value with the key "code" (even outside a [lua] tag) and when it is the sole attribute of the line. The highlighting of "" in double quoted string, variable ($...|) and formula ($(...)) is rarely (read never) working in Lua code. There is certainly others bugs… I let you hunt them. :)
    I am not a Vim syntax wizard, my goal was to make a (more or less) working syntax file, so the code is not very elegant. However, the file is under 3-clause BSD license, so do not hesitate to improve it. If you have any remark or problem, please let me know (here or on IRC).

    I suppose Vim is not widely used across UMC author, but I hope this will be useful to some of you. :)
Attachments
vim-wml.tar.gz
Vim syntax highlight for WML
(7.15 KiB) Downloaded 285 times
Pardon my English.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Vim syntax highlighting for WML

Post by Sapient »

I have been using vim so this will be very nice. Thank you!
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
AI
Developer
Posts: 2394
Joined: January 31st, 2008, 8:38 pm

Re: Vim syntax highlighting for WML

Post by AI »

I'm having trouble with the autocmd setf, here's part of my .vimrc:

Code: Select all

augroup vimrc_autocmds
    au!
    au BufNewFile,BufRead *.cfg setf wesml
    au BufNewFile,BufRead *.cfg echo "setf wesml"
augroup END
The echo happens, regardless of the order of the two au lines. Using :setf wesml or :set syn=wesml after vim has started also works, but the automatic setf doesn't seem to do anything.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Vim syntax highlighting for WML

Post by Sapient »

maybe it is setting it correctly but then something later is setting it to a different value
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
flixx
Inactive Developer
Posts: 3
Joined: April 11th, 2013, 6:24 pm

Re: Vim syntax highlighting for WML

Post by flixx »

Code: Select all

au BufRead,BufNewFile *.cfg set syn=wesml
works for me.
Thank you ejls!
fabi
Inactive Developer
Posts: 1254
Joined: March 21st, 2004, 2:42 pm
Location: Germany

Re: Vim syntax highlighting for WML

Post by fabi »

Please commit it to data/tools.
Hopefully it will not fight with the emacs mode there :-)
AI
Developer
Posts: 2394
Joined: January 31st, 2008, 8:38 pm

Re: Vim syntax highlighting for WML

Post by AI »

It works for me now, so I've committed it.
Post Reply