racket.vim 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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: 2024 Jun 01
  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. setlocal shiftwidth=2 softtabstop=2
  16. " Enable auto begin new comment line when continuing from an old comment line
  17. setlocal comments=:;;;;,:;;;,:;;,:;
  18. setlocal formatoptions+=r
  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< shiftwidth< softtabstop< 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. if has("win32")
  61. let b:browsefilter .= "All Files (*.*)\t*\n"
  62. else
  63. let b:browsefilter .= "All Files (*)\t*\n"
  64. endif
  65. let b:undo_ftplugin .= " | unlet! b:browsefilter"
  66. endif
  67. if exists("loaded_matchit") && !exists("b:match_words")
  68. let b:match_words = '#|:|#'
  69. let b:undo_ftplugin .= " | unlet! b:match_words"
  70. endif
  71. let &cpo = s:cpo_save
  72. unlet s:cpo_save