Skip to content

Commit

Permalink
Merge pull request #28 from liquidz/dev
Browse files Browse the repository at this point in the history
ver 0.3.1
  • Loading branch information
liquidz authored Sep 13, 2018
2 parents a07fa5a + 105b183 commit 41a6e97
Show file tree
Hide file tree
Showing 24 changed files with 308 additions and 94 deletions.
12 changes: 9 additions & 3 deletions .aspell.en.pws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 123
personal_ws-1.1 en 129
grimoire
IcedGrep
IcedDocumentOpen
Expand All @@ -9,8 +9,8 @@ IcedPrintLast
rhs
defn
dec
IcedReconnect
jonase
IcedReconnect
sha
CursorHoldI
IcedEval
Expand All @@ -28,12 +28,14 @@ clj
liquidz
macroexpand
IcedDefJump
affd
belowright
linter
undef
figwheel
sexp
dir
href
IcedEvalOuterTopList
lhs
changelog
Expand Down Expand Up @@ -70,6 +72,7 @@ IcedDisconnect
IcedTestAll
Undefine
stdout
IcedBrowseFunction
IcedToggleTraceNs
FileType
aboveleft
Expand All @@ -86,11 +89,12 @@ nrepl
concat
IcedToggleSrcAndTest
BufWritePost
IcedLintCurrentFile
linters
IcedLintCurrentFile
IcedFormDocument
IcedCleanNs
Cljfmt's
IcedClearCtrlpCache
url
IcedEchoFormDocument
leiningen
Expand All @@ -99,7 +103,9 @@ nashorn
IcedSlurp
leftabove
vimrc
CircleCI
IcedToggleTraceVar
IcedStdoutBufferClose
txt
IcedBrowseSpec
Sdeps
Expand Down
5 changes: 5 additions & 0 deletions .local.vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let g:ctrlp_custom_ignore['dir'] =
\ '\v[\/](\.git|\.vim-themis|\.vim-sexp|vital)$'
let g:ctrlp_custom_ignore['file'] =
\ '\v(\.bk|\.gitkeep|\.aspell\.en\.pws|tags)$'

19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# vim-iced
[![CircleCI](https://circleci.com/gh/liquidz/vim-iced.svg?style=svg)](https://circleci.com/gh/liquidz/vim-iced)
[![Powered by vital.vim](https://img.shields.io/badge/powered%20by-vital.vim-80273f.svg)](https://github.com/vim-jp/vital.vim)

Clojure Interactive Development Environment for Vim8.
<h4 align="center">Clojure Interactive Development Environment for Vim8.</h4>
<p align="center">
<a href="https://circleci.com/gh/liquidz/vim-iced">
<img src="https://circleci.com/gh/liquidz/vim-iced.svg?style=svg" alt="CircleCI" />
</a>

<a href="https://github.com/liquidz/vim-iced/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/liquidz/vim-iced.svg" alt="GitHub license" />
</a>

<a href="https://github.com/vim-jp/vital.vim">
<img src="https://img.shields.io/badge/powered%20by-vital.vim-80273f.svg" alt="Powered by vital.vim" />
</a>
</p>

**WARN**: This project is work in progress.

Expand Down Expand Up @@ -79,7 +90,7 @@ See [vim-iced.txt](./doc/vim-iced.txt) for actual mappings.
1. Start repl
- `lein repl`
- `boot repl`
- `clojure -Sdeps '{:deps {iced-repl {:git/url "https://github.com/liquidz/vim-iced" :sha "5e56f4a33c9d87e494b67e174c7d6a3f39f2e101"}}}' -m iced-repl`
- `clojure -Sdeps '{:deps {iced-repl {:git/url "https://github.com/liquidz/vim-iced" :sha "ac7affd6ab4b9e28f917a8900bd19465c8a08b7b"}}}' -m iced-repl`
2. Open source file
3. Evaluate forms (If not connected, vim-iced will connect automatically)

Expand Down
7 changes: 6 additions & 1 deletion autoload/ctrlp/iced.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ if exists('g:loaded_ctrlp')
endif

function! ctrlp#iced#init() abort
return get(s:config, 'candidates', [])
if has_key(s:config, 'init')
let Init = s:config['init']
return Init()
else
return get(s:config, 'candidates', [])
endif
endfunction

function! ctrlp#iced#accept(mode, line) abort
Expand Down
40 changes: 40 additions & 0 deletions autoload/ctrlp/iced/cache.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
let s:save_cpo = &cpo
set cpo&vim

let s:dir = ctrlp#utils#cachedir()
\ . ctrlp#utils#lash()
\ . 'iced'

function! s:cachefile(name) abort
return s:dir.ctrlp#utils#lash()
\ . iced#nrepl#system#project_name()
\ . '.' . a:name . '.txt'
endfunction

function! ctrlp#iced#cache#exists(name) abort
return filereadable(s:cachefile(a:name))
endfunction

function! ctrlp#iced#cache#write(name, lines) abort
let file = s:cachefile(a:name)
call ctrlp#utils#writecache(a:lines, s:dir, file)
endfunction

function! ctrlp#iced#cache#read(name) abort
if ctrlp#iced#cache#exists(a:name)
let file = s:cachefile(a:name)
return ctrlp#utils#readfile(file)
else
return []
endif
endfunction

function! ctrlp#iced#cache#clear() abort
for path in globpath(s:dir, '*.txt')
call delete(path)
endfor
return iced#message#info('cache_cleared')
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
4 changes: 4 additions & 0 deletions autoload/iced/buffer/stdout.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ function! iced#buffer#stdout#clear() abort
call iced#buffer#clear(s:bufname, funcref('s:initialize'))
endfunction

function! iced#buffer#stdout#close() abort
call iced#buffer#close(s:bufname)
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
14 changes: 5 additions & 9 deletions autoload/iced/nrepl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ function! s:merge_response_handler(resp) abort
return result
endfunction

function! s:identity_handler(resp) abort
function! s:default_handler(resp) abort
return a:resp
endfunction

function! iced#nrepl#register_handler(op, ...) abort
let Handler = get(a:, 1, funcref('s:identity_handler'))

if !iced#util#is_function(Handler)
function! iced#nrepl#register_handler(op, handler) abort
if !iced#util#is_function(a:handler)
throw 'handler must be funcref'
endif
let s:handlers[a:op] = Handler
let s:handlers[a:op] = a:handler
endfunction

"" -----------
Expand Down Expand Up @@ -143,7 +141,7 @@ function! s:dispatcher(ch, resp) abort

if has_key(s:messages, id)
let handler_result = v:none
let Handler = get(s:handlers, s:messages[id]['op'], v:none)
let Handler = get(s:handlers, s:messages[id]['op'], funcref('s:default_handler'))
if iced#util#is_function(Handler)
let handler_result = Handler(resp)
endif
Expand Down Expand Up @@ -367,8 +365,6 @@ function! iced#nrepl#load_file(callback) abort
\ })
endfunction

call iced#nrepl#register_handler('clone')
call iced#nrepl#register_handler('interrupt')
call iced#nrepl#register_handler('eval', funcref('s:merge_response_handler'))
call iced#nrepl#register_handler('load-file', funcref('s:merge_response_handler'))

Expand Down
9 changes: 0 additions & 9 deletions autoload/iced/nrepl/cider.vim
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,9 @@ function! iced#nrepl#cider#spec_form(spec_name, callback) abort
\ })
endfunction

call iced#nrepl#register_handler('info')
call iced#nrepl#register_handler('ns-path')
call iced#nrepl#register_handler('format-code')
call iced#nrepl#register_handler('test', funcref('s:test_handler'))
call iced#nrepl#register_handler('retest', funcref('s:test_handler'))
call iced#nrepl#register_handler('test-all', funcref('s:test_handler'))
call iced#nrepl#register_handler('undef')
call iced#nrepl#register_handler('macroexpand')
call iced#nrepl#register_handler('toggle-trace-ns')
call iced#nrepl#register_handler('toggle-trace-var')
call iced#nrepl#register_handler('spec-list')
call iced#nrepl#register_handler('spec-form')

let &cpo = s:save_cpo
unlet s:save_cpo
3 changes: 0 additions & 3 deletions autoload/iced/nrepl/cider/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@ function! iced#nrepl#cider#debug#input(key, in) abort
\ })
endfunction

call iced#nrepl#register_handler('init-debugger')
call iced#nrepl#register_handler('debug-input')

let &cpo = s:save_cpo
unlet s:save_cpo
5 changes: 0 additions & 5 deletions autoload/iced/nrepl/cider/sync.vim
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,5 @@ function! iced#nrepl#cider#sync#ns_path(ns) abort
\ })
endfunction

call iced#nrepl#register_handler('complete')
call iced#nrepl#register_handler('ns-list')
call iced#nrepl#register_handler('ns-vars-with-meta')
call iced#nrepl#register_handler('ns-path')

let &cpo = s:save_cpo
unlet s:save_cpo
45 changes: 45 additions & 0 deletions autoload/iced/nrepl/everywhere.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let s:save_cpo = &cpo
set cpo&vim

let s:type_dict = {
\ 'namespace': 'n',
\ 'function': 'f',
\ }

function! s:accept(mode, v) abort
let [_name, _type, path, pos] = split(a:v, "\t")
let [line_str, column_str] = split(pos, ':')

let cmd = ':edit'
if a:mode ==# 'v'
let cmd = ':split'
elseif a:mode ==# 't'
let cmd = ':tabedit'
endif
exe printf('%s %s', cmd, path)

call cursor(str2nr(line_str), str2nr(column_str))
normal! zz
endfunction

function! s:format_candidate(candidate) abort
return printf("%s\t%s\t%s\t%d:%d",
\ a:candidate['name'],
\ s:type_dict[a:candidate['type']],
\ a:candidate['file'],
\ a:candidate['line'], a:candidate['column'])
endfunction

function! s:everywhere(candidates) abort
call ctrlp#iced#start({
\ 'candidates': map(a:candidates, {_, v -> s:format_candidate(v)}),
\ 'accept': funcref('s:accept')
\ })
endfunction

function! iced#nrepl#everywhere#search() abort
call iced#nrepl#iced#everywhere(funcref('s:everywhere'))
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
49 changes: 49 additions & 0 deletions autoload/iced/nrepl/function.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let s:save_cpo = &cpo
set cpo&vim

let s:cache_name = 'functions'

function! s:open(mode, resp) abort
if !has_key(a:resp, 'file') || empty(a:resp['file'])
return iced#message#error('not_found')
endif

let path = substitute(a:resp['file'], '^file:', '', '')
if !filereadable(path)
return iced#message#error('not_found')
endif

let cmd = ':edit'
if a:mode ==# 'v'
let cmd = ':split'
elseif a:mode ==# 't'
let cmd = ':tabedit'
endif
exe printf('%s %s', cmd, path)

call cursor(a:resp['line'], a:resp['column'])
normal! zz
endfunction

function! s:resolve(mode, func_name) abort
call iced#nrepl#cider#info(a:func_name, {resp -> s:open(a:mode, resp)})
endfunction

function! s:select(functions) abort
if empty(a:functions) | return iced#message#error('not_found') | endif
call ctrlp#iced#cache#write(s:cache_name, a:functions)
call ctrlp#iced#start({'candidates': a:functions, 'accept': funcref('s:resolve')})
endfunction

function! iced#nrepl#function#list() abort
if ctrlp#iced#cache#exists(s:cache_name)
let lines = ctrlp#iced#cache#read(s:cache_name)
call ctrlp#iced#start({'candidates': lines, 'accept': funcref('s:resolve')})
else
call iced#message#info('fetching')
call iced#nrepl#iced#project_functions(funcref('s:select'))
endif
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
29 changes: 25 additions & 4 deletions autoload/iced/nrepl/iced.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,40 @@ function! iced#nrepl#iced#grimoire(platform, ns_name, symbol, callback) abort
\ })
endfunction

let s:concat_results = []
function! s:concat_handler(key, resp) abort
for resp in iced#util#ensure_array(a:resp)
if has_key(resp, a:key)
call extend(s:concat_results, resp[a:key])
endif
endfor
return s:concat_results
endfunction

function! iced#nrepl#iced#project_namespaces(callback) abort
if !iced#nrepl#is_connected() | return iced#message#error('not_connected') | endif

let s:concat_results = []
call iced#nrepl#send({
\ 'id': iced#nrepl#eval#id(),
\ 'op': 'project-namespaces',
\ 'sesion': iced#nrepl#current_session(),
\ 'callback': a:callback,
\ })
endfunction

call iced#nrepl#register_handler('lint-file')
call iced#nrepl#register_handler('grimoire')
call iced#nrepl#register_handler('project-namespaces')
function! iced#nrepl#iced#project_functions(callback) abort
if !iced#nrepl#is_connected() | return iced#message#error('not_connected') | endif
let s:concat_results = []
call iced#nrepl#send({
\ 'id': iced#nrepl#eval#id(),
\ 'op': 'project-functions',
\ 'sesion': iced#nrepl#current_session(),
\ 'callback': a:callback,
\ })
endfunction

call iced#nrepl#register_handler('project-namespaces', {resp -> s:concat_handler('namespaces', resp)})
call iced#nrepl#register_handler('project-functions', {resp -> s:concat_handler('functions', resp)})

let &cpo = s:save_cpo
unlet s:save_cpo
Loading

0 comments on commit 41a6e97

Please sign in to comment.