[slim-vim] Patch for Vim FFI, searching

Brad Beveridge brad.beveridge at gmail.com
Mon Jun 19 09:32:45 CDT 2006


On 19/06/06, Larry Clapp <larry at theclapp.org> wrote:
> On Sun, Jun 18, 2006 at 08:34:15PM -0700, Brad Beveridge wrote:
> > Hi all, my next post will add "package correctness" to Slim-vim, ie
> > when you eval a form it will be evaluated in Swank in the correct
> > package, but your Vim will need the following FFI patch.
> [snip]
> > (defun vim:search (pattern &key (back nil) (wrap t) (move-cursor nil))
> >   (let ((flags (with-output-to-string (s)
> >                  (when back (princ "b" s))
> >                  (if wrap (princ "w" s) (princ "W" s))
> >                  (unless move-cursor (princ "n" s)))))
> >     (vim:funcall "search" (string pattern) (string flags))))
>
> Vim's search(), by default, moves the cursor.  This one doesn't.
Yeah, I should have been consistant with Vim's conventions really

>
<SNIP>
>
> but they both suffer from a minor annoyance: search() in Vim7 has 8
> flags, which are all essentially booleans; having a keyword for each,
> which is just T or NIL, seems excessive.  For example, we might end up
> with
>
>   (vim:search "pattern"
>     :back t :accept-match-at-cursor t :move-to-end t
>     :return-match-count t :set-tick-mark t :wrap t)
>
> All the T's seem pretty redundant.  What do we think of just having a
> list of flags:
>
>   (vim:search
>     '(:back :accept-match-at-cursor :move-to-end :return-match-count
>       :set-tick-mark :wrap))
>
That's a really good point.  What is the "Lispy" way to do flags like
this?  I suspect it is probably to have the enabled flags in a list
like you have them.  Alternately we could define search as
(defun search (pattern &rest flags)....)

> We could even have a compiler macro that "compiles" a literal list of
> keywords into a string at compile-time instead of run-time.  The above
> would become:
>
>   (vim:funcall "search" "bcepsw")
For the added effort, I'd just do it at runtime.  But a
flags->flags_string function would be useful.

Cheers
Brad


More information about the slim-vim mailing list