blob: ae235abba8ac6ccd34505310d90994996d888a8d [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
Bram Moolenaare8008642022-08-19 17:15:35 +01005" Last Change: 2022-08-06
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 Moolenaare8008642022-08-19 17:15:35 +010032if !exists('no_plugin_maps') && !exists('no_j_maps')
33 let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
34 let s:sectionend = '\s*)\s*'
Bram Moolenaar75b81562014-04-06 14:09:13 +020035
Bram Moolenaare8008642022-08-19 17:15:35 +010036 function! s:SearchSection(end, backwards, visualmode) abort
37 if a:visualmode !=# ''
38 normal! gv
39 endif
40 let l:flags = a:backwards ? 'bsW' : 'sW'
41 if a:end
42 call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
43 else
44 call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
45 endif
46 endfunction
Bram Moolenaar75b81562014-04-06 14:09:13 +020047
Bram Moolenaare8008642022-08-19 17:15:35 +010048 noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
49 xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
50 sunmap <buffer> ]]
51 noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
52 xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
53 sunmap <buffer> ][
54 noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
55 xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
56 sunmap <buffer> [[
57 noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
58 xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
59 sunmap <buffer> []
Bram Moolenaar75b81562014-04-06 14:09:13 +020060
Bram Moolenaare8008642022-08-19 17:15:35 +010061 let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
62 \ . ' | silent! execute "unmap <buffer> ]["'
63 \ . ' | silent! execute "unmap <buffer> [["'
64 \ . ' | silent! execute "unmap <buffer> []"'
65endif
Bram Moolenaar75b81562014-04-06 14:09:13 +020066
Bram Moolenaare8008642022-08-19 17:15:35 +010067" Browse dialog filter on Windows and GTK (see ":help browsefilter")
68if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
Bram Moolenaar75b81562014-04-06 14:09:13 +020069 let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
70 \ . "All Files (*.*)\t*.*\n"
71 let b:undo_ftplugin .= ' | unlet! b:browsefilter'
72endif
73
74" Enhanced "%" matching (see ":help matchit")
75if exists('loaded_matchit') && !exists('b:match_words')
76 let b:match_ignorecase = 0
Bram Moolenaar83caecf2015-01-14 19:42:21 +010077 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 +020078 \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
79 let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
80endif
81
82let &cpo = s:save_cpo
83unlet s:save_cpo