Skip to content

Commit

Permalink
Update GetIcedIndent to fallback to GetClojureIndent #64
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Dec 17, 2018
1 parent b8a1d42 commit 7ea75a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
7 changes: 4 additions & 3 deletions autoload/iced/format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ endfunction

function! iced#format#calculate_indent(lnum) abort
if !iced#nrepl#is_connected()
return -1
return GetClojureIndent()
endif

if ! s:is_indentation_rule_setted
Expand All @@ -104,18 +104,19 @@ function! iced#format#calculate_indent(lnum) abort
let res = iced#paredit#get_current_top_list(2)
let code = res['code']
if iced#compat#trim(code) ==# ''
return 0
return GetClojureIndent()
endif

let start_line = res['curpos'][1]
let start_column = res['curpos'][2] - 1
let target_lnum = a:lnum - start_line

let resp = iced#nrepl#op#iced#sync#calculate_indent_level(code, target_lnum, iced#nrepl#ns#alias_dict(ns_name))
echom printf('FIXME %s', resp)
if has_key(resp, 'indent-level') && type(resp['indent-level']) == type(1)
return resp['indent-level'] + start_column
else
return -1
return GetClojureIndent()
endif
finally
let @@ = reg_save
Expand Down
19 changes: 5 additions & 14 deletions indent/clojure.vim
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
let g:iced_enable_auto_indent = get(g:, 'iced_enable_auto_indent', v:true)
if exists('b:did_indent') || !g:iced_enable_auto_indent
finish
endif

setlocal autoindent
setlocal indentexpr=GetIcedIndent()
setlocal indentkeys=!^F,o,O

setlocal expandtab
setlocal tabstop<
setlocal softtabstop=2
setlocal shiftwidth=2
let s:save_cpo = &cpo
set cpo&vim

" NOTE: setting indentexpr is executed at nREPL connection
function! GetIcedIndent()
return iced#format#calculate_indent(v:lnum)
endfunction

let b:did_indent = 1
let &cpo = s:save_cpo
unlet s:save_cpo
6 changes: 5 additions & 1 deletion test/format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ let s:assert = themis#helper('assert')
let s:ch = themis#helper('iced_channel')
let s:buf = themis#helper('iced_buffer')

function! GetClojureIndent() abort
return -1
endfunction

function! s:format_code_relay(msg, formatted) abort
if a:msg['op'] ==# 'iced-format-code-with-indents'
return {'status': ['done'], 'formatted': a:formatted}
Expand Down Expand Up @@ -82,7 +86,7 @@ function! s:suite.calculate_indent_without_corresponding_form_test() abort
\ '|',
\ ])
let result = iced#format#calculate_indent(line('.'))
call s:assert.equals(result, 0)
call s:assert.equals(result, GetClojureIndent())

call s:buf.stop_dummy()
endfunction

0 comments on commit 7ea75a9

Please sign in to comment.