Feature request: IMPORTANT and SIMPLE feature to improve Vim!

6 views
Skip to first unread message
Message has been deleted
Message has been deleted

StarWing

unread,
Jan 10, 2009, 2:22:32 PM1/10/09
to vim_use
i have thinked for a long time, and make it more confortable. just
save it in a file, and open with Vim. something changed in this
version.

okay, i used Vim for years, and I really really love her. i'm a
script-writer, so i want to create everything with vim-script, it's
wonderful, i know, but need improved. i think add these feature are
very simple(i will give the reason), and these can make a revolution
to script-writer!! it's worth to read it, i swear. just take you
several minutes.

1. interaction with other application

yes, the first big problem!! Vim has Unix-traditional isn't it? so it
should have the philosophy Unix have: just mix tools for you, not a
stiffness program. now Vim CAN interaction with other program, yes,
through interface of perl, python, ruby, tcl, netbeans, etc. i know.
but i haven't study neither of above, and use C will lost portable.
let's face the readlity: why not afford a interface in the Vim-script?
it not hard, because we always have|cscope_connection()|function.
just add some bulit-in function below:

*interaction*
*executable()*
executable({expr})
yes! we just have this function yet!! |executable()|

*isconnect()*
isconnect({expr})
this function return whether a program has connected to
program. it can replace|cscope_connection()|. if {expr} is
a number, it's the|pid|of program, and if it's a string,
it's the name of program.

example: check whether Vim connected to cscope >
:call isconnect("cscope")
<
*connect()*
connect({expr})
connect Vim and a program, that is, Vim run it, and if it
wait for input, let it wait, untill kill it or give it
input it want. this function return the pid of program
returned. {expr} use for string, it's the name of program
to run, program must be in $PATH.

example: connect Vim with gdb >
:let gdb_pid = connect('gdb -q')
:ec "Connect GDB pid=" . gdb_pid
<

*kill()*
kill({expr}[, {sid}])
to kill a connected program has pid or name of {expr}. the
usage of {expr}, see|isconnect()|. if {expr} is program name,
it must match the {expr} in|connect()|byte-by-byte. and all
connect use the {expr} to|connect()|will be killed.

if has {sid}, just send a signal {sid} to program. >
:call kill(gdb_pid) " kill the gdb connected
:call kill('gdb -q') " kill all gdb connected use the
string 'gdb -q'
<

*sendto()*
sendto({expr}, {data})
send {data} to the program, the usage of {expr}, see
|isconnect()|.

{data} is treated as string, and if {data} is a List,
treat it as a multi-line stirng, each item split with
<NL>.

this function always return immediately. the return value is
the byte count written into the buffer of program connected. >

:call sendto(gdb_pid, 'list') "list source in gdb
<

*recvfrom()*
recvfrom({expr}, {var}[, {async}])
recv data from program. the usage of {expr}, see
|isconnect()|.the returnd Stirng is saved in variable named
{var}. {var} must be a string or number variable, or
undefined.

To make the return more system-independent, the shell output
is filtered to replace <CR> with <NL> for Macintosh, and
<CR><NL> with <NL> for DOS-like systems. just like the return
value of|system()|.

the funtion returnd the byte count of data received.

if there are no data from program, wait for data. and if
{async} is given and nonzero, return 0 immediately. >
:call recvfrom(gdb_pid, 'res', 1)
:echo 'gdb:' . res
<

NOTE: if has any error, put the return code of program into
v:connect_error (just like|v:shell_error|), and return
zero.

just six function and a variable (one of it has implement yet), makes
Vim script can interaction with other program. it's easy, isn't it?
and if do so, we can apart cscope and grep support from Vim, just use
plugin to implement them.

2. more powerful autocmds

Timer Support:
*Timer*
Timer when timer time is comming. The pattern is matched the
id of timer. if it's a buflocal autocmd, the <amatch>
is the id of timer. |autocmd-buflocal| >
autocmd Timer <buffer> echo
\ 'Timer:'.expand(<amatch>)
<

*:settimer*
:[N]sett[imer] [N] [m] {id}
set a timer, it will raise|Timer|autocmd per [N]
seconds. when [m] is included, per [N] milliseconds.
the default is one second. >
:settimer 1 "set a timer, raise
Timer autocmd per
second, and id is 1
:5settimer 1 "same above, per 5 second
:settimer 100m 1 "per 100 milliseconds
< if you want drop it, use killtimer.

*:killtimer*
:ki[lltimer] {id}
drop a timer.


we can define timer in scripts, so we must know the free id of timer,
just use the function below:


*hastimer()*
hastimer({expr})
the function returns whether the timer has the id of {expr}
exists.


this will be very useful, it can detect whether the operation takes a
long time, and can used in game, it's paltform-specified, so before
use timer, you can detect whether your system supports it. use
exists('##Timer'). |exists()|
if it slow, just can add a option 'enabletimer' 'ent' to
disable/enable it.

*buffer-modified*
buffer-modified detect:

maybe can add a autocmd BufModfied, <aopera> is the operation, 'a'
add, 'd' delete, 'm', modified, etc, and <amatch> is the text of
modified (or other ways, all in all, just afford a way to detect
wthether the buffer changed), it useful to make on-the-fly plugin, and
if choose a right way to implement, it may be very simple. and maybe
another autocmd BufModfiedI, raised in modified operation in insert
mode. it's very simple, but it's powerful. (e.g. can add BufTextAdd,
BufTextDelete, etc, this is another way to implement, I don't know
which one is more effitive)

thanks for reading, I'm a programmer, I think to add these feature
isn't very hard, but they are useful, isn't it? I'm in my third years
in collenge, my mayjor is compuer science. so if nobody want to
implement it, i want to try, just hope anyone can support me!

" vim: ft=help:ts=4:sw=4:tw=70:et:sta:ai

Teemu Likonen

unread,
Jan 10, 2009, 2:59:20 PM1/10/09
to vim...@googlegroups.com
StarWing (2009-01-10 11:22 -0800) wrote:

> 1. interaction with other application

> executable({expr})
> isconnect({expr})
> connect({expr})


> kill({expr}[, {sid}])

> sendto({expr}, {data})

> recvfrom({expr}, {var}[, {async}])

> [...] so if nobody want to implement it, i want to try, just hope
> anyone can support me!

No doubt such features, if implemented well, would be useful for many.
Maybe Emacs Lisp manual can give you some ideas for the script interface
for external processes:

http://www.gnu.org/software/emacs/manual/html_node/elisp/Processes.html#Processes

StarWing

unread,
Jan 10, 2009, 3:08:40 PM1/10/09
to vim_use
i think it's good to make recvfrom has sync/async option, and others
all async. because the system() function make the sync calls.

we can discuss the interface of functions, and make the patch to Vim,
anyone want to join me?

if you are in china, you can find me with my QQ number:253727351, or
you can touch me with MSN:weasl...@sina.com. but if you use MSN,
please give me a e-mail, let me know it.

i planed to implement the timer feature and connect feature in win32
version and unix version, hope for joining!
> http://www.gnu.org/software/emacs/manual/html_node/elisp/Processes.ht...
Reply all
Reply to author
Forward
0 new messages