Monday, July 16, 2012

setting a "current file to compile and run", strange problem

Hi all,

i'm trying to set a "current file to set and run" :
when i use :make, i want this file to be compiled and run, instead of the file that i'm in.

For this, i've first used this which seems to work : 

"current file to compile and run must be the current one...
let $CURRENT_FILE_TO_RUN="%"
"...unless we choose the file that we are reading as the current file to compile and run
map ;f :let $CURRENT_FILE_TO_RUN=bufname('%')<CR>

This works well. The $CURRENT_FILE_TO_RUN variable echos what i want.

Then, i've used this, to effectively use this file name when i :make
autocmd FileType perl set makeprg=perl\ -cIlib\ $CURRENT_FILE_TO_RUN\ $*

I obtain a strange result.
Let's say i have a these two files :
C:/test.t

* Scenario 1 (the one that works) :
First, i open test.t in Vim. 
      at this moment, $CURRENT_FILE_TO_RUN is equal to %, and :make compiles test.t
Then, i press ;f
      this works well : now, i have $CURRENT_FILE_TO_RUN equal to C:/test.t
Then, i open C:/module.pm in the current buffer, with
:e C:/module.pm
which closes test.t
      Now, i still have $CURRENT_FILE_TO_RUN equal to C:/test.t
Finally, i press
:make
and things do what they should : 
perl -cIlib C:/test.t 
is executed, everything is how it should be.

* Scenario 2 (the one that doesn't work) :
in this scenario, instead of opening C:/module.pm in the same buffer as C:/test.t, 
i open it with
:vsplit C:/module.pm
which splits the window in two, and open C:/module.pm in the new opened buffer.
      Now, whether i'm in the module.pm buffer, or in the test.t buffer,
      $CURRENT_FILE_TO_RUN is equal to C:/test.t, which is good !
BUT then, when i type
:make
it's module.pm which get compiled ! With
perl -cIlib C:/module.pm

I really don't understand why, as my environment variable $CURRENT_FILE_TO_RUN is equal to C:/test.t,
and it worked in the first Scenario.

It looks extremely strange to me, but the answer might be obvious to someone who is more used to Vim, its variables and their scope.

Any idea ?

If someone had another implementation (or plugin) to achieve the same goal, i'd be interested too.

Cheers =)

pierre / mascip

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: