Skip to content

Commit

Permalink
Merge pull request #36 from liquidz/dev
Browse files Browse the repository at this point in the history
ver 0.4.3
  • Loading branch information
liquidz authored Oct 2, 2018
2 parents 969aa8b + 0116cb8 commit 413a13e
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .aspell.en.pws
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 147
personal_ws-1.1 en 149
grimoire
IcedGrep
IcedDocumentOpen
Expand Down Expand Up @@ -42,6 +42,7 @@ sexp
dir
href
IcedEvalOuterTopList
IcedCommandPalette
lhs
changelog
wrapscan
Expand Down Expand Up @@ -82,6 +83,7 @@ IcedBrowseFunction
stdout
Javadoc
IcedExtractFunction
IcedGrimoireOpen
IcedToggleTraceNs
FileType
IcedMoveToLet
Expand Down
44 changes: 35 additions & 9 deletions autoload/iced/let.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@ function! iced#let#goto() abort
let reg_save = @@

try
call iced#paredit#move_to_prev_top_element()
let stopline = line('.')
call winrestview(view)
let ret = search('(let[ \r\n]', 'b', stopline)
if ret != 0
call search('\[')
if iced#paredit#move_to_current_element_head() == 0
call winrestview(view)
return 0
endif
return ret

while v:true
let head = strpart(getline('.'), col('.'), 4)
if head ==# 'let' || head ==# 'let '
call search('\[')
break
endif

if iced#paredit#move_to_parent_element() == 0
call winrestview(view)
return 0
endif
endwhile

return col('.')
finally
let @@ = reg_save
endtry
endfunction

function! iced#let#move_to_let() abort
function! iced#let#move_to_let(...) abort
let view = winsaveview()
let reg_save = @@

Expand All @@ -29,15 +40,30 @@ function! iced#let#move_to_let() abort

let indent = col('.')-1
let form = iced#util#del_indent(indent, form)
let name = trim(input('Name: '))
let name = get(a:, 1, '')
if empty(name)
let name = trim(input('Name: '))
endif
if empty(name)
return iced#message#echom('canceled')
endif

if iced#let#goto() == 0
" re-select form
call iced#paredit#get_outer_list_raw()
" 6 means `len('(let [')`
let form = iced#util#add_indent(len(name)+1+6, form)
let @@ = iced#util#add_indent(
\ indent, printf("(let [%s %s]\n %s)", name, form, name))
silent normal! gvp
else
" re-select form
" FIXME too redundant!!
let tmp = winsaveview()
call winrestview(view)
call iced#paredit#get_outer_list_raw()
call winrestview(tmp)

let pos = getcurpos()
let @@ = name
silent normal! gvp
Expand Down
5 changes: 2 additions & 3 deletions autoload/iced/nrepl/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function! s:apply_coordination(coordination) abort
let i = c
while i > 0
call sexp#move_to_adjacent_element('n', 1, 1, 0, 0)
let x = strpart(getline('.'), max([col('.')-1, 1]), 6)
let x = strpart(getline('.'), max([col('.')-1, 0]), 6)
if stridx(x, '#dbg') != 0 && stridx(x, '#break') != 0
let i = i - 1
endif
Expand Down Expand Up @@ -57,8 +57,7 @@ function! s:move_cursor_and_set_highlight(resp) abort
call s:apply_coordination(a:resp['coor'])

let pos = getcurpos()
let char = getline('.')[max([col('.')-1, 1])]
if char ==# '('
if iced#util#char() ==# '('
normal! l
let l = max([len(expand('<cword>')), 1])
else
Expand Down
9 changes: 5 additions & 4 deletions autoload/iced/nrepl/ns/refactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ function! s:add(ns_name) abort
call iced#message#info_str(msg)
endfunction

function! s:project_namespaces(namespaces) abort
let namespaces = (empty(a:namespaces) ? [] : a:namespaces)
function! s:ns_list(resp) abort
if !has_key(a:resp, 'ns-list') | return iced#message#error('ns_list_error') | endif
let namespaces = get(a:resp, 'ns-list', [])
let favorites = get(g:iced#nrepl#ns#refactor#favorites, iced#nrepl#current_session_key(), {})
call extend(namespaces, keys(favorites))
let namespaces = s:L.uniq(s:L.concat([namespaces, keys(favorites)]))

call ctrlp#iced#start({
\ 'candidates': namespaces,
Expand All @@ -173,7 +174,7 @@ endfunction

function! iced#nrepl#ns#refactor#add(ns_name) abort
if empty(a:ns_name)
call iced#nrepl#op#iced#project_namespaces(funcref('s:project_namespaces'))
call iced#nrepl#op#cider#ns_list(funcref('s:ns_list'))
else
call s:add(a:ns_name)
endif
Expand Down
9 changes: 9 additions & 0 deletions autoload/iced/nrepl/op/cider.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function! iced#nrepl#op#cider#ns_path(ns, callback) abort
\ })
endfunction

function! iced#nrepl#op#cider#ns_list(callback) abort
if !iced#nrepl#is_connected() | echom iced#message#get('not_connected') | return | endif
call iced#nrepl#send({
\ 'op': 'ns-list',
\ 'session': iced#nrepl#current_session(),
\ 'callback': a:callback,
\ })
endfunction

function! iced#nrepl#op#cider#format_code(code, callback) abort
if !iced#nrepl#is_connected() | echom iced#message#get('not_connected') | return | endif
call iced#nrepl#send({
Expand Down
4 changes: 4 additions & 0 deletions autoload/iced/nrepl/refactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function! iced#nrepl#refactor#extract_function() abort
try
let locals = a:resp['used-locals']
let func_name = trim(input('Function name: '))
if empty(func_name)
return iced#message#echom('canceled')
endif

let func_body = iced#paredit#get_outer_list_raw()

let @@ = printf('(%s %s)', func_name, join(locals, ' '))
Expand Down
44 changes: 44 additions & 0 deletions autoload/iced/palette.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
let s:save_cpo = &cpo
set cpo&vim

let s:default_palette = [
\ 'Connect',
\ 'Disconnect',
\ 'Reconnect',
\ 'Interrupt',
\ 'PrintLast',
\ 'RequireAll',
\ 'StartCljsRepl figwheel',
\ 'StartCljsRepl nashorn',
\ 'QuitCljsRepl',
\ 'TestNs',
\ 'TestAll',
\ 'TestRedo',
\ 'ToggleSrcAndTest',
\ 'BrowseNamespace',
\ 'BrowseFunction',
\ 'BrowseSpec',
\ 'CleanNs',
\ 'AddNs',
\ 'ToggleTraceVar',
\ 'ToggleTraceNs',
\ 'InReplNs',
\ 'LintCurrentFile',
\ 'LintToggle',
\ ]

let g:iced#palette#palette = get(g:, 'iced#palette#palette', s:default_palette)

function! s:run(candidate) abort
execute printf(':Iced%s', a:candidate)
endfunction

function! iced#palette#show() abort
call ctrlp#iced#start({
\ 'candidates': g:iced#palette#palette,
\ 'accept': {_, candidate -> s:run(candidate)},
\ })
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
31 changes: 30 additions & 1 deletion autoload/iced/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ function! iced#paredit#move_to_prev_top_element() abort
call sexp#move_to_adjacent_element('n', 0, 0, 0, 1)
endfunction

function! iced#paredit#move_to_current_element_head() abort
if iced#util#char() ==# '('
return col('.')
else
let pos = getcurpos()
silent normal! va(o
silent exe "normal! \<Esc>"
return (pos == getcurpos() ? 0 : col('.'))
endif
endfunction

function! iced#paredit#move_to_parent_element() abort
let view = winsaveview()
let ret = iced#paredit#move_to_current_element_head()
if ret == 0 || col('.') == 1
call winrestview(view)
return 0
endif

" move to parent form head
silent normal! hva(o
silent exe "normal! \<Esc>"
return col('.')
endfunction

function! iced#paredit#get_current_top_list_raw() abort
let code = v:none
let pos = v:none
Expand Down Expand Up @@ -81,7 +106,11 @@ function! iced#paredit#get_current_top_list() abort
endfunction

function! iced#paredit#get_outer_list_raw() abort
silent normal! va(y
try
silent normal! va(y
finally
silent exe "normal! \<Esc>"
endtry
return @@
endfunction

Expand Down
4 changes: 4 additions & 0 deletions autoload/iced/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@ function! iced#util#del_indent(n, s) abort
return substitute(a:s, '\r\?\n'.spc, "\n", 'g')
endfunction

function! iced#util#char() abort
return getline('.')[max([col('.')-1, 0])]
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
23 changes: 22 additions & 1 deletion doc/vim-iced.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*vim-iced.txt* Clojure interactive development environment for Vim8

Version: 0.4.2
Version: 0.4.3
Author : Masashi Iizuka <[email protected]>
License: MIT LICENSE

Expand Down Expand Up @@ -448,6 +448,18 @@ Commands *vim-iced-commands*
If {symbol} is not passed, symbol under cursor is used.
Key is mapped to |<Plug>(iced_source_show)|.

*:IcedGrimoireOpen*
:IcedGrimoireOpen [{symbol}]
Open a window, and show grimoire for {symbol}
If {symbol} is not passed, symbol under cursor is used.
Key is mapped to |<Plug>(iced_grimoire_open)|.

*:IcedCommandPalette*
:IcedCommandPalette
Select command from palette.
`ctrlp.vim` is required to select namespace.
Key is mapped to |<Plug>(iced_command_palette)|.

*:IcedSlurp*
:IcedSlurp
Slurp next element.
Expand Down Expand Up @@ -762,6 +774,14 @@ Key Mappings *vim-iced-key-mappings*
<Plug>(iced_source_show)
Same as |:IcedSourceShow|.

*<Plug>(iced_grimoire_open)*
<Plug>(iced_grimoire_open)
Same as |:IcedGrimoireOpen|.

*<Plug>(iced_command_palette)*
<Plug>(iced_command_palette)
Same as |:IcedCommandPalette|.

*<Plug>(iced_slurp)*
<Plug>(iced_slurp)
Same as |:IcedSlurp|.
Expand Down Expand Up @@ -1001,6 +1021,7 @@ g:iced_enable_default_key_mappings
<Leader>rml <Plug>(iced_move_to_let)
<Leader>hs <Plug>(iced_source_show)
<Leader>hg <Plug>(iced_grimoire_open)
<Leader>hh <Plug>(iced_command_palette)
<Leader>bn <Plug>(iced_browse_namespace)
<Leader>bf <Plug>(iced_browse_function)
<Leader>bs <Plug>(iced_browse_spec)
Expand Down
6 changes: 6 additions & 0 deletions ftplugin/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ command! IcedFormDocument call iced#nrepl#document#current_form()
command! IcedDocumentClose call iced#buffer#document#close()
command! -nargs=? IcedSourceShow call iced#nrepl#source#show(<q-args>)
command! -nargs=? IcedGrimoireOpen call iced#grimoire#open(<q-args>)
command! IcedCommandPalette call iced#palette#show()

command! IcedSlurp call iced#paredit#deep_slurp()
command! IcedBarf call iced#paredit#barf()
Expand Down Expand Up @@ -121,6 +122,7 @@ nnoremap <silent> <Plug>(iced_form_document) :<C-u>IcedFormDocument<CR>
nnoremap <silent> <Plug>(iced_document_close) :<C-u>IcedDocumentClose<CR>
nnoremap <silent> <Plug>(iced_source_show) :<C-u>IcedSourceShow<CR>
nnoremap <silent> <Plug>(iced_grimoire_open) :<C-u>IcedGrimoireOpen<CR>
nnoremap <silent> <Plug>(iced_command_palette) :<C-u>IcedCommandPalette<CR>
nnoremap <silent> <Plug>(iced_slurp) :<C-u>IcedSlurp<CR>
nnoremap <silent> <Plug>(iced_barf) :<C-u>IcedBarf<CR>
Expand Down Expand Up @@ -314,6 +316,10 @@ function! s:default_key_mappings() abort
silent! nmap <buffer> <Leader>hg <Plug>(iced_grimoire_open)
endif

if !hasmapto('<Plug>(iced_command_palette)')
silent! nmap <buffer> <Leader>hh <Plug>(iced_command_palette)
endif

if !hasmapto('<Plug>(iced_browse_namespace)')
silent! nmap <buffer> <Leader>bn <Plug>(iced_browse_namespace)
endif
Expand Down
2 changes: 2 additions & 0 deletions message/iced/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'start_to_trace': 'Start to trace: %s.',
'stop_to_trace': 'Stop to trace: %s.',
'untraced': 'Untraced.',
'ns_list_error': 'Failed to fetch ns list.',
'spec_list_error': 'Failed to fetch spec list.',
'spec_form_error': 'Failed to fetch spec form.',
'no_spec': 'No spec form is found.',
Expand All @@ -42,5 +43,6 @@
'search_hit_top': 'search hit TOP, continuing at BOTTOM...',
'search_hit_bottom': 'search hit BOTTOM, continuing at TOP...',
'used_locals_error': 'Failed to fetch used-locals.',
'canceled': 'Canceled.',
}
#vim:ft=ruby
Loading

0 comments on commit 413a13e

Please sign in to comment.