racket.vim 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. " Vim filetype plugin
  2. " Language: Racket
  3. " Maintainer: D. Ben Knoble <ben.knoble+github@gmail.com>
  4. " Previous Maintainer: Will Langstroth <will@langstroth.com>
  5. " URL: https://github.com/benknoble/vim-racket
  6. " Last Change: 2022 Aug 29
  7. if exists("b:did_ftplugin")
  8. finish
  9. endif
  10. let b:did_ftplugin = 1
  11. let s:cpo_save = &cpo
  12. set cpo&vim
  13. " quick hack to allow adding values
  14. setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94
  15. " Enable auto begin new comment line when continuing from an old comment line
  16. setlocal comments=:;;;;,:;;;,:;;,:;
  17. setlocal formatoptions+=r
  18. "setlocal commentstring=;;%s
  19. setlocal commentstring=#\|\ %s\ \|#
  20. setlocal formatprg=raco\ fmt
  21. " Undo our settings when the filetype changes away from Racket
  22. " (this should be amended if settings/mappings are added above!)
  23. let b:undo_ftplugin =
  24. \ "setlocal iskeyword< lispwords< lisp< comments< formatoptions< formatprg<"
  25. \. " | setlocal commentstring<"
  26. if !exists("no_plugin_maps") && !exists("no_racket_maps")
  27. " Simply setting keywordprg like this works:
  28. " setlocal keywordprg=raco\ docs
  29. " but then vim says:
  30. " "press ENTER or type a command to continue"
  31. " We avoid the annoyance of having to hit enter by remapping K directly.
  32. function s:RacketDoc(word) abort
  33. execute 'silent !raco docs --' shellescape(a:word)
  34. redraw!
  35. endfunction
  36. nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
  37. nmap <buffer> K <Plug>RacketDoc
  38. " For the visual mode K mapping, it's slightly more convoluted to get the
  39. " selected text:
  40. function! s:Racket_visual_doc()
  41. try
  42. let l:old_a = @a
  43. normal! gv"ay
  44. call system("raco docs '". @a . "'")
  45. redraw!
  46. return @a
  47. finally
  48. let @a = l:old_a
  49. endtry
  50. endfunction
  51. xnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>
  52. xmap <buffer> K <Plug>RacketDoc
  53. let b:undo_ftplugin .=
  54. \ " | silent! execute 'nunmap <buffer> K'"
  55. \. " | silent! execute 'xunmap <buffer> K'"
  56. endif
  57. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  58. let b:browsefilter =
  59. \ "Racket Source Files (*.rkt *.rktl)\t*.rkt;*.rktl\n"
  60. \. "All Files (*.*)\t*.*\n"
  61. let b:undo_ftplugin .= " | unlet! b:browsefilter"
  62. endif
  63. if exists("loaded_matchit") && !exists("b:match_words")
  64. let b:match_words = '#|:|#'
  65. let b:undo_ftplugin .= " | unlet! b:match_words"
  66. endif
  67. let &cpo = s:cpo_save
  68. unlet s:cpo_save