blob: 71ac4c54188ae10d0497e7e2ee639450bcd87e47 [file] [log] [blame]
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02001" Vim filetype plugin
2" Language: J
3" Maintainer: David Bürgin <676c7473@gmail.com>
Bram Moolenaara6878372014-03-22 21:02:50 +01004" URL: https://github.com/glts/vim-j
Bram Moolenaar83caecf2015-01-14 19:42:21 +01005" Last Change: 2015-01-11
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02006
Bram Moolenaara6878372014-03-22 21:02:50 +01007if exists('b:did_ftplugin')
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02008 finish
9endif
10let b:did_ftplugin = 1
11
Bram Moolenaar75b81562014-04-06 14:09:13 +020012let s:save_cpo = &cpo
13set cpo&vim
14
15setlocal iskeyword=48-57,A-Z,_,a-z
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020016setlocal comments=:NB.
17setlocal commentstring=NB.\ %s
Bram Moolenaard5d015d2013-11-03 21:14:31 +010018setlocal formatoptions-=t
Bram Moolenaar83caecf2015-01-14 19:42:21 +010019setlocal shiftwidth=2
20setlocal softtabstop=2
21setlocal expandtab
Bram Moolenaard5d015d2013-11-03 21:14:31 +010022setlocal matchpairs=(:)
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020023
Bram Moolenaara6878372014-03-22 21:02:50 +010024let b:undo_ftplugin = 'setlocal matchpairs< expandtab< softtabstop< shiftwidth< formatoptions< commentstring< comments< iskeyword<'
Bram Moolenaar75b81562014-04-06 14:09:13 +020025
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.
Bram Moolenaar83caecf2015-01-14 19:42:21 +010028let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
Bram Moolenaar75b81562014-04-06 14:09:13 +020029let s:sectionend = '\s*)\s*'
30
31function! s:SearchSection(end, backwards, visualmode) abort
32 if a:visualmode !=# ''
33 normal! gv
34 endif
Bram Moolenaar83caecf2015-01-14 19:42:21 +010035 let l:flags = a:backwards ? 'bsW' : 'sW'
Bram Moolenaar75b81562014-04-06 14:09:13 +020036 if a:end
Bram Moolenaar83caecf2015-01-14 19:42:21 +010037 call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
Bram Moolenaar75b81562014-04-06 14:09:13 +020038 else
Bram Moolenaar83caecf2015-01-14 19:42:21 +010039 call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
Bram Moolenaar75b81562014-04-06 14:09:13 +020040 endif
41endfunction
42
Bram Moolenaar83caecf2015-01-14 19:42:21 +010043noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
44xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020045sunmap <buffer> ]]
Bram Moolenaar83caecf2015-01-14 19:42:21 +010046noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
47xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020048sunmap <buffer> ][
Bram Moolenaar83caecf2015-01-14 19:42:21 +010049noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
50xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020051sunmap <buffer> [[
Bram Moolenaar83caecf2015-01-14 19:42:21 +010052noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
53xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020054sunmap <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
Bram Moolenaar83caecf2015-01-14 19:42:21 +010071 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*$'
Bram Moolenaar75b81562014-04-06 14:09:13 +020072 \ . ',\<\%(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