Skip to content

Commit

Permalink
Merge pull request #454 from liquidz/next_release
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
liquidz authored Dec 28, 2022
2 parents 6d7b3d0 + 856e6e3 commit eacea6a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of http://keepachangelog.com/[keepachangelog.com].

== Unreleased (dev)
// {{{
=== Fixed
* https://github.com/liquidz/vim-iced/issues/453[#453]: Fixed `IcedCleanNs` command to reform `ns` form even if there are no changes.
// }}}

== 3.14.3192 (2022-12-24)
// {{{
Expand Down
45 changes: 44 additions & 1 deletion autoload/iced/nrepl/refactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,56 @@ function! iced#nrepl#refactor#extract_function() abort
endfunction " }}}

" iced#nrepl#refactor#clean_ns {{{
function! s:unify_ns_form() abort
" NOTE:
" When g:iced#refactor#insert_newline_after_require is true,
" refactor-nrepl's clean-ns op returns ns form including newline after require.
" But if there are no changes in ns form, clean-ns op returns empty string as ns.
" Thus, when there is no newline after require and there are no changes in ns form,
" the newline after require won't be added.
"
" To unify these behaviors, even if there are no changes in ns form,
" vim-iced will add a newline after require while
" g:iced#refactor#insert_newline_after_require is true.
"
" cf. https://github.com/liquidz/vim-iced/issues/453
if ! g:iced#refactor#insert_newline_after_require
return v:false
endif

let ns_form = iced#nrepl#ns#get()
let idx = stridx(ns_form, ':require')
if idx == -1
return v:false
endif

let idx = idx + len(':require')
if ns_form[idx] !=# ' '
return v:false
endif

let new_ns_form = printf("%s\n%s", trim(strpart(ns_form, 0, idx)), trim(strpart(ns_form, idx)))
let context = iced#util#save_context()
try
call iced#nrepl#ns#util#replace(new_ns_form)
finally
call iced#util#restore_context(context)
endtry

return v:true
endfunction

function! s:clean_ns(resp) abort
if has_key(a:resp, 'error')
return iced#nrepl#eval#err(a:resp['error'])
endif
if has_key(a:resp, 'ns')
if empty(a:resp['ns'])
return iced#message#info('already_clean')
if s:unify_ns_form()
return iced#message#info('already_clean_but_reform')
else
return iced#message#info('already_clean')
endif
endif

let context = iced#util#save_context()
Expand Down
1 change: 1 addition & 0 deletions message/iced/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'all_ns_loading': 'Loading all namespaces...',
'all_reloaded': 'All reloaded.',
'already_clean': 'Already clean.',
'already_clean_but_reform': 'Already clean, but ns form is reformed.',
'already_connected': 'Already connected.',
'already_in_test_ns': 'Already in test namespace.',
'already_running': 'Already running.',
Expand Down

0 comments on commit eacea6a

Please sign in to comment.