git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Make the ftplugin right wrt gitdir

From
Jeff King <peff@peff.net>
Date
Oct 18, 2006, 09:46 UTC
Message-ID
<20061018094651.GA19907@coredump.intra.peff.net>
In-Reply-To
<200610181107.56260.madcoder@debian.org>
On Wed, Oct 18, 2006 at 11:07:54AM +0200, Pierre Habouzit wrote:
> well the result file is here: 
> http://madism.org/~madcoder/dotfiles/vim/ftplugin/git.vim
I was able to grab it...my comments are below.
Show 8 quoted lines
>  if exists("b:did_ftplugin")
>    finish
>  endif
>  
>  let b:did_ftplugin = 1
>  
>  setlocal tw=74
>  setlocal nowarn nowb

Do things like tw really have anything to do with the ftplugin? Shouldn't they instead go into the user's vimrc?

Show 44 quoted lines
>  "{{{ function Git_diff_windows
>  
>  function! Git_diff_windows(vertsplit, auto)
>      let i = 0
>      let list_of_files = ''
>  
>      " drop everything until '#  (will commit)' and the next empty line
>      while i <= line('$')
>          let line = getline(i)
>          if line =~ '^#\s*(will commit)$'
>              let i = i + 2
>              break
>          endif
>  
>          let i = i + 1
>      endwhile
>  
>      " read file names until we have EOF or an empty line
>      while i <= line('$')
>          let line = getline(i)
>          if line =~ '^#\s*[a-z ]*:.*->.*$'
>              let file = substitute(line, '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '')
>              let list_of_files = list_of_files . ' '.file
>              let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '')
>              let list_of_files = list_of_files . ' '.file
>          elseif line =~ '^#\s*[a-z ]*:'
>              let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$', '\1', '')
>              let list_of_files = list_of_files . ' '.file
>          elseif line =~ '^#\s*$'
>              break
>          endif
>  
>          let i = i + 1
>      endwhile
>  
>      if list_of_files == ""
>          return
>      endif
>  
>      if a:vertsplit
>          rightbelow vnew
>      else
>          rightbelow new
>      endif

This all looks OK to me, but then I don't really know vim script very well. :)

Show 11 quoted lines
>      silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
>      let gitDir = system('git rev-parse --git-dir 2>/dev/null')
>      let gitDir = substitute(gitDir, '.git\n', '', '')
>      let wd = getcwd()
>      if gitDir != ''
>          exe 'cd '.gitDir
>      endif
>      exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . "\n1Gdd"
>      exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
>      exe 'cd '.wd
>      setlocal nomodifiable

This procedure seems a bit hack-ish and fragile. I think the chdir is necessary not just to handle autochdir, but also because we want to do any diff from the top-level instead of a subdir. Why do we unconditionally set LANG=C? What about quoting for the file list?

In general, is this really that much nicer than simply using the '-v' flag to git-commit?

Show 5 quoted lines
>  if g:git_diff_spawn_mode == 1
>      call Git_diff_windows(0, 1)
>  elseif g:git_diff_spawn_mode == 2
>      call Git_diff_windows(1, 1)
>  endif
This should probably handle the case where g:git_diff_spawn_mode is not
defined (otherwise vim complains loudly):
  if exists("g:git_diff_spawn_mode")
     " do nothing
  elseif g:git_diff_spawn_mode == 1
etc.
-Peff
Previous: Pierre HabouzitNext: Jeff King
Message 22 of 23 in “be more vim-ish, and also syntax hilight Signed-off-by lines.”
  1. be more vim-ish, and also syntax hilight Signed-off-by lines.Pierre Habouzit, Oct 17, 2006
  2. nice ftplugin for vim, that shows the commited diff in a split'ed buffer.Pierre Habouzit, Oct 17, 2006
  3. Peter BaumannOct 17, 2006
  4. Pierre HabouzitOct 17, 2006
  5. Peter BaumannOct 17, 2006
  6. Pierre HabouzitOct 17, 2006
  7. Christian MICHONOct 17, 2006
  8. Junio C HamanoOct 17, 2006
  9. Petr BaudisOct 18, 2006
  10. Junio C HamanoOct 17, 2006
  11. contrib/vim patches, replace the previous setPierre Habouzit, Oct 18, 2006
  12. contrib/vim patches, replace the previous setPierre Habouzit, Oct 18, 2006
  13. be more vim-ish, and also syntax hilight Signed-off-by lines.Pierre Habouzit, Oct 18, 2006
  14. Nice ftplugin for vim, that shows the commited diff in a split'ed buffer.Pierre Habouzit, Oct 18, 2006
  15. Pierre HabouzitOct 18, 2006
  16. Make the ftplugin right wrt gitdirPierre Habouzit, Oct 18, 2006
  17. be more robust wrt the git-dir.Pierre Habouzit, Oct 18, 2006
  18. Jeff KingOct 18, 2006
  19. Pierre HabouzitOct 18, 2006
  20. Jeff KingOct 18, 2006
  21. Pierre HabouzitOct 18, 2006
  22. Jeff KingOct 18, 2006
  23. Jeff KingOct 18, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.