blob: 8335ea06c6bb286db94d8158b633464f0a49db9c [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
Doug Kearns93197fd2024-01-14 20:59:02 +01006" 2024 Jan 14 by Vim Project (browsefilter)
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02007
Bram Moolenaara6878372014-03-22 21:02:50 +01008if exists('b:did_ftplugin')
Bram Moolenaarbaca7f72013-09-22 14:42:24 +02009 finish
10endif
11let b:did_ftplugin = 1
12
Bram Moolenaar75b81562014-04-06 14:09:13 +020013let s:save_cpo = &cpo
14set cpo&vim
15
Bram Moolenaar60cce2f2015-10-13 23:21:27 +020016setlocal iskeyword=48-57,A-Z,a-z,_
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020017setlocal comments=:NB.
18setlocal commentstring=NB.\ %s
Bram Moolenaard5d015d2013-11-03 21:14:31 +010019setlocal formatoptions-=t
Bram Moolenaard5d015d2013-11-03 21:14:31 +010020setlocal matchpairs=(:)
Bram Moolenaar60cce2f2015-10-13 23:21:27 +020021setlocal path-=/usr/include
Bram Moolenaarbaca7f72013-09-22 14:42:24 +020022
Bram Moolenaar60cce2f2015-10-13 23:21:27 +020023" Includes. To make the shorthand form "require 'web/cgi'" work, double the
24" last path component. Also strip off leading folder names like "~addons/".
25setlocal include=\\v^\\s*(load\|require)\\s*'\\zs\\f+\\ze'
26setlocal includeexpr=substitute(substitute(tr(v:fname,'\\','/'),'\\v^[^~][^/.]*(/[^/.]+)$','&\\1',''),'\\v^\\~[^/]+/','','')
27setlocal suffixesadd=.ijs
28
Bram Moolenaar09c6f262019-11-17 15:55:14 +010029let b:undo_ftplugin = 'setlocal suffixesadd< includeexpr< include< path< matchpairs< formatoptions< commentstring< comments< iskeyword<'
Bram Moolenaar75b81562014-04-06 14:09:13 +020030
31" Section movement with ]] ][ [[ []. The start/end patterns below are amended
32" inside the function in order to avoid matching on the current cursor line.
Bram Moolenaare8008642022-08-19 17:15:35 +010033if !exists('no_plugin_maps') && !exists('no_j_maps')
34 let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
35 let s:sectionend = '\s*)\s*'
Bram Moolenaar75b81562014-04-06 14:09:13 +020036
Bram Moolenaare8008642022-08-19 17:15:35 +010037 function! s:SearchSection(end, backwards, visualmode) abort
38 if a:visualmode !=# ''
39 normal! gv
40 endif
41 let l:flags = a:backwards ? 'bsW' : 'sW'
42 if a:end
43 call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
44 else
45 call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
46 endif
47 endfunction
Bram Moolenaar75b81562014-04-06 14:09:13 +020048
Bram Moolenaare8008642022-08-19 17:15:35 +010049 noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
50 xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
51 sunmap <buffer> ]]
52 noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
53 xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
54 sunmap <buffer> ][
55 noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
56 xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
57 sunmap <buffer> [[
58 noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
59 xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
60 sunmap <buffer> []
Bram Moolenaar75b81562014-04-06 14:09:13 +020061
Bram Moolenaare8008642022-08-19 17:15:35 +010062 let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
63 \ . ' | silent! execute "unmap <buffer> ]["'
64 \ . ' | silent! execute "unmap <buffer> [["'
65 \ . ' | silent! execute "unmap <buffer> []"'
66endif
Bram Moolenaar75b81562014-04-06 14:09:13 +020067
Bram Moolenaare8008642022-08-19 17:15:35 +010068" Browse dialog filter on Windows and GTK (see ":help browsefilter")
69if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
Bram Moolenaar75b81562014-04-06 14:09:13 +020070 let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
Doug Kearns93197fd2024-01-14 20:59:02 +010071 if has("win32")
72 let b:browsefilter .= "All Files (*.*)\t*\n"
73 else
74 let b:browsefilter .= "All Files (*)\t*\n"
75 endif
Bram Moolenaar75b81562014-04-06 14:09:13 +020076 let b:undo_ftplugin .= ' | unlet! b:browsefilter'
77endif
78
79" Enhanced "%" matching (see ":help matchit")
80if exists('loaded_matchit') && !exists('b:match_words')
81 let b:match_ignorecase = 0
Bram Moolenaar83caecf2015-01-14 19:42:21 +010082 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 +020083 \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
84 let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
85endif
86
87let &cpo = s:save_cpo
88unlet s:save_cpo