racket.vim 2.6 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: 2022 Aug 29
  7. " 2024 Jan 14 by Vim Project (browsefilter)
  8. if exists("b:did_ftplugin")
  9. finish
  10. endif
  11. let b:did_ftplugin = 1
  12. let s:cpo_save = &cpo
  13. set cpo&vim
  14. " quick hack to allow adding values
  15. setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,94
  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 commentstring=#\|\ %s\ \|#
  21. setlocal formatprg=raco\ fmt
  22. " Undo our settings when the filetype changes away from Racket
  23. " (this should be amended if settings/mappings are added above!)
  24. let b:undo_ftplugin =
  25. \ "setlocal iskeyword< lispwords< lisp< comments< formatoptions< formatprg<"
  26. \. " | setlocal commentstring<"
  27. if !exists("no_plugin_maps") && !exists("no_racket_maps")
  28. " Simply setting keywordprg like this works:
  29. " setlocal keywordprg=raco\ docs
  30. " but then vim says:
  31. " "press ENTER or type a command to continue"
  32. " We avoid the annoyance of having to hit enter by remapping K directly.
  33. function s:RacketDoc(word) abort
  34. execute 'silent !raco docs --' shellescape(a:word)
  35. redraw!
  36. endfunction
  37. nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
  38. nmap <buffer> K <Plug>RacketDoc
  39. " For the visual mode K mapping, it's slightly more convoluted to get the
  40. " selected text:
  41. function! s:Racket_visual_doc()
  42. try
  43. let l:old_a = @a
  44. normal! gv"ay
  45. call system("raco docs '". @a . "'")
  46. redraw!
  47. return @a
  48. finally
  49. let @a = l:old_a
  50. endtry
  51. endfunction
  52. xnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>
  53. xmap <buffer> K <Plug>RacketDoc
  54. let b:undo_ftplugin .=
  55. \ " | silent! execute 'nunmap <buffer> K'"
  56. \. " | silent! execute 'xunmap <buffer> K'"
  57. endif
  58. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  59. let b:browsefilter =
  60. \ "Racket Source Files (*.rkt, *.rktl)\t*.rkt;*.rktl\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. if exists("loaded_matchit") && !exists("b:match_words")
  69. let b:match_words = '#|:|#'
  70. let b:undo_ftplugin .= " | unlet! b:match_words"
  71. endif
  72. let &cpo = s:cpo_save
  73. unlet s:cpo_save