Excerpts from Christian Brabandt's message of Wed Oct 27 14:02:26 +0200 2010:
> There is already a getbufline() function available, so I would expect a
> setbufline() function as well. Asynchronous functions would be nice for
> monitoring logfiles but I guess, this functionality won't be included soon
> in Vim

No, but we can provide an implementation which is written in scheme.
The scheme interpreter implementation provides kind of cooperative
threading .. And racket has a non blocking IO implementation.

I haven't had time to digg into it deeper Sergey already helped by
providing some samples.

Original patch (branch asystem) (see wiki)
http://github.com/bartman/vim

My changes - which have to be tidied up:
http://github.com/MarcWeber/vim (branch work)

An illustration about how a VimL abstraction will look like:
http://github.com/MarcWeber/vim-addon-async

The C patch will be only one implementation.

I'm very lucky - it seems that I can just change the curbuf pointer and
run some code (nothing crashed yet .. )

So does anyone who knows the C code internals much better could be a
hint whether providing a function

run_in_buf_context(buf_nr, func, args)
run_in_buf_context(buf_nr, code)

which temporarely changes curbuf would cause any trouble?

Because a buffer can already be viewed multiple times I'd guess that
this could work for all simple use cases reasonable well.

The implementation could be as simple as this:

  /*
   * "withcurrentbuf(bufnr, callback, args[, dict])" function
   * This is a very quick and dirty experiment. WARNING: I didn't verify that
   * this doesn't mix things up.
   *
   * It changes the curbuf pointer, then call the function with the provided 
arguments
   */
      static void
  f_withcurrentbuf(argvars, rettv)
      typval_T  *argvars;
      typval_T  *rettv;
  {
      buf_T * oldbuf = curbuf;
      curbuf = get_buf_tv(&argvars[0]);
      if (!curbuf){
          EMSG(_("E999: buf does not exist"));
          rettv->vval.v_number = 0;
      } else {
          f_call(&argvars[1], rettv);
      }
      curbuf = oldbuf;
  }

Usage could look like this:

  call withcurrentbuf(40, function('append'), ["abc","foo"])

Thoughts?

Marc Weber

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui