xref: /vim-8.2.3635/runtime/ftplugin/j.vim (revision 83caecf3)
1" Vim filetype plugin
2" Language:	J
3" Maintainer:	David Bürgin <[email protected]>
4" URL:		https://github.com/glts/vim-j
5" Last Change:	2015-01-11
6
7if exists('b:did_ftplugin')
8  finish
9endif
10let b:did_ftplugin = 1
11
12let s:save_cpo = &cpo
13set cpo&vim
14
15setlocal iskeyword=48-57,A-Z,_,a-z
16setlocal comments=:NB.
17setlocal commentstring=NB.\ %s
18setlocal formatoptions-=t
19setlocal shiftwidth=2
20setlocal softtabstop=2
21setlocal expandtab
22setlocal matchpairs=(:)
23
24let b:undo_ftplugin = 'setlocal matchpairs< expandtab< softtabstop< shiftwidth< formatoptions< commentstring< comments< iskeyword<'
25
26" Section movement with ]] ][ [[ []. The start/end patterns below are amended
27" inside the function in order to avoid matching on the current cursor line.
28let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
29let s:sectionend = '\s*)\s*'
30
31function! s:SearchSection(end, backwards, visualmode) abort
32  if a:visualmode !=# ''
33    normal! gv
34  endif
35  let l:flags = a:backwards ? 'bsW' : 'sW'
36  if a:end
37    call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
38  else
39    call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
40  endif
41endfunction
42
43noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
44xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
45sunmap <buffer> ]]
46noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
47xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
48sunmap <buffer> ][
49noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
50xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
51sunmap <buffer> [[
52noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
53xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
54sunmap <buffer> []
55
56let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
57                   \ . ' | silent! execute "unmap <buffer> ]["'
58                   \ . ' | silent! execute "unmap <buffer> [["'
59                   \ . ' | silent! execute "unmap <buffer> []"'
60
61" Browse dialog filter on Windows (see ":help browsefilter")
62if has('gui_win32') && !exists('b:browsefilter')
63  let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
64                   \ . "All Files (*.*)\t*.*\n"
65  let b:undo_ftplugin .= ' | unlet! b:browsefilter'
66endif
67
68" Enhanced "%" matching (see ":help matchit")
69if exists('loaded_matchit') && !exists('b:match_words')
70  let b:match_ignorecase = 0
71  let b:match_words = '^\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(\:\s*0\|def\s\+0\|define\)\)\>:^\s*\:\s*$:^\s*)\s*$'
72                  \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
73  let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
74endif
75
76let &cpo = s:save_cpo
77unlet s:save_cpo
78