robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
7945732ed7
master
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: 2025 Aug 09 7" 2026 Mar 31 by Vim project: use shellescape for the K mapping 8" 2026 Apr 01 by Vim project: make K mapping more robust for shell injection 9" 2026 Jun 27 by Vim Project: add recommended style guard 10 11if exists ( "b:did_ftplugin" ) 12finish 13endif 14let b: did_ftplugin = 1 15 16let s: cpo_save = & cpo 17set cpo & vim 18 19" quick hack to allow adding values 20setlocal iskeyword = @,!,#-',*-:,<-Z,a-z,~,_,94 21 22if get ( g:, 'racket_recommended_style' , 23 \get ( g:, 'filetype_recommended_style' , 1 )) 24setlocal shiftwidth = 2 softtabstop = 2 25endif 26 27" Enable auto begin new comment line when continuing from an old comment line 28setlocal comments = :;;;;,:;;;,:;;,:; 29setlocal formatoptions += r 30 31setlocal commentstring = ;;\ %s 32 33setlocal formatprg = raco\ fmt 34 35" Undo our settings when the filetype changes away from Racket 36" (this should be amended if settings/mappings are added above!) 37let b: undo_ftplugin = 38 \"setlocal iskeyword< shiftwidth< softtabstop< comments< formatoptions< formatprg<" 39 \. " | setlocal commentstring<" 40 41if ! exists ( "no_plugin_maps" ) && ! exists ( "no_racket_maps" ) 42" Simply setting keywordprg like this works: 43" setlocal keywordprg=raco\ docs 44" but then vim says: 45" "press ENTER or type a command to continue" 46" We avoid the annoyance of having to hit enter by remapping K directly. 47function s: RacketDoc ( word ) abort 48execute 'silent !raco docs --' shellescape ( a: word , v: true ) 49redraw ! 50endfunction 51nnoremap <buffer> < Plug > RacketDoc :call< SID > RacketDoc(expand('< cword>'))< CR > 52nmap <buffer> K< Plug > RacketDoc 53 54" For the visual mode K mapping, it's slightly more convoluted to get the 55" selected text: 56function ! s: Racket_visual_doc () 57try 58let l: old_a = @a 59normal ! gv"ay 60call system ( "raco docs -- " . string ( shellescape ( @a))) 61redraw ! 62return @a 63finally 64let @a= l: old_a 65endtry 66endfunction 67 68xnoremap <buffer> < Plug > RacketDoc :call< SID > Racket_visual_doc()< cr > 69xmap <buffer> K< Plug > RacketDoc 70 71let b: undo_ftplugin .= 72 \" | silent! execute 'nunmap <buffer> K'" 73 \. " | silent! execute 'xunmap <buffer> K'" 74endif 75 76if ( has ( "gui_win32" ) || has ( "gui_gtk" )) && ! exists ( "b:browsefilter" ) 77let b: browsefilter = 78 \"Racket Source Files (*.rkt, *.rktl)\t*.rkt;*.rktl\n" 79if has ( "win32" ) 80let b: browsefilter .= "All Files (*.*)\t*\n" 81else 82let b: browsefilter .= "All Files (*)\t*\n" 83endif 84let b: undo_ftplugin .= " | unlet! b:browsefilter" 85endif 86 87if exists ( "loaded_matchit" ) && ! exists ( "b:match_words" ) 88let b: match_words = '#|:|#' 89let b: undo_ftplugin .= " | unlet! b:match_words" 90endif 91 92let & cpo = s: cpo_save 93unlet s: cpo_save