robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40472 from zeertzjq/vim-1f337327945732ed7

master
2.8 KiB93 linesraw
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")
12  finish
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))
24  setlocal 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.
47  function s:RacketDoc(word) abort
48    execute 'silent !raco docs --' shellescape(a:word, v:true)
49    redraw!
50  endfunction
51  nnoremap <buffer> <Plug>RacketDoc :call <SID>RacketDoc(expand('<cword>'))<CR>
52  nmap <buffer> K <Plug>RacketDoc
53
54  " For the visual mode K mapping, it's slightly more convoluted to get the
55  " selected text:
56  function! s:Racket_visual_doc()
57    try
58      let l:old_a = @a
59      normal! gv"ay
60      call system("raco docs -- ". string(shellescape(@a)))
61      redraw!
62      return @a
63    finally
64      let @a = l:old_a
65    endtry
66  endfunction
67
68  xnoremap <buffer> <Plug>RacketDoc :call <SID>Racket_visual_doc()<cr>
69  xmap <buffer> K <Plug>RacketDoc
70
71  let 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")
77  let b:browsefilter =
78        \  "Racket Source Files (*.rkt, *.rktl)\t*.rkt;*.rktl\n"
79  if has("win32")
80    let b:browsefilter .= "All Files (*.*)\t*\n"
81  else
82    let b:browsefilter .= "All Files (*)\t*\n"
83  endif
84  let b:undo_ftplugin .= " | unlet! b:browsefilter"
85endif
86
87if exists("loaded_matchit") && !exists("b:match_words")
88  let b:match_words = '#|:|#'
89  let b:undo_ftplugin .= " | unlet! b:match_words"
90endif
91
92let &cpo = s:cpo_save
93unlet s:cpo_save