From: Iain Patterson Date: Sun, 28 Jun 2009 14:36:27 +0000 (+0100) Subject: Feature tidyup. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=51df94caeca32b071b1cfbc2ce81b0988e1ffbe6;p=profile.git Feature tidyup. Check for the signs feature before trying to use sign-related functions. Batch up startup resize operations to avoid racing with screen. --- diff --git a/.vimrc b/.vimrc index 7ac76ec..c3eee65 100644 --- a/.vimrc +++ b/.vimrc @@ -80,7 +80,9 @@ se mouse=nvir " Update more quickly. For use with sign highlighting as polling for " CursorMove makes redrawing slow. -se updatetime=500 +if has("signs") + se updatetime=500 +endif " Enable tab-completion prompting for commands. se wildmenu @@ -98,8 +100,10 @@ augroup Display autocmd! augroup Mode autocmd! -augroup Signs -autocmd! +if has("signs") + augroup Signs + autocmd! +endif augroup StatusLine autocmd! augroup END @@ -153,11 +157,13 @@ fun! Iain_Vars() if ! exists("g:iainextracolumns") let g:iainextracolumns = 0 endif - if ! exists("g:marksigns") - let g:marksigns = 0 - endif - if ! exists("g:firstsign") - let g:firstsign = 100 + if has("signs") + if ! exists("g:marksigns") + let g:marksigns = 0 + endif + if ! exists("g:firstsign") + let g:firstsign = 100 + endif endif endfun @@ -265,7 +271,7 @@ fun! Resize_Columns(op, ...) endfun " Toggle number display. -fun! Number() +fun! Number(resize) call Iain_Vars() let &number = ! &number @@ -281,16 +287,20 @@ fun! Number() if l:num_numbers == 0 let g:iainextracolumns = 0 - call Resize_Columns("-") + if a:resize + call Resize_Columns("-") + endif elseif g:iainextracolumns == 0 let g:iainextracolumns = 1 - call Resize_Columns("+") + if a:resize + call Resize_Columns("+") + endif endif endif endfun " Restore window size. -au Display VimLeave * if exists("oldcols") | let &columns=oldcols | endif +au Display VimLeave * if exists("oldcols") | call Resize_Columns("-", (&columns - oldcols)) | endif " Map Makefile mode. au Mode BufEnter * if &ft == "make" | call MakeMode_map() | endif @@ -343,7 +353,7 @@ call Mapping("p", ":se paste!:") " Swap case-sensitivity with \c. call Mapping("c", ":call Invert_Case():") " Change number mode with \n. -call Mapping("n", ":call Number():") +call Mapping("n", ":call Number(1):") " Expand or shrink window size with \> and \<. call Mapping(">", ":call Resize_Columns('+'):") call Mapping("<", ":call Resize_Columns('-'):") @@ -356,8 +366,29 @@ map Q " Vim tip 99: What's the highlighting group under the cursor? call Mapping("h", ":echo \"hi<\" . synIDattr(synID(line(\".\"),col(\".\"),1),\"name\") . '> trans<' . synIDattr(synID(line(\".\"),col(\".\"),0),\"name\") . \"> lo<\" . synIDattr(synIDtrans(synID(line(\".\"),col(\".\"),1)),\"name\") . \">\"") +fun! Startup_Resize() + " Resize for numbers. + if version >= "700" + let l:columns = &numberwidth + else + let l:columns = 8 + endif + + " Resize for signs. + if has("signs") + if version >= "600" + let l:columns += 2 + endif + endif + + call Resize_Columns("+", l:columns) +endfun + " Show numbers by default. -au Display VimEnter * call Number() +au Display VimEnter * call Number(0) + +" Resize after startup. +au Display VimEnter * call Startup_Resize() endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -413,8 +444,10 @@ vnoremap * y/\V=substitute(escape(@@,"/\\"),"\n","\\\\n","ge") vnoremap # y?\V=substitute(escape(@@,"?\\"),"\n","\\\\n","ge") " Set mark and update highlighting. -au Signs BufEnter * call Highlight_Signs() -au Signs CursorHold * call Highlight_Signs() +if has("signs") + au Signs BufEnter * call Highlight_Signs() + au Signs CursorHold * call Highlight_Signs() +endif fun! Prep_Signs() if ! exists("b:signdot") || ! g:marksigns @@ -491,7 +524,7 @@ fun! Place_Sign(number, line, old, name) endfun fun! Highlight_Signs(...) - if ! g:marksigns + if ! has("signs") || ! g:marksigns return endif @@ -521,7 +554,10 @@ fun! Highlight_Signs(...) endfun " Toggle signs. -fun! Cycle_Signs() +fun! Cycle_Signs(resize) + if ! has("signs") + return + endif call Iain_Vars() let g:marksigns = ! g:marksigns @@ -549,7 +585,9 @@ fun! Cycle_Signs() sign define MarkE text=E texthl=MarkSign linehl=MarkLine sign define MarkF text=F texthl=MarkSign linehl=MarkLine - call Resize_Columns("+", 2) + if a:resize + call Resize_Columns("+", 2) + endif call Highlight_Signs() else exe "sign unplace " . (g:firstsign + 0) @@ -595,7 +633,9 @@ fun! Cycle_Signs() sign undefine MarkF call Prep_Signs() - call Resize_Columns("-", 2) + if a:resize + call Resize_Columns("-", 2) + endif endif endfun @@ -658,7 +698,7 @@ call Mapping("q", ":call Cycle_Quickfix():") " updated as a side-effect. call Mapping("s", ":filetype detect:") " Toggle marks with \m. -call Mapping("m", ":call Cycle_Signs():") +call Mapping("m", ":call Cycle_Signs(1):") fun! Iain_Colour(colour) if &t_Co == 88 @@ -731,13 +771,13 @@ fun! Highlight_StatusLine(flag) let l:termcolour = Iain_Colour(l:colour) - exec "highlight StatusLine guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour + exec "highlight StatusLine gui=bold term=bold cterm=bold guifg=white guibg=" . l:colour . " ctermfg=white ctermbg=" . l:termcolour endfun au Display VimEnter * call Highlight_StatusLine("") " Show signs by default. -au Display VimEnter * call Cycle_Signs() +au Display VimEnter * call Cycle_Signs(0) endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -824,8 +864,10 @@ au StatusLine FocusLost * call Highlight_StatusLine("f") au StatusLine InsertEnter * call Highlight_StatusLine("I") au StatusLine InsertLeave * call Highlight_StatusLine("i") -au Signs InsertEnter * call Highlight_Signs() -au Signs InsertLeave * call Highlight_Signs() +if has("signs") + au Signs InsertEnter * call Highlight_Signs() + au Signs InsertLeave * call Highlight_Signs() +endif " Limit the size of the popup menu when completing. se pumheight=20