random-state.net

Nikodemus Siivola

<< next | top | previous >>

Vim and SBCL #
hacking, June 5th 2009

Disclaimer: I don' use vim. However, there was a question on sbcl-devel about how to make ED use the console vim, and I thought someone not on sbcl-devel readers might get a kick out of this:

(require :sb-introspect)

(define-alien-routine system int (command c-string))

(defun namestring-for-vim (thing)
  (when thing
    (typecase thing
      (pathname
       (native-namestring (translate-logical-pathname thing) :as-file t))
      (string
       thing)
      (t
       (let* ((source
               (sb-introspect:find-definition-source (fdefinition thing)))
              (pathname
               (sb-introspect:definition-source-pathname source))
              (offset
               (or (sb-introspect:definition-source-character-offset source)
                   0)))
         (unless pathname
           (error "Don't know where the definition of ~S is, sorry." thing))
         (format nil "-c \"goto ~A\" ~A"
                 offset
                 (namestring-for-vim pathname)))))))

(defun ed-in-vim (thing)
  (system (format nil "vim~@[ ~A~]" (namestring-for-vim thing))))

(push 'ed-in-vim *ed-functions*)

Given this, (ED 'CONS) does the right thing, assuming SBCL sources are in place.