Skip to content

Commit

Permalink
Add vim-redl
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynes committed May 7, 2013
1 parent 44253ed commit 6a80df1
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 0 deletions.
1 change: 1 addition & 0 deletions bundle/vim-redl/.gitignore
@@ -0,0 +1 @@
/doc/tags
78 changes: 78 additions & 0 deletions bundle/vim-redl/README.markdown
@@ -0,0 +1,78 @@
# Redl.vim -- Read Eval Debug Loop

This plugin integrates Vim with a running Clojure JVM. It provides a repl that
supports breakpoints, documentation lookup, source code navigation, and
omnicompletion.

## Installation

First, you'll need to install this as a Vim plugin. Do that with

cd ~/.vim/bundle
git clone git://github.com/dgrnbrg/vim-redl.git

You'll need Pathogen so that vim-redl gets loaded. Otherwise, if you are
a user of Vundle or NeoBundle, you can just use `Bundle 'dgrnbrg/vim-redl'`
or `NeoBundle 'dgrnbrg/vim-redl'` respectively to install the Vim component.

Then, you'll need to install the Clojure component. To get this, you just need to add 2 lines
to your `~/.lein/profiles.clj`.

- `:injections [(require '[redl core complete])]` ensure that redl is loaded on jvm startup
- `:dependencies [[redl "0.1.0"]]` ensures that redl is available on the classpath

A minimal profiles.clj (including REDL, Spyscope, and `lein pprint`) would look like:

```clojure
{:user {:dependencies [[spyscope "0.1.2"]
[redl "0.1.0"]]
:injections [(require 'spyscope.core)
(require '[redl complete core])]
:plugins [[lein-pprint "1.1.1"]]}}
```

### A REPL

To access the other repl, use `:Repl` or `:ReplHere`. The former opens a new
split window containing a repl in the namespace `user`. The latter opens the
repl in the namespace of the current file.

If you don't reconfigure the plugs below, these are the default controls for
the repl:

- `ctrl-e` in insert mode evaluates the current line, regardless of cursor position.
- `return` in insert mode at the end of the line evaluates the line, otherwise inserts a newline.
- `ctrl-up` goes up in the history
- `ctrl-down` goes down in the history

To use the breakpoint feature, check out dgrnbrg/redl (short version: `redl.core/break`
and `redl.core/continue`.

The plugs for the repl:

<Plug>clj_repl_enter.
<Plug>clj_repl_eval.
<Plug>clj_repl_hat.
<Plug>clj_repl_Ins.
<Plug>clj_repl_uphist.
<Plug>clj_repl_downhist.


### Omnicomplete

This feature requires redl to be loaded in the connected JVM, as this plugin
uses redl's advanced fuzzy completion engine.

## Contributing

Please, open GitHub issues for bug reports and feature requests. Even better than a
feature request is just to tell me the pain you're experiencing, and perhaps
some ideas for what might eliminate it.

This plugin was made by borrowing generous amounts of code from vimclojure Meikel Brandmeyer.

## License

Copyright © David Greenberg, Tim Pope, and Meikel Brandmeyer.
Distributed under the same terms as Vim itself.
See `:help license`.
68 changes: 68 additions & 0 deletions bundle/vim-redl/doc/redl.txt
@@ -0,0 +1,68 @@
*redl.txt* Clojure Read Eval Debug Loop

Author: David Greenberg <dsg123456789 {at} gmail {dot} com>
License: Same terms as Vim itself (see |license|)

You need Clojure runtime (vim-clojure-static) plugin and vim-fireplace + vim-classpath plugins to use this plugin.

CLOJURE CONFIGURATION *redl-clojure-configuration*

Add following lines to your ~/.lein/profiles.clj

:injections [(require '[redl core complete])] ensure that redl is loaded on jvm startup
:dependencies [[redl "0.1.0"]] ensures that redl is available on the classpath

A minimal profiles.clj (including REDL, Spyscope, and lein pprint) would look like:

{:user {:dependencies [[spyscope "0.1.2"]
[redl "0.1.0"]]
:injections [(require 'spyscope.core)
(require '[redl complete core])]
:plugins [[lein-pprint "1.1.1"]]}}

REPL *redl-repl*

Repl is only available in Clojure filetype.

*redl-:Repl*
:Repl Show repl in user namespace.

*redl-:ReplHere*
:ReplHere Show repl in current namespace.

*redl-CTRL-e*
C-e Evaluate current line in instert mode, regardless of
cursor position.

*redl-CR*
CR In insert mode at the end of the line evaluates the line, otherwise inserts a newline.

*redl-CTRL-UP*
C-Up Goes up in the repl history.

*redl-CTRL-DOWN*
C-Down Goes down in the repl history.

OMNICOMPLETE *redl-omnicomplete*

This feature requires redl to be loaded in the connected JVM, as this plugin
uses redl's advanced fuzzy completion engine.

KEYS *redl-keys*

To change default keys you can use following plugs:

<Plug>clj_repl_enter. CR
<Plug>clj_repl_eval. C-e
<Plug>clj_repl_hat. ^
<Plug>clj_repl_Ins. I
<Plug>clj_repl_uphist. C-Up
<Plug>clj_repl_downhist. C-Down

ABOUT *redl-about*

Grab the latest version or report a bug on GitHub:

https://github.com/dgrnbrg/vim-redl

vim:tw=78:et:ft=help:norl:
109 changes: 109 additions & 0 deletions bundle/vim-redl/plugin/redl.vim
@@ -0,0 +1,109 @@
" redl.vim - Clojure REPL Enhancements
" Maintainer: David Greenberg

if exists("g:loaded_redl") || v:version < 700 || &cp
finish
endif
let g:loaded_redl = 1

function! redl#eval_complete(A, L, P) abort
let prefix = matchstr(a:A, '\%(.* \|^\)\%(#\=[\[{('']\)*')
let keyword = a:A[strlen(prefix) : -1]
return sort(map(redl#omnicomplete(0, keyword), 'prefix . v:val.word'))
endfunction

function! redl#omnicomplete(findstart, base) abort
if a:findstart
let line = getline('.')[0 : col('.')-2]
return col('.') - strlen(matchstr(line, '\k\+$')) - 1
else
try
let ns = fireplace#ns()
let results = fireplace#evalparse('(map redl.complete/->vim-omnicomplete'.
\' (redl.complete/completions '.s:qsym(ns).' "'.a:base.'"))')
if type(results) == type([])
return results
else
return []
endif
catch /.*/
return []
endtry
endif
endfunction

function! s:qsym(symbol)
if a:symbol =~# '^[[:alnum:]?*!+/=<>.:-]\+$'
return "'".a:symbol
else
return '(symbol "'.escape(a:symbol, '"').'")'
endif
endfunction


augroup redl_completion
autocmd!
autocmd FileType clojure setlocal omnifunc=redl#omnicomplete
augroup END

function! s:Eval(bang, line1, line2, count, args) abort
if a:args !=# ''
let expr = a:args
else
if a:count ==# 0
normal! ^
let line1 = searchpair('(','',')', 'bcrn', g:fireplace#skip)
let line2 = searchpair('(','',')', 'rn', g:fireplace#skip)
else
let line1 = a:line1
let line2 = a:line2
endif
if !line1 || !line2
return ''
endif
let expr = join(getline(line1, line2), "\n")
if a:bang
exe line1.','.line2.'delete _'
endif
endif
if a:bang
try
let result = fireplace#session_eval(expr)
if a:args !=# ''
call append(a:line1, result)
exe a:line1
else
call append(a:line1-1, result)
exe a:line1-1
endif
catch /^Clojure:/
endtry
else
call fireplace#echo_session_eval(expr)
endif
return ''
endfunction

function! s:setup_eval() abort
command! -buffer -bang -range=0 -nargs=? -complete=customlist,redl#eval_complete Eval :exe s:Eval(<bang>0, <line1>, <line2>, <count>, <q-args>)

command! -buffer Repl :call redl#repl#create("user")
command! -buffer ReplHere :call redl#repl#create(fireplace#ns())
endfunction

function! s:cmdwinenter()
setlocal filetype=clojure
endfunction

function! s:cmdwinleave()
setlocal filetype< omnifunc<
endfunction

augroup redl_eval
autocmd!
autocmd FileType clojure call s:setup_eval()
autocmd CmdWinEnter @ if exists('s:input') | call s:cmdwinenter() | endif
autocmd CmdWinLeave @ if exists('s:input') | call s:cmdwinleave() | endif
augroup END

" vim:set et sw=2:

0 comments on commit 6a80df1

Please sign in to comment.