blob: 774696836f8eae13d2af818ec8f56a3543876e8a [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 Moolenaar5a5f4592015-04-13 12:43:06 +02005" Last Change: 2015-03-27
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 Moolenaard5d015d2013-11-03 21:14:31 +010019setlocal matchpairs=(:)
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020020
Bram Moolenaar5a5f4592015-04-13 12:43:06 +020021let b:undo_ftplugin = 'setlocal matchpairs< formatoptions< commentstring< comments< iskeyword<'
Bram Moolenaar75b81562014-04-06 14:09:13 +020022
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.
Bram Moolenaar83caecf2015-01-14 19:42:21 +010025let 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 +020026let s:sectionend = '\s*)\s*'
27
28function! s:SearchSection(end, backwards, visualmode) abort
29 if a:visualmode !=# ''
30 normal! gv
31 endif
Bram Moolenaar83caecf2015-01-14 19:42:21 +010032 let l:flags = a:backwards ? 'bsW' : 'sW'
Bram Moolenaar75b81562014-04-06 14:09:13 +020033 if a:end
Bram Moolenaar83caecf2015-01-14 19:42:21 +010034 call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
Bram Moolenaar75b81562014-04-06 14:09:13 +020035 else
Bram Moolenaar83caecf2015-01-14 19:42:21 +010036 call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
Bram Moolenaar75b81562014-04-06 14:09:13 +020037 endif
38endfunction
39
Bram Moolenaar83caecf2015-01-14 19:42:21 +010040noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
41xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020042sunmap <buffer> ]]
Bram Moolenaar83caecf2015-01-14 19:42:21 +010043noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
44xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 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(0, 1, '')<CR>
47xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, 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(1, 1, '')<CR>
50xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020051sunmap <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
Bram Moolenaar83caecf2015-01-14 19:42:21 +010068 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 +020069 \ . ',\<\%(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