[slimpl] Fun with vim+async+ecl

Larry Clapp larry at theclapp.org
Mon Mar 6 22:42:54 CST 2006


I noticed the current vim+async+ecl didn't have a function to read the
value of a Vim variable, and since I don't know Vim internals well
enough to write one in C, I wrote one in CL.  (Actually, I probably
could have figured out the Vim internals, but this was more fun.  :)

  (use-package :vim)
  (defvar *vim-val*)
  (defun vim-val (var)
    "Return the value of a Vim variable"
    (let* (*vim-val*
	   (cmd (format nil "exec \"ecl (setq *vim-val* \\\"\" . ~A . \"\\\")\"~%" var)))
      (command cmd)
      *vim-val*))

I also wrote a sort of LET for Vim.

  (defmacro vim-let (vars &body body)
    `(progn
       ,@(mapcar (lambda (var-spec)
		   (destructuring-bind (var val &optional (var-name (symbol-name var))) var-spec
		     `(command ,(format nil "let ~A=\"~A\"" var-name val))))
		 vars)
       (symbol-macrolet
	 (,@(mapcar (lambda (var-spec)
		      (destructuring-bind (var val &optional (var-name (symbol-name var))) var-spec
			`(,var (vim-val ,var-name))))
		    vars))
	 , at body)))

So

  (vim-let ((var1 "val1" "var1_name")
	    (var2 "val2" "var2_name"))
    (format t "var1 is ~A" var1)
    (format t "var2 is ~A" var2))
  =>
  var1 is val1
  var2 is val2

and also

  :echo var1_name
  => val1

The macroexpansion looks like

  (progn
    (command "let var1_name=\"val1\"")
    (command "let var2_name=\"val2\"")
    (symbol-macrolet ((var1 (vim-val "var1_name")) (var2 (vim-val "var2_name")))
      (format t "var1 is ~A" var1)
      (format t "var2 is ~A" var2)))

Sometimes it doesn't work, though: sometimes it prints extra garbage,
and sometimes it crashes Vim outright.  I suspect a re-entrancy
problem involving vim-val, where I have recursive levels of :ecl
invoked at once.  I suspect the resolution is "don't do that then".
:)  But it was fun.

Anyway, Jim's web page says "It does not use configure as I don't know
how, it just does nasty things with the Makefile. (patch pending)"
Well, it's my patch, and now that I've checked out his darcs
repository, I'll look at generating a darcs patch for him.

Happy Vimming!

-- Larry



More information about the slimpl mailing list