metapost indentation problem

23 views
Skip to first unread message

Peng Yu

unread,
Jul 31, 2007, 11:23:37 AM7/31/07
to vim_use
Hi,

There are some metapost indentation problems like the following (.mp
file). Can somebody let me fix them?

Thanks,
Peng

for i = 0 upto 3:
for j = 0 upto 3:
dotlabel ("", (i+.5,j+.5)*8*u);
endfor
endfor

def square(expr x, y, s) =
unitsquare scaled s shifted (x,y)
enddef;

def circle(expr x, y, r) =
fullcircle scaled (2*r) shifted (x,y)
enddef;

Zhaojun WU

unread,
Aug 1, 2007, 2:16:19 AM8/1/07
to vim...@googlegroups.com
Hi, Peng Yu,

I changed a bit of the codes in $VIMRUNTIME/indent/mp.vim to resolve
the indentation problem for nested "FOR". It seems to me that this
modification is working well for your problem. (you can download the
attached mp.vim to replace the original one after you make a backup of
it)

But, as a reminder, the original author mentioned that "First of all,
MetaPost language don't expect any identation rules." So that if you
want other indentation format, you'd better to DIY the mp.vim.

HTH,
--
Best,
Zhaojun (Joseph)

mp.vim

Peng Yu

unread,
Aug 1, 2007, 5:03:32 PM8/1/07
to vim_use

Thank you for your effort. I tried mp.vim and t works for "for". But
it becomes worse for "def". I would like to modify mp.vim by myself
when I have time. Could you please fix the indentation of "def" for
now?

Here is what I get.

def square(expr x, y, s) =
unitsquare scaled s shifted (x,y)
enddef;

def circle(expr x, y, r) =
fullcircle scaled (2*r) shifted (x,y)
enddef;

I want it to be

def square(expr x, y, s) =
unitsquare scaled s shifted (x,y)
enddef;

def circle(expr x, y, r) =
fullcircle scaled (2*r) shifted (x,y)
enddef;

Thanks,
Peng

Zhaojun WU

unread,
Aug 2, 2007, 3:02:48 AM8/2/07
to vim...@googlegroups.com
Hi, Peng Yu,

On 8/2/07, Peng Yu <Peng...@gmail.com> wrote:
> Thank you for your effort. I tried mp.vim and t works for "for". But
> it becomes worse for "def". I would like to modify mp.vim by myself
> when I have time. Could you please fix the indentation of "def" for
> now?
>
> Here is what I get.
>
> def square(expr x, y, s) =
> unitsquare scaled s shifted (x,y)
> enddef;
>
> def circle(expr x, y, r) =
> fullcircle scaled (2*r) shifted (x,y)
> enddef;
>

Actually, I have no any experience on metapost at all, but change the
mp.vim based on the intuition trained from other languages.

For the indentation problem for "def" and "enddef", a temporary
solution is: if possible and not violating the matepost's grammar,
please add a semicolon at the end of the line before "enddef", like:

def circle(expr x, y, r) =
fullcircle scaled (2*r) shifted (x,y);
enddef;

If you don't put a ";" at the end of one statement, the mp.vim will
treat the current line as a broken line and will indent forward twice
at the beginning of next line. Thus, even though you put "enddef" in
the new line, it will only indent backward once.

However, as I mentioned before, I don't know metapost much, so I am not sure if

"fullcircle scaled (2*r) shifted (x,y);"

is the same to:

"fullcircle scaled (2*r) shifted (x,y)"

in macro definition.

Another option is that, you just put all the macro definition in one
line, similar to those macro definition examples described in MetaPost
User Manual.

Sorry, I am not capable of rewriting the whole mp.vim because of my
zero knowledge of metapost.

Good luck!
--
Best,
Zhaojun (Joseph)

Abel Van

unread,
Jul 13, 2016, 11:12:13 AM7/13/16
to vim_use
在 2007年8月1日星期三 UTC+8下午2:16:19,Zhaojun WU写道:
I use mpgraphics.sty to include mp code into tex source. And I need to indent the following code correctly:
\begin{mpdisplay}
for i=1 upto 2:
show i;
endfor;
\end{mpdisplay}

Can you help me?
Reply all
Reply to author
Forward
0 new messages