xref: /vim-8.2.3635/runtime/ftplugin/j.vim (revision fc39ecf8)
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-03-27
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 matchpairs=(:)
20
21let b:undo_ftplugin = 'setlocal matchpairs< formatoptions< commentstring< comments< iskeyword<'
22
23" Section movement with ]] ][ [[ []. The start/end patterns below are amended
24" inside the function in order to avoid matching on the current cursor line.
25let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
26let s:sectionend = '\s*)\s*'
27
28function! s:SearchSection(end, backwards, visualmode) abort
29  if a:visualmode !=# ''
30    normal! gv
31  endif
32  let l:flags = a:backwards ? 'bsW' : 'sW'
33  if a:end
34    call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
35  else
36    call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
37  endif
38endfunction
39
40noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
41xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
42sunmap <buffer> ]]
43noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
44xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
45sunmap <buffer> ][
46noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
47xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
48sunmap <buffer> [[
49noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
50xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
51sunmap <buffer> []
52
53let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
54                   \ . ' | silent! execute "unmap <buffer> ]["'
55                   \ . ' | silent! execute "unmap <buffer> [["'
56                   \ . ' | silent! execute "unmap <buffer> []"'
57
58" Browse dialog filter on Windows (see ":help browsefilter")
59if has('gui_win32') && !exists('b:browsefilter')
60  let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
61                   \ . "All Files (*.*)\t*.*\n"
62  let b:undo_ftplugin .= ' | unlet! b:browsefilter'
63endif
64
65" Enhanced "%" matching (see ":help matchit")
66if exists('loaded_matchit') && !exists('b:match_words')
67  let b:match_ignorecase = 0
68  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*$'
69                  \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
70  let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
71endif
72
73let &cpo = s:save_cpo
74unlet s:save_cpo
75