Problem of frequency call of func through --remote-expr

15 views
Skip to first unread message

epanda

unread,
Mar 20, 2010, 3:30:50 AM3/20/10
to vim_use
Hi,


I am using this command in order to retrieve data stored into c:/
infos.txt at regular interval back to GVim without disturbing main
GVim instance.

exec '!start /MIN cmd /c "vim --servername ' . v:servername . ' --
remote-expr "AnalysisCppInfos('."'c:/infos.txt'". ')"'

The problem is that the call of AnalysisCppInfos( happens only one
time.

I would like a call done each time an event occurs.
Event may be :
. each second
. each time the file is written
. etC..

I wonder why it is called only one time.

Thank you


Tony Mechelynck

unread,
Mar 20, 2010, 6:15:17 AM3/20/10
to vim...@googlegroups.com, epanda

To repetitively call something (in a Vim compiled with the +autocmd
feature), you may want to harness the CursorHold and/or CursorHoldI
event, which, in Normal mode or Insert mode respectively, will fire once
when 'updatetime' milliseconds (by default 4000) have passed since the
last time you pressed a key. Or (IIUC) you may call the feedkeys()
function from that autocommand in order to trigger it again.

Note that changing this option has a side-effect (which from a different
point of view is the main effect): the swapfile is written (if not yet
done since the last time the file was changed) at the same time the
autocommand fires.

Similarly, "each time the file is written" is the BufWrite event.
(BufWrite is an alias of BufWritePre, "just before writing the file".
There is also a BufWritePost event.)


Best regards,
Tony.
--
Character Density, n.:
The number of very weird people in the office.

epanda

unread,
Mar 20, 2010, 10:28:05 AM3/20/10
to vim_use

> To repetitively call something (in a Vim compiled with the +autocmd
> feature), you may want to harness the CursorHold and/or CursorHoldI

On the contrary, I search for an event out of user key.

idem for the feedkeys()

In fact a search for an exaplanation of this feature remote-expr.

Is is cycling ? or one shot ?
I am reading a file that is output by a first cmd.

Ben Fritz

unread,
Mar 22, 2010, 12:47:47 PM3/22/10
to vim_use

On Mar 20, 2:30 am, epanda <callingel...@hotmail.fr> wrote:
> Hi,
>
> I am using this command in order to retrieve data stored into c:/
> infos.txt at regular interval back to GVim without disturbing main
> GVim instance.
>
> exec '!start /MIN cmd /c "vim --servername ' . v:servername . ' --
> remote-expr "AnalysisCppInfos('."'c:/infos.txt'". ')"'
>
> The problem is that the call of AnalysisCppInfos( happens only one
> time.

Naturally. You only call it once. The :!start command is to call an
external command, A SINGLE TIME, in an asynchronous process.

>
> I would like a call done each time an event occurs.
> Event may be :
> . each second
> . each time the file is written
> . etC..
>
> I wonder why it is called only one time.
>

If you want it to run more than once, you will need to call in more
than once.

Message has been deleted

epanda

unread,
Mar 22, 2010, 4:14:10 PM3/22/10
to vim_use
Ok I have done this with cursorHold autocommand but it call only one
time too my func :

set updatetime=1000
let g:startTime = reltime()
au!
autocmd CursorHold * call s:AnalysisCppCheckInfos("c:/infos.txt")

function! s:AnalysisCppCheckInfos(temp_file_name)

echo "Temps écoulé " . reltimestr(reltime(g:startTime))

endfunc

I see only one time the message.

epanda

unread,
Mar 22, 2010, 4:25:52 PM3/22/10
to vim_use
hum in fact this work but I would like an event out of user action,
I thought cursorHold was when curso blink.

Which event can I use to call myFunc each constant time?

Ben Fritz

unread,
Mar 23, 2010, 10:59:47 AM3/23/10
to vim_use

There isn't one. The closest you can get is to use both CursorHold and
CursorMoved. See the :help entry for each. I believe I may have seen a
way to trick Vim into generating cursor movement with CursorHold, so
that CursorHold would fire repeatedly, but normally it just fires once
after the timeout period.

You may be better off making your EXTERNAL process run forever and
repeatedly call your function, as I suggested previously. You could do
this in a shell script/batch file/whatever you want.

epanda

unread,
Mar 23, 2010, 12:05:44 PM3/23/10
to vim_use
Ben I know your first idea which aim to add an external process to go
repeatedly call and I really think it will work.

But generaly, I apply my philosophy which consist of using less layer
as soon as possible.

I am already using vim which call and encapsulate cppcheck process, so
that's why I don't want to add another layer just to get repeat call.

I will see what I can do to not overheat CPU load while I using
cppcheck.

Thank you

Christian Brabandt

unread,
Mar 24, 2010, 5:48:47 AM3/24/10
to vim...@googlegroups.com
On Tue, March 23, 2010 3:59 pm, Ben Fritz wrote:
>
>
> On Mar 22, 3:25 pm, epanda <callingel...@hotmail.fr> wrote:
>> Which event can I use to call myFunc each constant time?
>
> There isn't one. The closest you can get is to use both CursorHold and
> CursorMoved. See the :help entry for each. I believe I may have seen a
> way to trick Vim into generating cursor movement with CursorHold, so
> that CursorHold would fire repeatedly, but normally it just fires once
> after the timeout period.

Yes, Simply call feedkeys in your autocommand and put in some key, that
won't hurt. Something like this may be:

fu! s:Run()
let k_refresh="\x0c" " this is ctrl-l
" Do whatever you want to be done here
echomsg strftime("%H:%M:%S ") . "Autocommand triggered"
call feedkeys(k_refresh, 't')
endfu

augroup RunContinuously
au!
au CursorHold * :call s:Run()
augroup end


I am not sure, how invasive this will be for the user, though.

regards,
Christian

bill lam

unread,
Mar 24, 2010, 6:51:36 AM3/24/10
to vim_use
mar, 23 Mar 2010, epanda skribis:

I think you should follow Ben's suggestion to get the job done first
and worry efficiency later.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

Ben Fritz

unread,
Mar 24, 2010, 11:59:44 AM3/24/10
to vim_use

On Mar 24, 4:48 am, "Christian Brabandt" <cbli...@256bit.org> wrote:
>
> Yes, Simply call feedkeys in your autocommand and put in some key, that
> won't hurt. Something like this may be:
>
> fu! s:Run()
>    let k_refresh="\x0c" " this is ctrl-l
>    " Do whatever you want to be done here
>    echomsg strftime("%H:%M:%S ") . "Autocommand triggered"
>    call feedkeys(k_refresh, 't')
> endfu
>
> augroup RunContinuously
>   au!
>   au CursorHold * :call s:Run()
> augroup end
>
> I am not sure, how invasive this will be for the user, though.
>

I think it would be pretty invasive. It will make not just the desired
script, but ALL CursorHold events, to fire without end. I imagine some
plugins rely on the fact that CursorHold only fires once after cursor
inactivity, though I don't know any specific ones. Most likely this
will only cause inefficiencies, doing work multiple times instead of
just once, but there might be cases where it actually screws things up.

epanda

unread,
Mar 24, 2010, 2:47:26 PM3/24/10
to vim_use
Hi Christian, it is invasive cause I cannot edit Text while my
cppcheck process is running BUT

It is a cool new func I have learned !!!

Meanwhile it is taking all resources, I use it.

Thanks

epanda

unread,
Mar 24, 2010, 2:52:35 PM3/24/10
to vim_use
Sorry for the bad precedent message :

Christian your solution is working perfectly.

I can writing into the buffer and use Gvim as I want while refresh of
cppcheck progression is done perfectly.

So Thank you , it is perfect.
Epanda

Reply all
Reply to author
Forward
0 new messages