diff options
author | René Neumann <rene.neumann@in.tum.de> | 2011-12-09 16:29:52 +0100 |
---|---|---|
committer | René Neumann <rene.neumann@in.tum.de> | 2011-12-09 16:29:53 +0100 |
commit | c7c03a0185ac4598331bf88eea1ccd0bc62b87d5 (patch) | |
tree | ce242ecdf6ddf486bb30c586b3fba7ac40f2f688 /.vim/compiler/ghc.vim | |
parent | b4a2b04706d0b86bcd9fd47c77a2c579805196a0 (diff) | |
download | dotfiles-c7c03a0185ac4598331bf88eea1ccd0bc62b87d5.tar.gz dotfiles-c7c03a0185ac4598331bf88eea1ccd0bc62b87d5.tar.bz2 dotfiles-c7c03a0185ac4598331bf88eea1ccd0bc62b87d5.zip |
Update haskellmode
Diffstat (limited to '')
-rw-r--r-- | .vim/compiler/ghc.vim | 133 |
1 files changed, 95 insertions, 38 deletions
diff --git a/.vim/compiler/ghc.vim b/.vim/compiler/ghc.vim index 2760df6..b50bc29 100644 --- a/.vim/compiler/ghc.vim +++ b/.vim/compiler/ghc.vim @@ -2,7 +2,7 @@ " Vim Compiler File " Compiler: GHC " Maintainer: Claus Reinke <claus.reinke@talk21.com> -" Last Change: 30/04/2009 +" Last Change: 22/06/2010 " " part of haskell plugins: http://projects.haskell.org/haskellmode-vim @@ -16,15 +16,7 @@ let current_compiler = "ghc" let s:scriptname = "ghc.vim" -if (!exists("g:ghc") || !executable(g:ghc)) - if !executable('ghc') - echoerr s:scriptname.": can't find ghc. please set g:ghc, or extend $PATH" - finish - else - let g:ghc = 'ghc' - endif -endif -let ghc_version = substitute(system(g:ghc . ' --numeric-version'),'\n','','') +if !haskellmode#GHC() | finish | endif if (!exists("b:ghc_staticoptions")) let b:ghc_staticoptions = '' endif @@ -111,6 +103,10 @@ function! GHC_ShowType(addTypeDecl) endfunction " show type of identifier under mouse pointer in balloon +" TODO: it isn't a good idea to tie potentially time-consuming tasks +" (querying GHCi for the types) to cursor movements (#14). Currently, +" we ask the user to call :GHCReload explicitly. Should there be an +" option to reenable the old implicit querying? if has("balloon_eval") set ballooneval set balloondelay=600 @@ -125,11 +121,22 @@ if has("balloon_eval") let [start,symb,qual,unqual] = namsym let name = qual=='' ? unqual : qual.'.'.unqual let pname = name " ( symb ? '('.name.')' : name ) - silent call GHC_HaveTypes() - if has("balloon_multiline") - return (has_key(b:ghc_types,pname) ? split(b:ghc_types[pname],' -- ') : '') + if b:ghc_types == {} + redraw + echo "no type information (try :GHGReload)" + elseif (b:my_changedtick != b:changedtick) + redraw + echo "type information may be out of date (try :GHGReload)" + endif + " silent call GHC_HaveTypes() + if b:ghc_types!={} + if has("balloon_multiline") + return (has_key(b:ghc_types,pname) ? split(b:ghc_types[pname],' -- ') : '') + else + return (has_key(b:ghc_types,pname) ? b:ghc_types[pname] : '') + endif else - return (has_key(b:ghc_types,pname) ? b:ghc_types[pname] : '') + return '' endif else return '' @@ -180,31 +187,17 @@ command! GHCReload call GHC_BrowseAll() function! GHC_BrowseAll() " let imports = haskellmode#GatherImports() " let modules = keys(imports[0]) + keys(imports[1]) + let b:my_changedtick = b:changedtick let imports = {} " no need for them at the moment let current = GHC_NameCurrent() let module = current==[] ? 'Main' : current[0] - if GHC_VersionGE([6,8,1]) + if haskellmode#GHC_VersionGE([6,8,1]) return GHC_BrowseBangStar(module) else return GHC_BrowseMultiple(imports,['*'.module]) endif endfunction -function! GHC_VersionGE(target) - let current = split(g:ghc_version, '\.' ) - let target = a:target - for i in current - if ((target==[]) || (i>target[0])) - return 1 - elseif (i==target[0]) - let target = target[1:] - else - return 0 - endif - endfor - return 1 -endfunction - function! GHC_NameCurrent() let last = line("$") let l = 1 @@ -243,7 +236,7 @@ endfunction function! GHC_Info(what) " call GHC_HaveTypes() - let output = system(g:ghc . ' ' . b:ghc_staticoptions . ' -v0 --interactive ' . expand("%"), ":i ". a:what) + let output = system(g:ghc . ' ' . b:ghc_staticoptions . ' -v0 --interactive ' . expand("%"), ":info ". a:what) return output endfunction @@ -447,15 +440,72 @@ function! GHC_MkImportsExplicit() call setpos('.', save_cursor) endfunction -if GHC_VersionGE([6,8,2]) - let opts = filter(split(substitute(system(g:ghc . ' -v0 --interactive', ':set'), ' ', '','g'), '\n'), 'v:val =~ "-f"') +" no need to ask GHC about its supported languages and +" options with every editing session. cache the info in +" ~/.vim/haskellmode.config +" TODO: should we store more info (see haskell_doc.vim)? +" move to autoload? +" should we keep a history of GHC versions encountered? +function! GHC_SaveConfig() + let vimdir = expand('~').'/'.'.vim' + let config = vimdir.'/haskellmode.config' + if !isdirectory(vimdir) + call mkdir(vimdir) + endif + let entries = ['-- '.g:ghc_version] + for l in s:ghc_supported_languages + let entries += [l] + endfor + let entries += ['--'] + for l in s:opts + let entries += [l] + endfor + call writefile(entries,config) +endfunction + +" reuse cached GHC configuration info, if using the same +" GHC version. +function! GHC_LoadConfig() + let vimdir = expand('~').'/'.'.vim' + let config = vimdir.'/haskellmode.config' + if filereadable(config) + let lines = readfile(config) + if lines[0]=='-- '.g:ghc_version + let i=1 + let s:ghc_supported_languages = [] + while i<len(lines) && lines[i]!='--' + let s:ghc_supported_languages += [lines[i]] + let i+=1 + endwhile + let i+=1 + let s:opts = [] + while i<len(lines) + let s:opts += [lines[i]] + let i+=1 + endwhile + return 1 + else + return 0 + endif + else + return 0 + endif +endfunction + +let s:GHC_CachedConfig = haskellmode#GHC_VersionGE([6,8]) && GHC_LoadConfig() + +if haskellmode#GHC_VersionGE([6,8,2]) + if !s:GHC_CachedConfig + let s:opts = filter(split(substitute(system(g:ghc . ' -v0 --interactive', ':set'), ' ', '','g'), '\n'), 'v:val =~ "-f"') + endif else - let opts = ["-fglasgow-exts","-fallow-undecidable-instances","-fallow-overlapping-instances","-fno-monomorphism-restriction","-fno-mono-pat-binds","-fno-cse","-fbang-patterns","-funbox-strict-fields"] + let s:opts = ["-fglasgow-exts","-fallow-undecidable-instances","-fallow-overlapping-instances","-fno-monomorphism-restriction","-fno-mono-pat-binds","-fno-cse","-fbang-patterns","-funbox-strict-fields"] endif +let s:opts = sort(s:opts) amenu ]OPTIONS_GHC.- :echo '-'<cr> aunmenu ]OPTIONS_GHC -for o in opts +for o in s:opts exe 'amenu ]OPTIONS_GHC.'.o.' :call append(0,"{-# OPTIONS_GHC '.o.' #-}")<cr>' endfor if has("gui_running") @@ -466,9 +516,11 @@ endif amenu ]LANGUAGES_GHC.- :echo '-'<cr> aunmenu ]LANGUAGES_GHC -if GHC_VersionGE([6,8]) - let ghc_supported_languages = split(system(g:ghc . ' --supported-languages'),'\n') - for l in ghc_supported_languages +if haskellmode#GHC_VersionGE([6,8]) + if !s:GHC_CachedConfig + let s:ghc_supported_languages = sort(split(system(g:ghc . ' --supported-languages'),'\n')) + endif + for l in s:ghc_supported_languages exe 'amenu ]LANGUAGES_GHC.'.l.' :call append(0,"{-# LANGUAGE '.l.' #-}")<cr>' endfor if has("gui_running") @@ -477,3 +529,8 @@ if GHC_VersionGE([6,8]) map <LocalLeader>lang :emenu ]LANGUAGES_GHC. endif endif + +if !s:GHC_CachedConfig + call GHC_SaveConfig() +endif + |