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