Guest User

Untitled

a guest
Oct 7th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 2.59 KB | None | 0 0
  1.       "In:  the current mode (eg. "visual", "normal", etc.)
  2.       "Out: the type information (calls s:Extract_type_data)
  3.     function! s:Get_type(mode, annot_file_name)
  4.       let [lin1,lin2,col1,col2] = s:Match_borders(a:mode)
  5.       return s:Extract_type_data(s:Block_pattern(lin1,lin2,col1,col2), a:annot_file_name)
  6.     endfun
  7.  
  8.       "In: A string destined to be printed in the 'echo buffer'. It has line
  9.       "break and 2 space at each line beginning.
  10.       "Out: A string destined to be yanked, without space and double space.
  11.     function s:unformat_ocaml_type(res)
  12.       "Remove end of line.
  13.       let res = substitute (a:res, "\n", "", "g" )
  14.       "remove double space
  15.       let res =substitute(res , "  ", " ", "g")
  16.       "remove space at begining of string.
  17.       let res = substitute(res, "^ *", "", "g")
  18.       return res
  19.     endfunction
  20.  
  21.   "d. main
  22.       "In:         the current mode (eg. "visual", "normal", etc.)
  23.       "After call: the type information is displayed
  24.     if !exists("*Ocaml_get_type")
  25.       function Ocaml_get_type(mode)
  26.         let annot_file_name = s:Fnameescape(expand('%:t:r')).'.annot'
  27.         call s:Locate_annotation()
  28.         call s:Load_annotation(annot_file_name)
  29.     let res = s:Get_type(a:mode, annot_file_name)
  30.     "Copy result in the unnamed buffer
  31.     let @" = s:unformat_ocaml_type(res)
  32.         return res
  33.       endfun
  34.     endif
  35.  
  36.     if !exists("*Ocaml_get_type_or_not")
  37.       function Ocaml_get_type_or_not(mode)
  38.         let t=reltime()
  39.         try
  40.       let res = Ocaml_get_type(a:mode)
  41.       return res
  42.         catch
  43.           return ""
  44.         endtry
  45.       endfun
  46.     endif
  47.  
  48.     if !exists("*Ocaml_print_type")
  49.       function Ocaml_print_type(mode)
  50.         if expand("%:e") == "mli"
  51.           echohl ErrorMsg | echo "No annotations for interface (.mli) files" | echohl None
  52.           return
  53.         endif
  54.         try
  55.             let res = Ocaml_get_type(a:mode)
  56. "          echo Ocaml_get_type(a:mode)
  57.             echo res
  58.         catch /E484:/
  59.           echohl ErrorMsg | echo "No type annotations (.annot) file found" | echohl None
  60.         catch /no_expression/
  61.           echohl ErrorMsg | echo "No expression found under the cursor" | echohl None
  62.         catch /no_annotation/
  63.           echohl ErrorMsg | echo "No type annotation found for the given text" | echohl None
  64.         catch /malformed_annot_file/
  65.           echohl ErrorMsg | echo "Malformed .annot file" | echohl None
  66.         endtry
  67.       endfun
  68.     endif
  69.  
  70. " Maps
  71.   map  <silent> <LocalLeader>t :call Ocaml_print_type("normal")<CR>
  72.   vmap <silent> <LocalLeader>t :<C-U>call Ocaml_print_type("visual")<CR>`<
Add Comment
Please, Sign In to add comment