blob: 3cd0cb8e2b008a0315ccc15001a4debd7bcbe9b2 [file] [log] [blame]
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02001" Vim filetype plugin
2" Language: J
Bram Moolenaar09c6f262019-11-17 15:55:14 +01003" Maintainer: David Bürgin <dbuergin@gluet.ch>
4" URL: https://gitlab.com/glts/vim-j
5" Last Change: 2015-10-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
Bram Moolenaar60cce2f2015-10-13 23:21:27 +020015setlocal 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 Moolenaar60cce2f2015-10-13 23:21:27 +020020setlocal path-=/usr/include
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020021
Bram Moolenaar60cce2f2015-10-13 23:21:27 +020022" Includes. To make the shorthand form "require 'web/cgi'" work, double the
23" last path component. Also strip off leading folder names like "~addons/".
24setlocal include=\\v^\\s*(load\|require)\\s*'\\zs\\f+\\ze'
25setlocal includeexpr=substitute(substitute(tr(v:fname,'\\','/'),'\\v^[^~][^/.]*(/[^/.]+)$','&\\1',''),'\\v^\\~[^/]+/','','')
26setlocal suffixesadd=.ijs
27
Bram Moolenaar09c6f262019-11-17 15:55:14 +010028let b:undo_ftplugin = 'setlocal suffixesadd< includeexpr< include< path< matchpairs< formatoptions< commentstring< comments< iskeyword<'
Bram Moolenaar75b81562014-04-06 14:09:13 +020029
30" Section movement with ]] ][ [[ []. The start/end patterns below are amended
31" inside the function in order to avoid matching on the current cursor line.
Bram Moolenaar83caecf2015-01-14 19:42:21 +010032let 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 +020033let s:sectionend = '\s*)\s*'
34
35function! s:SearchSection(end, backwards, visualmode) abort
36 if a:visualmode !=# ''
37 normal! gv
38 endif
Bram Moolenaar83caecf2015-01-14 19:42:21 +010039 let l:flags = a:backwards ? 'bsW' : 'sW'
Bram Moolenaar75b81562014-04-06 14:09:13 +020040 if a:end
Bram Moolenaar83caecf2015-01-14 19:42:21 +010041 call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
Bram Moolenaar75b81562014-04-06 14:09:13 +020042 else
Bram Moolenaar83caecf2015-01-14 19:42:21 +010043 call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
Bram Moolenaar75b81562014-04-06 14:09:13 +020044 endif
45endfunction
46
Bram Moolenaar83caecf2015-01-14 19:42:21 +010047noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
48xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020049sunmap <buffer> ]]
Bram Moolenaar83caecf2015-01-14 19:42:21 +010050noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
51xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020052sunmap <buffer> ][
Bram Moolenaar83caecf2015-01-14 19:42:21 +010053noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
54xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020055sunmap <buffer> [[
Bram Moolenaar83caecf2015-01-14 19:42:21 +010056noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
57xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
Bram Moolenaar75b81562014-04-06 14:09:13 +020058sunmap <buffer> []
59
60let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
61 \ . ' | silent! execute "unmap <buffer> ]["'
62 \ . ' | silent! execute "unmap <buffer> [["'
63 \ . ' | silent! execute "unmap <buffer> []"'
64
65" Browse dialog filter on Windows (see ":help browsefilter")
66if has('gui_win32') && !exists('b:browsefilter')
67 let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
68 \ . "All Files (*.*)\t*.*\n"
69 let b:undo_ftplugin .= ' | unlet! b:browsefilter'
70endif
71
72" Enhanced "%" matching (see ":help matchit")
73if exists('loaded_matchit') && !exists('b:match_words')
74 let b:match_ignorecase = 0
Bram Moolenaar83caecf2015-01-14 19:42:21 +010075 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 +020076 \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
77 let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
78endif
79
80let &cpo = s:save_cpo
81unlet s:save_cpo