[slim-vim] Patch for Vim FFI, searching
Larry Clapp
larry at theclapp.org
Mon Jun 19 08:25:07 CDT 2006
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.
I would have said
(defun vim:search (pattern &key (back nil)
(wrap (plusp (vim:var "&wrapscan")))
(keep-cursor nil))
(let ((flags (concatenate 'string
(if back "b" "")
(if wrap "w" "W")
(if keep-cursor "n" ""))))
(vim:funcall "search" (string pattern) flags)))
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))
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")
On the other hand, I guess we could always have both, and one would
call the other. :)
Thoughts?
-- Larry
More information about the slim-vim
mailing list