Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc/paredit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ added or deleted, they are entered or removed in pairs.
The function takes care of strings and comments, so no parenthesis and square
bracket balancing is performed inside a string or comment.
Please note that [] and {} pairs are not balanced for Lisp filetypes, only
for Clojure and Scheme.
for Clojure and Scheme by default.

The idea is taken from the paredit mode of Emacs, but not all paredit.el
editing functions are implemented or behave exactly the same way as they do
Expand Down Expand Up @@ -378,6 +378,9 @@ PAREDIT OPTIONS *paredit-options*

|g:paredit_electric_return| If nonzero, electric return feature is enabled.

|g:paredit_full_balancing| If nonzero, [] and {} are also balanced,
regardless of the language.

|g:paredit_smartjump| If nonzero, '(' and ')' also target square brackets
and curly braces when editing Clojure or Scheme.

Expand Down Expand Up @@ -414,6 +417,11 @@ to send the command line to the swank server for evaluation.
Please find a video demonstration of the electric return feature here:
http://img8.imageshack.us/img8/9479/openparen.gif

*g:paredit_full_balancing*
If nonzero, this option changes the default behavior of only balancing
'(' and ')' when the language is Clojure or Scheme. Therefore, in this option
'[', ']', '{', and '}' are also balanced regardless of the language.

*g:paredit_smartjump*
If nonzero, this option changes the behavior of '(' and ')' in normal and visual
modes when editing Clojure or Scheme. Rather than jumping to nearest open or close
Expand Down
25 changes: 15 additions & 10 deletions plugin/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if !exists( 'g:paredit_mode' )
let g:paredit_mode = 1
endif

" Enable [] and {} balancing outside Clojure and Scheme
if !exists( 'g:paredit_full_balancing' )
let g:paredit_full_balancing = 0
endif

" Match delimiter this number of lines before and after cursor position
if !exists( 'g:paredit_matchlines' )
let g:paredit_matchlines = 100
Expand Down Expand Up @@ -82,7 +87,7 @@ function! PareditInitBuffer()
let b:paredit_init = 1
" in case they are accidentally removed
" Also define regular expressions to identify special characters used by paredit
if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
let b:any_matched_char = '(\|)\|\[\|\]\|{\|}\|\"'
let b:any_matched_pair = '()\|\[\]\|{}\|\"\"'
let b:any_opening_char = '(\|\[\|{'
Expand Down Expand Up @@ -150,7 +155,7 @@ function! PareditInitBuffer()
execute 'nmap <buffer> <silent> ' . g:paredit_leader.'<Up> d[(,S'
execute 'nmap <buffer> <silent> ' . g:paredit_leader.'<Down> d])%,S'
call RepeatableNNoRemap(g:paredit_leader . 'I', ':<C-U>call PareditRaise()')
if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
inoremap <buffer> <expr> [ PareditInsertOpening('[',']')
inoremap <buffer> <silent> ] <C-R>=(pumvisible() ? "\<lt>C-Y>" : "")<CR><C-O>:let save_ve=&ve<CR><C-O>:set ve=all<CR><C-O>:<C-U>call PareditInsertClosing('[',']')<CR><C-O>:let &ve=save_ve<CR>
inoremap <buffer> <expr> { PareditInsertOpening('{','}')
Expand Down Expand Up @@ -219,7 +224,7 @@ function! PareditInitBuffer()
silent! unmap <buffer> cb
silent! unmap <buffer> ciw
silent! unmap <buffer> caw
if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
silent! iunmap <buffer> [
silent! iunmap <buffer> ]
silent! iunmap <buffer> {
Expand Down Expand Up @@ -251,7 +256,7 @@ endfunction
" Include all prefix and special characters in 'iskeyword'
function! s:SetKeyword()
let old_value = &iskeyword
if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
setlocal iskeyword+=+,-,*,/,%,<,=,>,:,$,?,!,@-@,94,~,#,\|,&
else
setlocal iskeyword+=+,-,*,/,%,<,=,>,:,$,?,!,@-@,94,~,#,\|,&,.,{,},[,]
Expand Down Expand Up @@ -574,7 +579,7 @@ function! s:IsBalanced()
return 0
endif

if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
let b1 = searchpair( '\[', '', '\]', 'brnmW', s:skip_sc, matchb )
let b2 = searchpair( '\[', '', '\]', 'rnmW', s:skip_sc, matchf )
if !(b1 == b2) && !(b1 == b2 - 1 && line[c-1] == '[') && !(b1 == b2 + 1 && line[c-1] == ']')
Expand Down Expand Up @@ -637,15 +642,15 @@ function! s:Unbalanced( matched )
while 1
let matched = tmp
let tmp = substitute( tmp, '(\(\s*\))', ' \1 ', 'g')
if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
let tmp = substitute( tmp, '\[\(\s*\)\]', ' \1 ', 'g')
let tmp = substitute( tmp, '{\(\s*\)}', ' \1 ', 'g')
endif
let tmp = substitute( tmp, '"\(\s*\)"', ' \1 ', 'g')
if tmp == matched
" All paired chars eliminated
let tmp = substitute( tmp, ')\(\s*\)(', ' \1 ', 'g')
if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
let tmp = substitute( tmp, '\]\(\s*\)\[', ' \1 ', 'g')
let tmp = substitute( tmp, '}\(\s*\){', ' \1 ', 'g')
endif
Expand Down Expand Up @@ -810,7 +815,7 @@ function! s:ReGatherUp()
normal! ddk
endwhile
normal! Jl
elseif g:paredit_electric_return && getline('.') =~ '^\s*\(\]\|}\)' && &ft =~ '.*\(clojure\|scheme\|racket\).*'
elseif g:paredit_electric_return && getline('.') =~ '^\s*\(\]\|}\)' && (&ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing)
" Re-gather electric returns in the current line for ']' and '}'
normal! k
while getline( line('.') ) =~ '^\s*$'
Expand Down Expand Up @@ -865,7 +870,7 @@ function! PareditInsertClosing( open, close )
normal! Jl
return
endif
if len(nextline) > 0 && nextline[0] =~ '\]\|}' && &ft =~ '.*\(clojure\|scheme\|racket\).*'
if len(nextline) > 0 && nextline[0] =~ '\]\|}' && (&ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing)
" Re-gather electric returns in the line of the closing ']' or '}'
call setline( line('.'), substitute( line, '\s*$', '', 'g' ) )
normal! Jxl
Expand Down Expand Up @@ -1495,7 +1500,7 @@ function! s:FindClosing()
endif
call setpos( '.', [0, l, c, 0] )

if &ft =~ '.*\(clojure\|scheme\|racket\).*'
if &ft =~ '.*\(clojure\|scheme\|racket\).*' || g:paredit_full_balancing
call PareditFindClosing( '[', ']', 0 )
let lp = line( '.' )
let cp = col( '.' )
Expand Down