[slim-vim] Vim+ECL patch

Brad Beveridge brad.beveridge at gmail.com
Mon May 22 17:08:32 CDT 2006


> It is consistent with internal Vim, but I don't consider it a good
> thing.  I want to be able to make a very easy choice when doing
> Vim+ECL programming: If I'm writing in Lisp, I know I use zero-based
> code (buffer numbers, lines, etc); if I'm writing in C, I'll use
> whatever Vim internals already do.
>
> So I guess I'd rather the C internal "FFI" take zero-based indexes and
> translate them as appropriate.  When we write Lisp code that calls Vim
> functions (e.g. append() / bufnr() / col(), etc), have them do the
> same thing: accept zero-based indexes and translate to one-based
> indexes when calling Vim functions and translate their return values
> back to zero-based values.
>
> I'm imagining years in the future when we have way more Lisp code for
> Vim.  I don't want to have to know that THIS function eventually calls
> bufnr() and so I have to use 1..N for its ranges, but THAT function
> doesn't and so I use 0..(N-1), and oh if I want to use BOTH of them
> then I have to remember all this and translate the indexes myself,
> over and over and over, squared and cubed.  Ick ick ick!
>
> A simple example: Say I have an array that stores information indexed
> by the buffer number.  I have 5 buffers.  I can either waste an array
> slot and alocate one more than I need (0..5) and use aref directly
>
>   (defun number-of (b)
>     (vim:vim-funcall "bufnr" b))
>   (setf foo (make-array 6))
>   (aref foo (number-of some-buffer))
>
> or I can manually translate from one coordinate system to the other:
>
>   (defun number-of (b)
>     (vim:vim-funcall "bufnr" b))
>   (setf foo (make-array 5))
>   (aref foo (1- (number-of some-buffer)))
>
> OR (best case) number-of can be smart and do the 1- all on its own:
>
>   (defun number-of (b)
>     (1- (vim:vim-funcall "bufnr" b)))
>   (setf foo (make-array 5))
>   (aref foo (number-of some-buffer))
>
> and that's that.
You've convinced me, 0..(n-1) is the way to go.  I'll look over that
section soon I guess.  Probably just need to make a note somewhere
that Lisp line numbers are 0..N-1 based rather than 1..N.

Cheers
Brad


More information about the slim-vim mailing list