vim2grace : Grace/Common Music integration
| script karma
Downloaded by 215
Comments, bugs, improvements
script versions (upload new version)
|This program provides a very simple way to pass blocks of source code from
within vim (or other external editor) to Grace/Common Music for automatic
The program should be able to work without modification for any editor,
not just vim. All your editor has to do is write the blocks of source
code you want to send to Grace to a fifo (which is just like writing
to a regular file, so every editor should be capable of doing this).
This program has only undergone very minimal testing, and the
testing was done only on Linux with Grace 3.8.0 from svn.
USE AT YOUR OWN RISK.
The program does nothing fancy. It just uses a fifo for one-directional
communication from vim to Grace. That means that no results or errors
are passed from Grace back to vim. To see any results or errors, you will
have to look at the Grace screen.
More information on Grace/Common Music can be found here:
Here's how you could use vim2grace, should you choose to:
- First, download vim2grace.scm from the link at the bottom of this page.
- Second, if you want to change the default location of the fifo,
change the "vim2grace-fifo" variable near the top of vim2grace.scm,
or set a VIM2GRACE_FIFO environment variable, which will override
the hardcoded variable in the source.
NOTE: Because ANY scheme source code written to this fifo will be
automatically executed, you should keep this file under your control
and only writeable by you! I recommend keeping it somewhere in your
home directory and making sure your home directory is "chmod 700"
(ie. only readable, executable, and writeable by you).
- Third, start Grace and use the "File->Load File..." menu option to
load and run vim2grace.scm
Now Grace is in an infinite loop, waiting to read data from the fifo.
When it manages to read in an entire file from the fifo (up to the EOF),
it will assume what it read was Scheme source code and run it,
printing any errors, and then try to read another file's worth of data
from the fifo, etc..
- Fourth, in your ~/.vimrc you can (for example), create some key bindings
like the following:
:nnoremap <F3> vip:w>> ~/.vim2grace-fifo<CR>
:vnoremap <F4> :w>> ~/.vim2grace-fifo<CR>
- Fifth, now type a block of Scheme source code in to vim, place your cursor
somewhere within the block and hit F3 and your code should be passed
to Grace via the fifo. Alternatively, you can select some code in
visual block mode and hit F4 to do the same. Of course, you're free to
map any other keys, not just F3 and F4.
Problem: You just made your editor write some code to the fifo and
your editor is stuck at a blank screen.
Solution: This probably means that nothing is reading from the fifo.
Make sure Grace has started, and is running vim2grace.scm
If this does not help, you could always at least un-hang your
editor by typing the following in your shell:
(or whatever the path is to the fifo you had your editor use).
Problem: Using vim2grace to pass an expression like (+ 1 1) that
usually prints something when typed directly in to the Grace
editor prints nothing.
Solution: When you execute blocks of code from the Grace editor,
it runs them using (eval), which prints the value of the
expression it evaluates. Instead of (eval), vim2grace
uses (load), which does not print the values of the expressions
it evaluates. To see their values, try explicitly wrapping your
expression in a print statement, like: (print (+ 1 1))
Future versions of vim2grace might use (eval) too.
Problem: There's a bug in the code you passed from vim to Grace, and Grace
is stuck in an infinite loop or you have some other reason for
wanting to interrupt Grace.
Solution: The easiest thing is to just quit Grace (or kill it using the
unix/linux "kill" command).
As an alternative, instead of loading vim2grace.scm directly
in to Grace, you could try loading it in Grace's editor using
the "File->Open..." menu option, select the entire source code
and select the "Eval->Execute" menu option from within
the Grace editor.
Then, if you need to interrupt Grace for any reason, you
could use the "Eval->Interrupt Scheme" menu option.
Problem: Calls to procedures like (mp:receive) that are supposed to do
some background processing don't work.
Solution: Unfortunately, there is no solution for this problem right now,
and it's not exactly clear why it's happening. However, my guess
is that it's a consequence of relying on reading from a fifo, which
blocks all processing until more data is ready to be read from the
fifo. I'm guessing that no background processing can be done while
Grace is blocked. Perhaps a future version of vim2grep will use
some non-blocking or threaded means of communication, which should
hopefully fix the problem.
Click on the package to download.
ip used for rating: 126.96.36.199