Changeset 7112 for dotfiles/vim

Show
Ignore:
Timestamp:
02/25/08 02:38:17 (7 years ago)
Author:
kana
Message:

dotfiles/vim/kana:
* Fix incorrect {rhs} for "t'z".
* Revise the placement of s:SID_PREFIX().
* Add s:vcs_branch_name().
* Modify 'tabline' to show s:vcs_branch_name().

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dotfiles/vim/kana/dot.vimrc

    r7029 r7112  
    8383 
    8484set nocompatible  " to use many extensions of Vim. 
     85 
     86 
     87function! s:SID_PREFIX() 
     88 return matchstr(expand('<sfile>'), '<SNR>\d\+_') 
     89endfunction 
    8590 
    8691 
     
    192197set viminfo=<50,'10,h,r/a,n~/.viminfo 
    193198 
    194 function! s:SID_PREFIX() 
    195  return matchstr(expand('<sfile>'), '<SNR>\d\+_') 
    196 endfunction 
    197  
    198199" default 'statusline' with 'fileencoding'. 
    199200let &statusline = '' 
     
    201202let &statusline .= '%=' 
    202203  "" temporary disabled. 
    203   "let &statusline .= '(%{' . s:SID_PREFIX() . 'ReposBranch(getcwd())}) ' 
     204  "let &statusline .= '(%{' . s:SID_PREFIX() . 'vcs_branch_name(getcwd())}) ' 
    204205let &statusline .= '[%{&fileencoding == "" ? &encoding : &fileencoding}]' 
    205206let &statusline .= '  %-14.(%l,%c%V%) %P' 
     
    229230 
    230231  let s .= '%#TabLineFill#%T' 
    231   let s .= '%=%#TabLine#%999Xx%X' 
     232  let s .= '%=%#TabLine#' 
     233  let branch_name = s:vcs_branch_name(getcwd()) 
     234  if branch_name != '' 
     235    let s .= '(' . branch_name . ') ' 
     236  endif 
     237  let s .= '%999Xx%X' 
    232238  return s 
    233239endfunction "}}} 
     
    649655 
    650656 
     657" VCS branch name  "{{{2 
     658" Returns the name of the current branch of the given directory. 
     659" BUGS: git is only supported. 
     660let s:_vcs_branch_name_cache = {}  " dir_path = [branch_name, key_file_mtime] 
     661 
     662 
     663function! s:vcs_branch_name(dir) 
     664  let cache_entry = get(s:_vcs_branch_name_cache, a:dir, 0) 
     665  if cache_entry is 0 
     666   \ || cache_entry[1] < getftime(s:_vcs_branch_name_key_file(a:dir)) 
     667    unlet cache_entry 
     668    let cache_entry = s:_vcs_branch_name(a:dir) 
     669    let s:_vcs_branch_name_cache[a:dir] = cache_entry 
     670  endif 
     671 
     672  return cache_entry[0] 
     673endfunction 
     674 
     675 
     676function! s:_vcs_branch_name_key_file(dir) 
     677  return a:dir . '/.git/HEAD' 
     678endfunction 
     679 
     680 
     681function! s:_vcs_branch_name(dir) 
     682  let head_file = s:_vcs_branch_name_key_file(a:dir) 
     683  let branch_name = '' 
     684 
     685  if filereadable(head_file) 
     686    let ref_info = s:first_line(head_file) 
     687    if ref_info =~ '^\x\{40}$' 
     688      let remote_branches = split(glob(a:dir . '/.git/refs/remotes/*'), "\n") 
     689      call filter(remote_branches, 's:first_line(v:val) ==# ref_info') 
     690      if 1 <= len(remote_branches) 
     691        let branch_name = matchlist(remote_branches[0], '/\([^/]*\)$')[1] 
     692      endif 
     693    else 
     694      let branch_name = matchlist(ref_info, '^ref: refs/heads/\(\S\+\)$')[1] 
     695      if branch_name == '' 
     696        let branch_name = ref_info 
     697      endif 
     698    endif 
     699  endif 
     700 
     701  return [branch_name, getftime(head_file)] 
     702endfunction 
     703 
     704 
     705 
     706 
    651707" Misc.  "{{{2 
    652708 
     
    781837 
    782838 
    783 " Returns the name of the current branch of the given directory. 
    784 " BUGS: git is only supported. 
    785 function! s:ReposBranch(dir) 
    786   let head_file = a:dir . '/.git/HEAD' 
    787   let branch_name = '?' 
    788  
    789   if filereadable(head_file) 
    790     let ref_info = s:first_line(head_file) 
    791     if ref_info =~ '^\x\{40}$' 
    792       let remote_branches = split(glob(a:dir . '/.git/refs/remotes/*'), "\n") 
    793       call filter(remote_branches, 's:first_line(v:val) ==# ref_info') 
    794       if 1 <= len(remote_branches) 
    795         let branch_name = matchlist(remote_branches[0], '/\([^/]*\)$')[1] 
    796       endif 
    797     else 
    798       let branch_name = matchlist(ref_info, '^ref: refs/heads/\(\S\+\)$')[1] 
    799       if branch_name == '' 
    800         let branch_name = ref_info 
    801       endif 
    802     endif 
    803   endif 
    804  
    805   return branch_name 
    806 endfunction 
    807  
    808  
    809839function! s:first_line(file) 
    810840  let lines = readfile(a:file, '', 1) 
     
    867897" BUGS: t'' is not related to the default meaning of ''. 
    868898nnoremap <silent> t'c        :<C-u>pclose<Return> 
    869 nmap              t'z        t'z 
     899nmap              t'z        t'c 
    870900nmap              t''        t'c 
    871901