j.vim 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. " Vim filetype plugin
  2. " Language: J
  3. " Maintainer: David Bürgin <dbuergin@gluet.ch>
  4. " URL: https://gitlab.com/glts/vim-j
  5. " Last Change: 2022-08-06
  6. " 2024 Jan 14 by Vim Project (browsefilter)
  7. if exists('b:did_ftplugin')
  8. finish
  9. endif
  10. let b:did_ftplugin = 1
  11. let s:save_cpo = &cpo
  12. set cpo&vim
  13. setlocal iskeyword=48-57,A-Z,a-z,_
  14. setlocal comments=:NB.
  15. setlocal commentstring=NB.\ %s
  16. setlocal formatoptions-=t
  17. setlocal matchpairs=(:)
  18. setlocal path-=/usr/include
  19. " Includes. To make the shorthand form "require 'web/cgi'" work, double the
  20. " last path component. Also strip off leading folder names like "~addons/".
  21. setlocal include=\\v^\\s*(load\|require)\\s*'\\zs\\f+\\ze'
  22. setlocal includeexpr=substitute(substitute(tr(v:fname,'\\','/'),'\\v^[^~][^/.]*(/[^/.]+)$','&\\1',''),'\\v^\\~[^/]+/','','')
  23. setlocal suffixesadd=.ijs
  24. let b:undo_ftplugin = 'setlocal suffixesadd< includeexpr< include< path< matchpairs< formatoptions< commentstring< comments< iskeyword<'
  25. " Section movement with ]] ][ [[ []. The start/end patterns below are amended
  26. " inside the function in order to avoid matching on the current cursor line.
  27. if !exists('no_plugin_maps') && !exists('no_j_maps')
  28. let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
  29. let s:sectionend = '\s*)\s*'
  30. function! s:SearchSection(end, backwards, visualmode) abort
  31. if a:visualmode !=# ''
  32. normal! gv
  33. endif
  34. let l:flags = a:backwards ? 'bsW' : 'sW'
  35. if a:end
  36. call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
  37. else
  38. call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
  39. endif
  40. endfunction
  41. noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
  42. xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
  43. sunmap <buffer> ]]
  44. noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
  45. xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
  46. sunmap <buffer> ][
  47. noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
  48. xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
  49. sunmap <buffer> [[
  50. noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
  51. xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
  52. sunmap <buffer> []
  53. let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
  54. \ . ' | silent! execute "unmap <buffer> ]["'
  55. \ . ' | silent! execute "unmap <buffer> [["'
  56. \ . ' | silent! execute "unmap <buffer> []"'
  57. endif
  58. " Browse dialog filter on Windows and GTK (see ":help browsefilter")
  59. if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
  60. let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
  61. if has("win32")
  62. let b:browsefilter .= "All Files (*.*)\t*\n"
  63. else
  64. let b:browsefilter .= "All Files (*)\t*\n"
  65. endif
  66. let b:undo_ftplugin .= ' | unlet! b:browsefilter'
  67. endif
  68. " Enhanced "%" matching (see ":help matchit")
  69. if exists('loaded_matchit') && !exists('b:match_words')
  70. let b:match_ignorecase = 0
  71. 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*$'
  72. \ . ',\<\%(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'
  74. endif
  75. let &cpo = s:save_cpo
  76. unlet s:save_cpo