Skip to content

Commit

Permalink
Fix not to break code finding with parentheses in comment #277
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Oct 13, 2020
1 parent 3e6fa6e commit 4de36d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
10 changes: 7 additions & 3 deletions autoload/iced/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ function! iced#paredit#get_current_top_object_raw(...) abort

call setpos('.', start_pos)
" move to pair
silent normal! %
" NOTE: `%` may be matched to parentheses in comment block without matchit.vim
silent exe "normal \<Plug>(sexp_move_to_next_bracket)"
let end_pos = getcurpos()

if s:is_in_range(pos, start_pos, end_pos)
" select end_pos to start_pos
call setpos('.', end_pos)
silent exe 'normal! v'
call setpos('.', start_pos)
" NOTE: `o0y` is to wrap top level tag literal
silent exe printf('normal! va%so0y', open_char)
" NOTE: `0` is to wrap top level tag literal
silent exe 'normal! 0y'

let result = {
\ 'code': @@,
Expand Down
5 changes: 5 additions & 0 deletions test/helper/autoload/themis/helper/iced_buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function! s:helper.start_dummy(lines) abort
setl nobuflisted
setl filetype=clojure

" copy from runtime/syntax/clojure.vim
" required by <Plug>(sexp_move_to_next_bracket)
syntax match clojureComment ";.*$"
syntax match clojureComment "#!.*$"

let i = 1
let cursor_pos = [1, 1]
for line in a:lines
Expand Down
14 changes: 14 additions & 0 deletions test/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ let s:buf = themis#helper('iced_buffer')
let s:ch = themis#helper('iced_channel')
let s:funcs = s:scope.funcs('autoload/iced/nrepl.vim')

let g:iced_enable_clj_kondo_analysis = v:false
let g:iced_cache_directory = ''

function! s:format_code_relay(msg) abort
if a:msg['op'] ==# 'iced-format-code-with-indents'
return {'status': ['done'], 'formatted': a:msg['code']}
Expand Down Expand Up @@ -73,6 +76,17 @@ function! s:suite.get_current_top_object_with_tag_test() abort
call s:buf.stop_dummy()
endfunction

function! s:suite.get_current_top_object_with_comment_test() abort
call s:buf.start_dummy([
\ '(foo',
\ ' ;; baz)',
\ ' (bar|))',
\ ])
let res = iced#paredit#get_current_top_object()
call s:assert.equals(res['code'], "(foo\n ;; baz)\n (bar))")
call s:buf.stop_dummy()
endfunction

function! s:suite.move_to_current_element_head_test() abort
call s:buf.start_dummy(['(foo (bar (baz|)))'])
call s:assert.equals(col('.'), 15)
Expand Down

0 comments on commit 4de36d7

Please sign in to comment.