]>
Commit | Line | Data |
---|---|---|
e7d66018 BB |
1 | " LargeFile: Sets up an autocmd to make editing large files work with celerity |
2 | " Author: Charles E. Campbell, Jr. | |
3 | " Date: Sep 23, 2008 | |
4 | " Version: 4 | |
5 | " GetLatestVimScripts: 1506 1 :AutoInstall: LargeFile.vim | |
6 | ||
7 | " --------------------------------------------------------------------- | |
8 | " Load Once: {{{1 | |
9 | if exists("g:loaded_LargeFile") || &cp | |
10 | finish | |
11 | endif | |
12 | let g:loaded_LargeFile = "v4" | |
13 | let s:keepcpo = &cpo | |
14 | set cpo&vim | |
15 | ||
16 | " --------------------------------------------------------------------- | |
17 | " Commands: {{{1 | |
18 | com! Unlarge call s:Unlarge() | |
19 | com! -bang Large call s:LargeFile(<bang>0,expand("%")) | |
20 | ||
21 | " --------------------------------------------------------------------- | |
22 | " Options: {{{1 | |
23 | if !exists("g:LargeFile") | |
24 | let g:LargeFile= 20 " in megabytes | |
25 | endif | |
26 | ||
27 | " --------------------------------------------------------------------- | |
28 | " LargeFile Autocmd: {{{1 | |
29 | " for large files: turns undo, syntax highlighting, undo off etc | |
30 | " (based on vimtip#611) | |
31 | augroup LargeFile | |
32 | au! | |
33 | au BufReadPre * call <SID>LargeFile(0,expand("<afile>")) | |
34 | au BufReadPost * | |
35 | \ if &ch < 2 && (getfsize(expand("<afile>")) >= g:LargeFile*1024*1024 || getfsize(expand("<afile>")) == -2) | |
36 | \| echomsg "***note*** handling a large file" | |
37 | \| endif | |
38 | augroup END | |
39 | ||
40 | " --------------------------------------------------------------------- | |
41 | " s:LargeFile: {{{2 | |
42 | fun! s:LargeFile(force,fname) | |
43 | " call Dfunc("LargeFile(force=".a:force." fname<".a:fname.">)") | |
44 | if a:force || getfsize(a:fname) >= g:LargeFile*1024*1024 || getfsize(a:fname) <= -2 | |
45 | syn clear | |
46 | let b:eikeep = &ei | |
47 | let b:ulkeep = &ul | |
48 | let b:bhkeep = &bh | |
49 | let b:fdmkeep= &fdm | |
50 | let b:swfkeep= &swf | |
51 | set ei=FileType | |
52 | setlocal noswf bh=unload fdm=manual ul=-1 | |
53 | let fname=escape(substitute(a:fname,'\','/','g'),' ') | |
54 | exe "au LargeFile BufEnter ".fname." set ul=-1" | |
55 | exe "au LargeFile BufLeave ".fname." let &ul=".b:ulkeep."|set ei=".b:eikeep | |
56 | exe "au LargeFile BufUnload ".fname." au! LargeFile * ". fname | |
57 | echomsg "***note*** handling a large file" | |
58 | endif | |
59 | " call Dret("s:LargeFile") | |
60 | endfun | |
61 | ||
62 | " --------------------------------------------------------------------- | |
63 | " s:Unlarge: this function will undo what the LargeFile autocmd does {{{2 | |
64 | fun! s:Unlarge() | |
65 | " call Dfunc("s:Unlarge()") | |
66 | if exists("b:eikeep") |let &ei = b:eikeep |endif | |
67 | if exists("b:ulkeep") |let &ul = b:ulkeep |endif | |
68 | if exists("b:bhkeep") |let &bh = b:bhkeep |endif | |
69 | if exists("b:fdmkeep")|let &fdm = b:fdmkeep|endif | |
70 | if exists("b:swfkeep")|let &swf = b:swfkeep|endif | |
71 | syn on | |
72 | doau FileType | |
73 | " call Dret("s:Unlarge") | |
74 | endfun | |
75 | ||
76 | " --------------------------------------------------------------------- | |
77 | " Restore: {{{1 | |
78 | let &cpo= s:keepcpo | |
79 | unlet s:keepcpo | |
80 | " vim: ts=4 fdm=marker |