Monday, July 16, 2012

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

I've tried different combinations :
bufname("%") instead of bufname('%')
bufname(1)     instead of bufname('%')
and got exactly the same results, for Scenario 1 and 2, and for Scenario 3 (which is even more strange to me)
.

*Scenario 3:
if i first use ;f to set $CURRENT_FILE_TO_RUN to C:/test.t,
and ONLY THEN open module.pm with
:vsplit C:/module.pm
and put my cursor there, to make it the current buffer.
Then i get the result what i want :
when i type :make it is the test.t file which is compiled and run.

BUT as is said before, if i FIRST split the window
:vsplit C:/module.pm
and then set the $CURRENT_FILE_TO_RUN with
;f
Then, i get that the current file is compiled and run.


This would mean that when i have more than one buffer, 
the change of $CURRENT_FILE_TO_RUN is not really taken into account.
But when i "echo" it, it says what it should say.

I really don't understand why this order matters :
first :vsplit => it doesn't work
OR
first :let $CURRENT_FILE_TO_RUN=bufname("%") => it works

but in both case, $CURRENT_FILE_TO_RUN is equal to C:/test.t before i use :make.

I tried to set makrprg=echo\ $CURRENT_FILE_TO_RUN
but it didn't work : when i typed :make, it just printed echo\ $CURRENT_FILE_TO_RUN, not its value.

I don't have a clue what's going on...



On 17 July 2012 02:20, mascip <mascip@gmail.com> wrote:
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



--

mascip@gmail.com
http://lesrikikibians.fr

--
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:

Post a Comment