Skip to content

Commit

Permalink
Merge pull request #147 from liquidz/dev
Browse files Browse the repository at this point in the history
ver 0.12.1
  • Loading branch information
liquidz authored Sep 13, 2019
2 parents e7d84e3 + 1b3f370 commit 5f95db1
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 74 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ jobs:
name: Install and deploy dev docs to netlify
command: |
npm install -g --silent netlify-cli
sleep 3
netlify deploy --auth=${NETLIFY_PERSONAL_ACCESS_TOKEN} --site=${NETLIFY_SITE_ID} --dir=target/html --prod
.circleci/scripts/deploy_to_netlify
docs-deploy:
docker:
Expand Down
21 changes: 21 additions & 0 deletions .circleci/scripts/deploy_to_netlify
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

for i in {1..5}; do
echo "Trying to deploy: ${i}"

netlify deploy \
--auth=${NETLIFY_PERSONAL_ACCESS_TOKEN} \
--site=${NETLIFY_SITE_ID} \
--dir=target/html \
--prod

if [ $? -eq 0 ]; then
echo "Succeeded to deploy"
exit 0
fi

sleep 1000
done

echo "Failed to deploy"
exit 1
22 changes: 22 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file. This change

== Unreleased (dev)

== 0.12.1 (2019-09-14)
// {{{
=== Added
* Add `g:iced#buffer#stdout#max_line` option.
** This option is a limit of line count in stdout buffer.
* Add `g:iced#buffer#stdout#deleting_line_delay` option.
* Add operation to evaluate codes and tap its results.
** `<Plug>(iced_eval_and_tap)`
* Add `:IcedInterruptAll` command.
* Add `:IcedJackIn` command.
** Add `g:iced#nrepl#connect#jack_in_command` option.
*** This option enables you to customize jack-in command.

=== Changed
* Bump cider-nrepl to 0.22.3.
* Bump iced-nrepl to 0.6.4.

=== Fixed
* Fix to extract ns-name correctly.
** Previously it was not working well for ns form with metadata.
// }}}

== 0.12.0 (2019-09-07)
// {{{
=== Changed
Expand Down
30 changes: 29 additions & 1 deletion autoload/iced/buffer/stdout.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,31 @@ let s:default_init_text = join([

let g:iced#buffer#stdout#init_text = get(g:, 'iced#buffer#stdout#init_text', s:default_init_text)
let g:iced#buffer#stdout#mods = get(g:, 'iced#buffer#stdout#mods', '')
let g:iced#buffer#stdout#max_line = get(g:, 'iced#buffer#stdout#max_line', 512)
let g:iced#buffer#stdout#max_line = get(g:, 'iced#buffer#stdout#max_line', -1)
let g:iced#buffer#stdout#deleting_line_delay = get(g:, 'iced#buffer#stdout#deleting_line_delay', 1000)
let g:iced#buffer#stdout#file = get(g:, 'iced#buffer#stdout#file', '')

function! s:delete_old_lines(_) abort
let bufnr = iced#buffer#nr(s:bufname)
let buflen = len(getbufline(bufnr, 0, '$'))
if g:iced#buffer#stdout#max_line > 0 && buflen > g:iced#buffer#stdout#max_line
let line_diff = buflen - g:iced#buffer#stdout#max_line
call iced#compat#deletebufline(bufnr, 1, line_diff)

if iced#buffer#stdout#is_visible()
let current_window = winnr()
try
call iced#buffer#stdout#focus()
let view = winsaveview()
let view['topline'] = max([1, view['topline'] - line_diff])
call winrestview(view)
finally
execute current_window . 'wincmd w'
endtry
endif
endif
endfunction

function! s:initialize(bufnr) abort
call setbufvar(a:bufnr, '&buflisted', 0)
call setbufvar(a:bufnr, '&buftype', 'nofile')
Expand Down Expand Up @@ -42,6 +64,7 @@ function! iced#buffer#stdout#open() abort
\ 'scroll_to_bottom': v:true})
endfunction

let s:delete_timer_id = -1
function! iced#buffer#stdout#append(s) abort
let s = iced#util#delete_color_code(a:s)
if !empty(g:iced#buffer#stdout#file)
Expand All @@ -52,6 +75,11 @@ function! iced#buffer#stdout#append(s) abort
\ s:bufname,
\ s,
\ {'scroll_to_bottom': v:true})

if s:delete_timer_id != -1 | call timer_stop(s:delete_timer_id) | endif
let s:delete_timer_id = timer_start(
\ g:iced#buffer#stdout#deleting_line_delay,
\ funcref('s:delete_old_lines'))
endfunction

function! iced#buffer#stdout#clear() abort
Expand Down
8 changes: 8 additions & 0 deletions autoload/iced/compat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ function! iced#compat#job_stop(job_id) abort
endif
endfunction

function! iced#compat#is_job_id(x) abort
if has('nvim')
return type(a:x) == v:t_number && a:x > 0
else
return type(a:x) == v:t_job
endif
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo
14 changes: 13 additions & 1 deletion autoload/iced/nrepl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ function! s:warm_up() abort
" load util files
let load_dir = printf('%s/clj/load_files', g:vim_iced_home)
for path in glob(printf('%s/*.clj', load_dir), v:true, v:true)
echom printf('FIXME %s', path)
call iced#nrepl#send({
\ 'id': iced#nrepl#id(),
\ 'op': 'load-file',
Expand Down Expand Up @@ -416,6 +415,7 @@ function! iced#nrepl#disconnect() abort " {{{
let s:nrepl = s:initialize_nrepl()
call iced#cache#clear()
call iced#nrepl#cljs#reset()
call iced#nrepl#connect#reset()
call iced#message#info('disconnected')
endfunction " }}}

Expand Down Expand Up @@ -489,6 +489,18 @@ function! s:interrupted() abort
call iced#message#info('interrupted')
endfunction

function! iced#nrepl#interrupt_all() abort
let ids = iced#nrepl#sync#session_list()
if type(ids) != v:t_list | return | endif
for id in ids
call iced#nrepl#sync#send({'op': 'interrupt', 'session': id})
endfor

" NOTE: ignore reading error
let s:response_buffer = ''
call s:clear_messages()
endfunction

function! iced#nrepl#interrupt(...) abort
if ! iced#nrepl#is_connected() | return iced#message#warning('not_connected') | endif
let session = get(a:, 1, iced#nrepl#current_session())
Expand Down
10 changes: 9 additions & 1 deletion autoload/iced/nrepl/auto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ function! iced#nrepl#auto#bufenter() abort
if !iced#nrepl#is_connected() | return | endif
call s:auto_switching_session()
" eval `in-ns` automatically
" NOTE: Do not use `iced#nrepl#ns#in` here
" because ns-name by `*in*` var may be different in new buffer.
if ! iced#nrepl#check_session_validity(v:false) | return | endif
call iced#nrepl#ns#in()
let ns_name = iced#nrepl#ns#name_by_buf()
let ns_name = (empty(ns_name))
\ ? iced#nrepl#ns#name_by_var(iced#nrepl#repl_session())
\ : ns_name
if !empty(ns_name)
call iced#nrepl#eval(printf('(in-ns ''%s)', ns_name), {_ -> ''})
endif
endfunction

function! iced#nrepl#auto#bufread() abort
Expand Down
75 changes: 62 additions & 13 deletions autoload/iced/nrepl/connect.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ let s:save_cpo = &cpoptions
set cpoptions&vim

let s:nrepl_port_file = '.nrepl-port'
let s:jack_in_job = -1

let g:iced#nrepl#connect#jack_in_command = get(g:, 'iced#nrepl#connect#jack_in_command', 'iced repl')

function! s:detect_port_from_nrepl_port_file() abort
let path = findfile(s:nrepl_port_file, '.;')
return (empty(path)
\ ? v:false
\ : str2nr(readfile(path)[0]))
if empty(path)
return v:false
else
let lines = readfile(path)
return (empty(lines))
\ ? v:false
\ : str2nr(lines[0])
endif
endfunction

function! s:detect_shadow_cljs_nrepl_port() abort
Expand All @@ -20,7 +28,8 @@ function! s:detect_shadow_cljs_nrepl_port() abort
\ : str2nr(readfile(path)[0]))
endfunction

function! iced#nrepl#connect#auto() abort
function! iced#nrepl#connect#auto(...) abort
let verbose = get(a:, 1, v:true)
let port = s:detect_shadow_cljs_nrepl_port()

if !port
Expand All @@ -32,31 +41,71 @@ function! iced#nrepl#connect#auto() abort
return v:true
endif

call iced#message#error('no_port_file')
if verbose | call iced#message#error('no_port_file') | endif
return v:false
endfunction

function! s:instant_repl_callback(_, out) abort
function! s:wait_for_auto_connection(id) abort
if iced#nrepl#connect#auto(v:false)
call iced#di#get('timer').stop(a:id)
endif
endfunction

function! s:jack_in_callback(_, out) abort
let connected = iced#nrepl#is_connected()

for line in iced#util#ensure_array(a:out)
if empty(line) | continue | endif
let line = iced#util#delete_color_code(line)
echo line
if stridx(line, 'nREPL server started') != -1 && !iced#nrepl#is_connected()
call iced#util#future(function('iced#nrepl#connect#auto'))

if connected
call iced#buffer#stdout#append(line)
else
echo line
"" NOTE: Leiningen, Boot and Clojure CLI print the same text like below.
if stridx(line, 'nREPL server started') != -1 && !iced#nrepl#is_connected()
call iced#di#get('timer').start(
\ 500,
\ funcref('s:wait_for_auto_connection'),
\ {'repeat': 10})
endif
endif
endfor
endfunction

function! iced#nrepl#connect#instant() abort
function! iced#nrepl#connect#jack_in(...) abort
if iced#nrepl#is_connected()
return iced#message#info('already_connected')
endif

if !executable('iced')
return iced#message#error('not_executable', 'iced')
endif

if iced#compat#is_job_id(s:jack_in_job)
return iced#message#error('already_running')
endif

let command = get(a:, 1, g:iced#nrepl#connect#jack_in_command)
let s:jack_in_job = iced#compat#job_start(command, {
\ 'out_cb': funcref('s:jack_in_callback'),
\ })
endfunction

function! iced#nrepl#connect#instant() abort
if !executable('clojure')
return iced#message#error('not_executable', 'clojure')
endif

call iced#compat#job_start('iced repl --instant', {
\ 'out_cb': funcref('s:instant_repl_callback'),
\ })
call iced#nrepl#connect#jack_in('iced repl --instant')
endfunction

function! iced#nrepl#connect#reset() abort
if iced#compat#is_job_id(s:jack_in_job)
call iced#compat#job_stop(s:jack_in_job)
endif

let s:jack_in_job = -1
endfunction

let &cpoptions = s:save_cpo
Expand Down
43 changes: 26 additions & 17 deletions autoload/iced/nrepl/ns.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let s:save_cpo = &cpo
set cpo&vim
let s:save_cpo = &cpoptions
set cpoptions&vim

let s:V = vital#iced#new()
let s:D = s:V.import('Data.Dict')
Expand All @@ -23,7 +23,7 @@ function! iced#nrepl#ns#get() abort
return code
endfunction

function! s:ns_name_by_var(...) abort
function! iced#nrepl#ns#name_by_var(...) abort
let session = get(a:, 1, iced#nrepl#current_session())
let resp = iced#nrepl#sync#eval('*ns*', {'session_id': session})
if type(resp) != v:t_dict || !has_key(resp, 'value')
Expand All @@ -32,30 +32,39 @@ function! s:ns_name_by_var(...) abort
return iced#nrepl#ns#util#extract_ns(resp['value'])
endfunction

function! iced#nrepl#ns#name() abort
function! iced#nrepl#ns#name_by_buf() abort
let view = winsaveview()
let reg_save = @@

try
if iced#nrepl#ns#util#search() == 0
let ns_name = s:ns_name_by_var()
if empty(ns_name)
call iced#message#error('ns_not_found')
return
endif
return ns_name
return ''
endif

" Move to next element head
silent normal! l
call sexp#move_to_adjacent_element('n', 0, 1, 0, 0)

" skip meta
let p = getcurpos()
if searchpos('\^', 'cn') == [p[1], p[2]]
call sexp#move_to_adjacent_element('n', 0, 1, 0, 0)
endif
let start = line('.')
let line = trim(join(getline(start, start+1), ' '))
let line = substitute(line, '(ns ', '', '')
return matchstr(line, '[a-z0-9.\-]\+',
\ (stridx(line, '^') == 0 ? stridx(line, ' ') : 0))

return matchstr(getline('.'), '[a-z0-9.\-]\+', col('.') - 1)
finally
let @@ = reg_save
call winrestview(view)
endtry
endfunction

function! iced#nrepl#ns#name() abort
let ns_name = iced#nrepl#ns#name_by_buf()
return (empty(ns_name))
\ ? iced#nrepl#ns#name_by_var()
\ : ns_name
endfunction

function! iced#nrepl#ns#eval(callback) abort
let code = iced#nrepl#ns#get()
if empty(code)
Expand Down Expand Up @@ -144,7 +153,7 @@ function! iced#nrepl#ns#in_repl_session_ns() abort
return iced#message#error('invalid_session', 'clj')
endif

let ns_name = s:ns_name_by_var(iced#nrepl#repl_session())
let ns_name = iced#nrepl#ns#name_by_var(iced#nrepl#repl_session())
if empty(ns_name)
call iced#message#warn('not_found')
return
Expand Down Expand Up @@ -192,5 +201,5 @@ function! iced#nrepl#ns#find_existing_alias(ns_name) abort
return ''
endfunction

let &cpo = s:save_cpo
let &cpoptions = s:save_cpo
unlet s:save_cpo
4 changes: 4 additions & 0 deletions autoload/iced/operation.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function! iced#operation#eval_and_print(type) abort
return s:eval({code -> iced#nrepl#eval#code(code, opt)})
endfunction

function! iced#operation#eval_and_tap(type) abort
return s:eval({code -> iced#nrepl#eval#code(printf('(clojure.core/tap> %s)', code))})
endfunction

function! iced#operation#eval_repl(type) abort
let view = winsaveview()
let reg_save = @@
Expand Down
Loading

0 comments on commit 5f95db1

Please sign in to comment.