MapTool Macros Vim Syntax Hilight/Completion/Doc

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Craig »

Updates 03-Jan-2008:
  • Code completion, hints, and syntax highlighting updated for b49
  • Fixed a few minor bugs.
Updates 25-Nov-2008:
  • The syntax highlighting/code completion/help is now more up to date it contains some (but not all of b47) additions.
  • Fixed case problem with linux
  • Added "syntax on" to recommended vimrc commands.
Note: If you were using the previous version and had set any of the variables mentioned in help that start with MTMacro# their case has changed to mtmacro# and you will need to update your vimrc to reflect this.

Just download the file from the link below and follow the steps again to update.
---------------------------------------------------------------------------------------

Here is take 2 of the MapTool Macro plugin for the vim editor.

The latest version of vim is recommended.
If you have an older version then you may need to install vimball
http://www.vim.org/scripts/script.php?script_id=1502

For Microsoft Windows you can download vim here
http://www.vim.org/download.php#pc
Download the self installing executable

For Linux you will already have vim.

For Mac OSX, vim is included but you should download a more recent version that also has a mac GUI from the following link (MacVim-7_2-stable-1_2.tbz)
http://code.google.com/p/macvim/downloads/list

  • <b>Features</b>
  • Syntax Highlighting.
  • Code Completion with parameters and function descriptions.
  • Function parameter hints.
  • Many mappings for reducing typing :)
  • Help Documentation.
If you are not used to vim/vi then you will find it is different to most editors and my take you a little time to get used to. You may want to read
vimbook-OPL.pdf
Vim also has very good documentation available through :help
Another book that you can download for free as a pdf or read online is available at http://www.swaroopch.com/notes/Vim. The book tends to jump around a bit but the start is useful for beginners.

Once you are comfortable with vim download the file
mtmacro.vba
and edit it with vim, then type in

Code: Select all

:source %
:q
This will install the plug in. The next step is to edit your vim configuration file, to do that then start vim.
In windows type

Code: Select all

: e! $HOME/_vimrc
Linux/Mac OSX

Code: Select all

:e! $HOME/.vimrc
Then add the following lines.

Code: Select all

filetype plugin on
syntax on
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
Save and quit

Code: Select all

:wq

Now when you edit a file that ends in .mtmacro or .mtm the plugin will be loaded. You can also use :set filetype=mtmacro to load in for a file you are editing.

Control-X Control-O is used for completion if you find this to be too awkward you can install the SuperTab plugin which will allow you to use tab for completion SuperTab

You can get help about the plugin with
:help mtmacro

There is also help available for all of the functions which you can get by typing
:help mtm-<function>()
e.g.
:help mtm-abs()
:help mtm-listAppend()


The help file and plugin contain the information for build 45, and what I know about patches that are in the works for a later build. Once build 46 comes out I will update the plugin for that (and I will try keep it up to
date, probably a day or 2 behind each release).

<b>Some Screen shots.</b>

Syntax Highlighting
gvimSyntax.png
gvimSyntax.png (59.73 KiB) Viewed 9247 times
Code Completion & Function Hints
gvimAuto.png
gvimAuto.png (62.04 KiB) Viewed 9247 times
Help
gvimHelp.png
gvimHelp.png (79.98 KiB) Viewed 9247 times
Edit - RPTroll 03/16/2015 - fixed dropbox download link. Added Az's modifications.
Last edited by Craig on Thu Jan 08, 2009 4:31 am, edited 3 times in total.

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Post by RPTroll »

Craig,

You are a gem of great value.

Thanks,
RPTroll

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Post by Full Bleed »

Would it be redundant to have a similar tool like this built into MT's macro editor?

I haven't tried it yet, but it seems pretty useful.

demonnic
Cave Troll
Posts: 53
Joined: Sun Sep 07, 2008 10:03 pm

Post by demonnic »

I tried the previous one, and it's been invaluable. If nothing else, the bracket-matching is great and helps avoid a lot of confusion in those particularly lengthy macros.

demonnic
Cave Troll
Posts: 53
Joined: Sun Sep 07, 2008 10:03 pm

Well...

Post by demonnic »

I'm receiving errors after having installed this... when loading an mtm/mtmacro file:

Error detected while processing /home/demonnic/.vim/ftplugin/mtmacro/hints.vim:
line 30:
E746: Function name does not match script file name: MTMacro#hints#DispHint
Error detected while processing /home/demonnic/.vim/ftplugin/mtmacro/mtmacro.vim
:
line 301:
E746: Function name does not match script file name: MTMacro#GetCompleteList
line 377:
E746: Function name does not match script file name: MTMacro#CompleteForFunction

line 395:
E746: Function name does not match script file name: MTMacro#CompleteForString
line 435:
E746: Function name does not match script file name: MTMacro#CompleteFunction
Press ENTER or type command to continue


Does this mean there are files which I'm missing? Or that the files are misnamed? I've been using vim for awhile, but never got into scripting it.

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: Well...

Post by Craig »

demonnic wrote:I'm receiving errors after having installed this... when loading an mtm/mtmacro file:

Error detected while processing /home/demonnic/.vim/ftplugin/mtmacro/hints.vim:
line 30:
E746: Function name does not match script file name: MTMacro#hints#DispHint
Error detected while processing /home/demonnic/.vim/ftplugin/mtmacro/mtmacro.vim
:
line 301:
E746: Function name does not match script file name: MTMacro#GetCompleteList
line 377:
E746: Function name does not match script file name: MTMacro#CompleteForFunction

line 395:
E746: Function name does not match script file name: MTMacro#CompleteForString
line 435:
E746: Function name does not match script file name: MTMacro#CompleteFunction
Press ENTER or type command to continue


Does this mean there are files which I'm missing? Or that the files are misnamed? I've been using vim for awhile, but never got into scripting it.
My bad in a moment of brain malfunction I used the incorrect case when naming the modules and tested it on windows/mac both of which have case insensitive file names. I have updated the vba file if you download it and follow the steps again it will correct the problem

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Azhrei »

Craig, any more work on adding other completion strings?

I'm sure I could do it myself if I had the motivation, but alas, I don't. :mrgreen: And I thought if you already had it...

It might be nice to find some way to extract the information from the code. Would the code format support such a thing?

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Craig »

Azhrei wrote:Craig, any more work on adding other completion strings?

I'm sure I could do it myself if I had the motivation, but alas, I don't. :mrgreen: And I thought if you already had it...

It might be nice to find some way to extract the information from the code. Would the code format support such a thing?
I am working on it, but its between a few things... The syntax highlighting has an issue with code: { } I need to fix, and a few more functions to add. (I don't want to thinking about the doco at the moment ;))

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Craig »

I have updated the Hints, Code Completion and Syntax highlighting to match b49. The doco is still behind, so you should probably check the wiki if you need more info than the hints and code completion give you.

User avatar
Ferdil
Cave Troll
Posts: 31
Joined: Wed Jan 07, 2009 1:27 pm

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Ferdil »

Can't get it to work. I edited my vimrc file, and I installed the plugin with :so %, but it doesn't even appear on the filetypes list.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Azhrei »

Cool. Thanks. :)

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Craig »

Ferdil wrote:Can't get it to work. I edited my vimrc file, and I installed the plugin with :so %, but it doesn't even appear on the filetypes list.
The filetypes list in the menu? This is because those are not generated at run time but at the time VIM is packaged.

You can test it is working by editing a file that ends with .mtmacro or you can in command mode use :set filetype=mtmacro

If you want to add it to the syntax->filetypes menu
edit the syntax menu file (usually something like vim/vim72/synmenu.vim, but you may have to use find files to find it)

about line 292 you will see

Code: Select all

an 50.60.470 &Syntax.L-Ma.Maple\ V :cal SetSyn("maple")<CR>
an 50.60.480 &Syntax.L-Ma.Mason :cal SetSyn("mason")<CR>
backup the file, then insert the following line

Code: Select all

an 50.60.475 &Syntax.L-Ma.MapTool\ Macro :cal SetSyn("mtmacro")<CR>
So you end up with

Code: Select all

an 50.60.470 &Syntax.L-Ma.Maple\ V :cal SetSyn("maple")<CR>
an 50.60.475 &Syntax.L-Ma.MapTool\ Macro :cal SetSyn("mtmacro")<CR>
an 50.60.480 &Syntax.L-Ma.Mason :cal SetSyn("mason")<CR>
I cant find a way to do this as part of an install of a new plugin.


Its up to you if you want to go through the effort, I will say this though I have been using vim for a long time (just thinking how long makes me feel old... :) ). And er the first time I ever used the syntax filetypes menu was um just now while testing this out :)

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Azhrei »

Yeah, since Vim will auto-detect the syntax type to use, you really don't need that menu except in weird cases. Just open/create a new file with the correct naming convention and life will be good. (Craig mentions .mtmacro but .mtm works as well.)

Craig, I still don't see how to get Vim to prompt me for the parameters to a function. Specifically, I'm thinking of input().

I know I can use ^X^O to get the completion list, and I can type \ to get some type of shortcut, but I can't make it do what I thought it was supposed to do, which is to lmove the cursor from parameter to parameter and give me hints along the way (the same way Eclipse does).

Took me awhile to figure out that the <LocalLeader> that appears in the help doc was referring to \, too!

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Craig »

Azhrei wrote:Yeah, since Vim will auto-detect the syntax type to use, you really don't need that menu except in weird cases. Just open/create a new file with the correct naming convention and life will be good. (Craig mentions .mtmacro but .mtm works as well.)

Craig, I still don't see how to get Vim to prompt me for the parameters to a function. Specifically, I'm thinking of input().

I know I can use ^X^O to get the completion list, and I can type \ to get some type of shortcut, but I can't make it do what I thought it was supposed to do, which is to lmove the cursor from parameter to parameter and give me hints along the way (the same way Eclipse does).
At the moment all you can get it to do put place holders in the code completion.
(from :help mtmacro)

OmniComplete Window
The default completion for the plugin will insert the function name but no parameters, for example
abs()
If you want the completion to add in place holders for the arguments when it does completion, such as
abs(number)
Then add the following line in your .vimrc
let g:mtmacro#InclParam=1



I would like to improve the code completion to have extra features, but thats a lot of work that I probably wont start until a feature freeze is declared for 1.3. Thats not to say that the code completion and and syntax highlighting as it stands is not useful.
Azhrei wrote: Took me awhile to figure out that the <LocalLeader> that appears in the help doc was referring to \, too!
Sorry about that I should change that to make it clearer.

User avatar
Ferdil
Cave Troll
Posts: 31
Joined: Wed Jan 07, 2009 1:27 pm

Re: MapTool Macros Vim Syntax Hilight/Completion/Doc

Post by Ferdil »

Craig wrote:
Ferdil wrote:Can't get it to work. I edited my vimrc file, and I installed the plugin with :so %, but it doesn't even appear on the filetypes list.
The filetypes list in the menu? This is because those are not generated at run time but at the time VIM is packaged.
Ah, ok, didn't know that (I tried the menu just because the plugin wasn't working), but even with the command :set filetype=mtmacro or opening a .mtm file doesn't work. It does not recognise the :help mtmacro command. It's like it's not installed. Maybe I did something wrong, I'm still quite a noob at vim.

P.S. I tried both on linux and on windows and it happens exactly the same thing. Maybe I'm doing something wrong?

Post Reply

Return to “Drop-In Macro Resources”