diff options
Diffstat (limited to '')
-rw-r--r-- | .vim/.VimballRecord | 2 | ||||
-rw-r--r-- | .vim/autoload/haskellmode.vim | 40 | ||||
-rw-r--r-- | .vim/compiler/ghc.vim | 133 | ||||
-rw-r--r-- | .vim/doc/haskellmode.txt | 15 | ||||
-rw-r--r-- | .vim/ftplugin/haskell_doc.vim | 120 |
5 files changed, 228 insertions, 82 deletions
diff --git a/.vim/.VimballRecord b/.vim/.VimballRecord index b72e3e8..d2ae40c 100644 --- a/.vim/.VimballRecord +++ b/.vim/.VimballRecord @@ -1 +1 @@ -haskellmode-20090430.vba: call delete('/home/necoro/.vim/compiler/ghc.vim')|call delete('/home/necoro/.vim/ftplugin/haskell.vim')|call delete('/home/necoro/.vim/ftplugin/haskell_doc.vim')|call delete('/home/necoro/.vim/ftplugin/haskell_hpaste.vim')|call delete('/home/necoro/.vim/autoload/haskellmode.vim')|call delete('/home/necoro/.vim/doc/haskellmode.txt') +haskellmode-20101118.vba: call delete('/home/necoro/.vim/compiler/ghc.vim')|call delete('/home/necoro/.vim/ftplugin/haskell.vim')|call delete('/home/necoro/.vim/ftplugin/haskell_doc.vim')|call delete('/home/necoro/.vim/ftplugin/haskell_hpaste.vim')|call delete('/home/necoro/.vim/autoload/haskellmode.vim')|call delete('/home/necoro/.vim/doc/haskellmode.txt') diff --git a/.vim/autoload/haskellmode.vim b/.vim/autoload/haskellmode.vim index ce20a67..4a26cd5 100644 --- a/.vim/autoload/haskellmode.vim +++ b/.vim/autoload/haskellmode.vim @@ -1,7 +1,7 @@ " " utility functions for haskellmode plugins " -" (Claus Reinke; last modified: 23/04/2009) +" (Claus Reinke; last modified: 22/06/2010) " " part of haskell plugins: http://projects.haskell.org/haskellmode-vim " please send patches to <claus.reinke@talk21.com> @@ -63,7 +63,7 @@ function! haskellmode#GatherImports() let res = haskellmode#GatherImport(i) if !empty(res) let [i,import] = res - let prefixPat = '^import\s*\(qualified\)\?\s\+' + let prefixPat = '^import\s*\%({-#\s*SOURCE\s*#-}\)\?\(qualified\)\?\s\+' let modulePat = '\([A-Z][a-zA-Z0-9_''.]*\)' let asPat = '\(\s\+as\s\+'.modulePat.'\)\?' let hidingPat = '\(\s\+hiding\s*\((.*)\)\)\?' @@ -153,3 +153,39 @@ function! haskellmode#UrlEncode(string) return url endfunction +" TODO: we could have buffer-local settings, at the expense of +" reconfiguring for every new buffer.. do we want to? +function! haskellmode#GHC() + if (!exists("g:ghc") || !executable(g:ghc)) + if !executable('ghc') + echoerr s:scriptname.": can't find ghc. please set g:ghc, or extend $PATH" + return 0 + else + let g:ghc = 'ghc' + endif + endif + return 1 +endfunction + +function! haskellmode#GHC_Version() + if !exists("g:ghc_version") + let g:ghc_version = substitute(system(g:ghc . ' --numeric-version'),'\n','','') + endif + return g:ghc_version +endfunction + +function! haskellmode#GHC_VersionGE(target) + let current = split(haskellmode#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 + 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 + diff --git a/.vim/doc/haskellmode.txt b/.vim/doc/haskellmode.txt index 905349c..27c224d 100644 --- a/.vim/doc/haskellmode.txt +++ b/.vim/doc/haskellmode.txt @@ -1,4 +1,4 @@ -*haskellmode.txt* Haskell Mode Plugins 23/04/2009 +*haskellmode.txt* Haskell Mode Plugins 02/05/2009 Authors: Claus Reinke <claus.reinke@talk21.com> ~ @@ -242,8 +242,17 @@ CONTENTS *haskellmode* show the errors otherwise. *:GHCStaticOptions* -:GHCStaticOptions Edit the static GHC options for the current buffer. - Useful for adding hidden packages (-package ghc). +:GHCStaticOptions Edit the static GHC options (more generally, options + that cannot be set by in-file OPTIONS_GHC pragmas) + for the current buffer. Useful for adding hidden + packages (-package ghc), or additional import paths + (-isrc; you will then also want to augment |path|). + If you have static options you want to set as + defaults, you could use b:ghc_staticoptions, eg: +> + au FileType haskell let b:ghc_staticoptions = '-isrc' + au FileType haskell setlocal path += src +< *:GHCi* :GHCi {command/expr} Run GHCi commands/expressions in the current module. diff --git a/.vim/ftplugin/haskell_doc.vim b/.vim/ftplugin/haskell_doc.vim index deceec6..482ea69 100644 --- a/.vim/ftplugin/haskell_doc.vim +++ b/.vim/ftplugin/haskell_doc.vim @@ -2,7 +2,7 @@ " use haddock docs and index files " show documentation, complete & qualify identifiers " -" (Claus Reinke; last modified: 30/04/2009) +" (Claus Reinke; last modified: 17/06/2009) " " part of haskell plugins: http://projects.haskell.org/haskellmode-vim " please send patches to <claus.reinke@talk21.com> @@ -66,14 +66,7 @@ if !exists("g:haddock_browser") echoerr s:scriptname." WARNING: please set g:haddock_browser!" endif -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 +if !haskellmode#GHC() | finish | endif if (!exists("g:ghc_pkg") || !executable(g:ghc_pkg)) let g:ghc_pkg = substitute(g:ghc,'\(.*\)ghc','\1ghc-pkg','') @@ -85,13 +78,17 @@ elseif executable(g:ghc_pkg) " try to figure out location of html docs " first choice: where the base docs are (from the first base listed) let [field;x] = split(system(g:ghc_pkg . ' field base haddock-html'),'\n') - let field = substitute(field,'haddock-html: \(.*\)libraries.base','\1','') + " path changes in ghc-6.12.* + " let field = substitute(field,'haddock-html: \(.*\)libraries.base','\1','') + let field = substitute(field,'haddock-html: \(.*\)lib\(raries\)\?.base.*$','\1','') let field = substitute(field,'\\','/','g') - let alternate = substitute(field,'html','doc/html','') - if isdirectory(field) - let s:docdir = field - elseif isdirectory(alternate) + " let alternate = substitute(field,'html','doc/html','') + " changes for ghc-6.12.*: check for doc/html/ first + let alternate = field.'doc/html/' + if isdirectory(alternate) let s:docdir = alternate + elseif isdirectory(field) + let s:docdir = field endif else echoerr s:scriptname." can't find ghc-pkg (set g:ghc_pkg ?)." @@ -102,8 +99,7 @@ if !exists('s:docdir') || !isdirectory(s:docdir) let s:ghc_libdir = substitute(system(g:ghc . ' --print-libdir'),'\n','','') let location1a = s:ghc_libdir . '/doc/html/' let location1b = s:ghc_libdir . '/doc/' - let s:ghc_version = substitute(system(g:ghc . ' --numeric-version'),'\n','','') - let location2 = '/usr/share/doc/ghc-' . s:ghc_version . '/html/' + let location2 = '/usr/share/doc/ghc-' . haskellmode#GHC_Version() . '/html/' if isdirectory(location1a) let s:docdir = location1a elseif isdirectory(location1b) @@ -164,7 +160,7 @@ endif command! DocSettings call DocSettings() function! DocSettings() - for v in ["g:haddock_browser","g:haddock_browser_callformat","g:haddock_docdir","g:haddock_indexfiledir","s:ghc_libdir","s:ghc_version","s:docdir","s:libraries","s:guide","s:haddock_indexfile"] + for v in ["g:haddock_browser","g:haddock_browser_callformat","g:haddock_docdir","g:haddock_indexfiledir","s:ghc_libdir","g:ghc_version","s:docdir","s:libraries","s:guide","s:haddock_indexfile"] if exists(v) echo v '=' eval(v) else @@ -317,8 +313,12 @@ command! DocIndex call DocIndex() function! DocIndex() let files = split(globpath(s:libraries,'doc-index*.html'),'\n') let g:haddock_index = {} - call ProcessHaddockIndexes2(s:libraries,files) - if GHC_VersionGE([6,8,2]) + if haskellmode#GHC_VersionGE([7,0,0]) + call ProcessHaddockIndexes3(s:libraries,files) + else + call ProcessHaddockIndexes2(s:libraries,files) + endif + if haskellmode#GHC_VersionGE([6,8,2]) if &shell =~ 'sh' " unix-type shell let s:addon_libraries = split(system(g:ghc_pkg . ' field \* haddock-html'),'\n') else " windows cmd.exe and the like @@ -330,7 +330,11 @@ function! DocIndex() let [_,quote,file,addon_path;x] = ml let addon_path = substitute(addon_path,'\(\\\\\|\\\)','/','g') let addon_files = split(globpath(addon_path,'doc-index*.html'),'\n') - call ProcessHaddockIndexes2(addon_path,addon_files) + if haskellmode#GHC_VersionGE([7,0,0]) + call ProcessHaddockIndexes3(addon_path,addon_files) + else + call ProcessHaddockIndexes2(addon_path,addon_files) + endif endif endfor endif @@ -425,6 +429,63 @@ function! ProcessHaddockIndexes2(location,files) endfor endfunction +function! ProcessHaddockIndexes3(location,files) + let entryPat= '>\(.*\)$' + let linkPat = '<a href="\([^"]*\)"' + let kindPat = '#\(.\)' + + " redraw + echo 'populating g:haddock_index from haddock index files in ' a:location + for f in a:files + echo f[len(a:location):] + let isLink = '' + let link = {} + let entry = '' + let lines = split(join(readfile(f,'b')),'\ze<') + for line in lines + if (line=~'class="src') || (line=~'/table') + if (link!={}) && (entry!='') + if has_key(g:haddock_index,DeHTML(entry)) + let dict = extend(g:haddock_index[DeHTML(entry)],deepcopy(link)) + else + let dict = deepcopy(link) + endif + let g:haddock_index[DeHTML(entry)] = dict + let link = {} + let entry = '' + endif + let ml = matchlist(line,entryPat) + if ml!=[] | let [_,entry;x] = ml | continue | endif + continue + endif + if entry!='' + let ml = matchlist(line,linkPat) + if ml!=[] + let [_,isLink;x]=ml + let ml = matchlist(line,entryPat) + if ml!=[] + let [_,module;x] = ml + let [_,kind;x] = matchlist(isLink,kindPat) + let last = a:location[strlen(a:location)-1] + let link[module."[".kind."]"] = a:location . (last=='/'?'':'/') . isLink + let isLink='' + endif + continue + endif + endif + endfor + if link!={} + if has_key(g:haddock_index,DeHTML(entry)) + let dict = extend(g:haddock_index[DeHTML(entry)],deepcopy(link)) + else + let dict = deepcopy(link) + endif + let g:haddock_index[DeHTML(entry)] = dict + endif + endfor +endfunction + + command! ExportDocIndex call ExportDocIndex() function! ExportDocIndex() call HaveIndex() @@ -465,7 +526,7 @@ function! MkHaddockModuleIndex() let html = dict[module] let html = substitute(html ,'#.*$','','') let module = substitute(module,'\[.\]','','') - let ml = matchlist(html,'libraries/\([^\/]*\)\/') + let ml = matchlist(html,'libraries/\([^\/]*\)[\/]') if ml!=[] let [_,package;x] = ml let g:haddock_moduleindex[module] = {'package':package,'html':html} @@ -818,20 +879,3 @@ function! HaddockIndexLookup(name) return g:haddock_index[a:name] endfunction -" copied from ghc.vim :-( should we move everything to using autoload instead? -" we query the ghc version here, as we don't otherwise need it.. -function! GHC_VersionGE(target) - let s:ghc_version = substitute(system(g:ghc . ' --numeric-version'),'\n','','') - 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 |