codekingpro/portable-devtools
115k
1" Vim filetype plugin2" Language: Racket3" Maintainer: D. Ben Knoble <ben.knoble+github@gmail.com>4" Previous Maintainer: Will Langstroth <will@langstroth.com>5" URL: https://github.com/benknoble/vim-racket6" Last Change: 2025 Aug 097" 2026 Mar 31 by Vim project: use shellescape for the K mapping8" 2026 Apr 01 by Vim project: make K mapping more robust for shell injection9 10if exists("b:did_ftplugin")11 finish12endif13let b:did_ftplugin = 114 15let s:cpo_save = &cpo16set cpo&vim17 18" quick hack to allow adding values19setlocal iskeyword=@,!,#-',*-:,<-Z,a-z,~,_,9420 21setlocal shiftwidth=2 softtabstop=222 23" Enable auto begin new comment line when continuing from an old comment line24setlocal comments=:;;;;,:;;;,:;;,:;25setlocal formatoptions+=r26 27setlocal commentstring=;;\ %s28 29setlocal formatprg=raco\ fmt30 31" Undo our settings when the filetype changes away from Racket32" (this should be amended if settings/mappings are added above!)33let b:undo_ftplugin =34 \ "setlocal iskeyword< shiftwidth< softtabstop< comments< formatoptions< formatprg<"35 \. " | setlocal commentstring<"36 37if !exists("no_plugin_maps") && !exists("no_racket_maps")38 " Simply setting keywordprg like this works:39 " setlocal keywordprg=raco\ docs40 " but then vim says:41 " "press ENTER or type a command to continue"42 " We avoid the annoyance of having to hit enter by remapping K directly.43 function s:RacketDoc(word) abort44 execute 'silent !raco docs --' shellescape(a:word, v:true)45 redraw!46 endfunction47 nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>48 nmap <buffer> K <Plug>RacketDoc49 50 " For the visual mode K mapping, it's slightly more convoluted to get the51 " selected text:52 function! s:Racket_visual_doc()53 try54 let l:old_a = @a55 normal! gv"ay56 call system("raco docs -- ". string(shellescape(@a)))57 redraw!58 return @a59 finally60 let @a = l:old_a61 endtry62 endfunction63 64 xnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>65 xmap <buffer> K <Plug>RacketDoc66 67 let b:undo_ftplugin .=68 \ " | silent! execute 'nunmap <buffer> K'"69 \. " | silent! execute 'xunmap <buffer> K'"70endif71 72if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")73 let b:browsefilter =74 \ "Racket Source Files (*.rkt, *.rktl)\t*.rkt;*.rktl\n"75 if has("win32")76 let b:browsefilter .= "All Files (*.*)\t*\n"77 else78 let b:browsefilter .= "All Files (*)\t*\n"79 endif80 let b:undo_ftplugin .= " | unlet! b:browsefilter"81endif82 83if exists("loaded_matchit") && !exists("b:match_words")84 let b:match_words = '#|:|#'85 let b:undo_ftplugin .= " | unlet! b:match_words"86endif87 88let &cpo = s:cpo_save89unlet s:cpo_save90 