Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "In: the current mode (eg. "visual", "normal", etc.)
- "Out: the type information (calls s:Extract_type_data)
- function! s:Get_type(mode, annot_file_name)
- let [lin1,lin2,col1,col2] = s:Match_borders(a:mode)
- return s:Extract_type_data(s:Block_pattern(lin1,lin2,col1,col2), a:annot_file_name)
- endfun
- "In: A string destined to be printed in the 'echo buffer'. It has line
- "break and 2 space at each line beginning.
- "Out: A string destined to be yanked, without space and double space.
- function s:unformat_ocaml_type(res)
- "Remove end of line.
- let res = substitute (a:res, "\n", "", "g" )
- "remove double space
- let res =substitute(res , " ", " ", "g")
- "remove space at begining of string.
- let res = substitute(res, "^ *", "", "g")
- return res
- endfunction
- "d. main
- "In: the current mode (eg. "visual", "normal", etc.)
- "After call: the type information is displayed
- if !exists("*Ocaml_get_type")
- function Ocaml_get_type(mode)
- let annot_file_name = s:Fnameescape(expand('%:t:r')).'.annot'
- call s:Locate_annotation()
- call s:Load_annotation(annot_file_name)
- let res = s:Get_type(a:mode, annot_file_name)
- "Copy result in the unnamed buffer
- let @" = s:unformat_ocaml_type(res)
- return res
- endfun
- endif
- if !exists("*Ocaml_get_type_or_not")
- function Ocaml_get_type_or_not(mode)
- let t=reltime()
- try
- let res = Ocaml_get_type(a:mode)
- return res
- catch
- return ""
- endtry
- endfun
- endif
- if !exists("*Ocaml_print_type")
- function Ocaml_print_type(mode)
- if expand("%:e") == "mli"
- echohl ErrorMsg | echo "No annotations for interface (.mli) files" | echohl None
- return
- endif
- try
- let res = Ocaml_get_type(a:mode)
- " echo Ocaml_get_type(a:mode)
- echo res
- catch /E484:/
- echohl ErrorMsg | echo "No type annotations (.annot) file found" | echohl None
- catch /no_expression/
- echohl ErrorMsg | echo "No expression found under the cursor" | echohl None
- catch /no_annotation/
- echohl ErrorMsg | echo "No type annotation found for the given text" | echohl None
- catch /malformed_annot_file/
- echohl ErrorMsg | echo "Malformed .annot file" | echohl None
- endtry
- endfun
- endif
- " Maps
- map <silent> <LocalLeader>t :call Ocaml_print_type("normal")<CR>
- vmap <silent> <LocalLeader>t :<C-U>call Ocaml_print_type("visual")<CR>`<
Add Comment
Please, Sign In to add comment