Re: Make the ftplugin right wrt gitdir

Previous thread: What's in git.git by Junio C Hamano on Tuesday, October 17, 2006 - 12:44 am. (6 messages)

Next thread: Re: [PATCH 1/2] Delete ref $frotz by moving ref file to "deleted-$frotz~ref". by Jakub Narebski on Tuesday, October 17, 2006 - 2:24 am. (1 message)
From: Junio C Hamano
Date: Tuesday, October 17, 2006 - 12:46 am

I'd prefer patches to contrib/ sections to be CC'ed to the
owners of them (in this case that would be Jeff King) to be
Acked, since I do not actively maintain anything under contrib/
myself.

Jeff, are you Ok with Pierre's two patches?

-

From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:38 pm

here is a brand new set of patches, the same update on the syntax
file, and an enhanced ftplugin that is very configureable.

  Those two patches replace the two previous ones.


-

From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:39 pm

here is a brand new set of patches, the same update on the syntax
file, and an enhanced ftplugin that is very configureable.

  Those two patches replace the two previous ones.


-

From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:39 pm

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/syntax/gitcommit.vim |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
index a9de09f..d0c6e5d 100644
--- a/contrib/vim/syntax/gitcommit.vim
+++ b/contrib/vim/syntax/gitcommit.vim
@@ -1,3 +1,14 @@
+" Vim syntax file
+" Language:	git commit message
+
+" Quit when a (custom) syntax file was already loaded
+if exists("b:current_syntax")
+  finish
+endif
+
+syn region gitSignedOff start=/^Signed-off-by:/ end=/$/ contains=gitAuthor,gitEmail
+syn region gitAuthor contained start=/\s/ end=/$/
+
 syn region gitLine start=/^#/ end=/$/
 syn region gitCommit start=/^# Updated but not checked in:$/ end=/^#$/ contains=gitHead,gitCommitFile
 syn region gitHead contained start=/^#   (.*)/ end=/^#$/
@@ -8,6 +19,9 @@ syn match gitCommitFile contained /^#\t.
 syn match gitChangedFile contained /^#\t.*/hs=s+2
 syn match gitUntrackedFile contained /^#\t.*/hs=s+2
 
+hi def link gitSignedOff Keyword
+hi def link gitAuthor Normal
+
 hi def link gitLine Comment
 hi def link gitCommit Comment
 hi def link gitChanged Comment
@@ -16,3 +30,7 @@ hi def link gitUntracked Comment
 hi def link gitCommitFile Type
 hi def link gitChangedFile Constant
 hi def link gitUntrackedFile Constant
+
+let b:current_syntax = "git"
+
+" vim: ts=8 sw=2
-- 
1.4.2.3

-

From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:39 pm

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/README                 |   10 +++++
 contrib/vim/ftplugin/gitcommit.vim |   75 ++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/contrib/vim/README b/contrib/vim/README
index 9e7881f..e5ca9ae 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -6,3 +6,13 @@ To syntax highlight git's commit message
      $ cat >>$HOME/.vimrc <<'EOF'
      autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
      EOF
+
+To use the fancy split-view with the currently commited diff, you need to:
+  1. Copy ftplugin/gitcommit.vim to vim's ftplugin directory:
+     $ mkdir -p $HOME/.vim/ftplugin
+     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
+  2. Auto-detect the editing of git commit files (see above).
+  3. You can configure the diff to spawn automatically by setting:
+     let git_diff_spawn_mode = 1 (or 2) for an horiz (resp. vert) split.
+     else you have the bindings ,gd or ,ghd to spawn an horiz split with
+     the diff, and ,gvd for the same with a vertical diff.
diff --git a/contrib/vim/ftplugin/gitcommit.vim b/contrib/vim/ftplugin/gitcommit.vim
new file mode 100644
index 0000000..a9cb946
--- /dev/null
+++ b/contrib/vim/ftplugin/gitcommit.vim
@@ -0,0 +1,75 @@
+if exists("b:did_ftplugin")
+  finish
+endif
+
+let b:did_ftplugin = 1
+
+setlocal tw=74
+setlocal nowarn nowb
+
+"{{{ 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 ...
From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:40 pm

damn, sorry, that's still not the good one :|

/me feels very tired.

=2D-=20
=C2=B7O=C2=B7  Pierre Habouzit
=C2=B7=C2=B7O                                                madcoder@debia=
n.org
OOO                                                http://www.madism.org
From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:47 pm

sorry for the mess, I'm a bit tired :)
Here is a third patch to fix the plugin to find the git-dir properly.

Also add a nice shortcut to quit that buffer.


-

From: Pierre Habouzit
Date: Tuesday, October 17, 2006 - 5:47 pm

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/ftplugin/gitcommit.vim |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/contrib/vim/ftplugin/gitcommit.vim b/contrib/vim/ftplugin/gitcommit.vim
index a9cb946..e958fb1 100644
--- a/contrib/vim/ftplugin/gitcommit.vim
+++ b/contrib/vim/ftplugin/gitcommit.vim
@@ -52,9 +52,17 @@ function! Git_diff_windows(vertsplit, au
         rightbelow new
     endif
     silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
-    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd"
-    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
+    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
+    noremap <buffer> q :bw<cr>
     if a:auto
         redraw!
         wincmd p
-- 
1.4.2.3

-

From: Jeff King
Date: Wednesday, October 18, 2006 - 12:02 am

Looks like the patch is missing (more sleep required?).

-Peff
-

From: Pierre Habouzit
Date: Wednesday, October 18, 2006 - 1:10 am

err, the patch is here:=20
<1161132446703-git-send-email-madcoder@debian.org>

at least I see it on the list for my part
=2D-=20
=B7O=B7  Pierre Habouzit
=B7=B7O                                                madcoder@debian.org
OOO                                                http://www.madism.org
From: Jeff King
Date: Wednesday, October 18, 2006 - 2:02 am

Right, that's the "be more robust" patch which applies on top of
something else (presumably "nice ftplugin for vim"), but the last one I
got of that (<11611319761977-git-send-email-madcoder@debian.org>) causes
vim errors and you immediately followed up with "that's still not the
good one." Where is that patch?

-Peff
-

From: Pierre Habouzit
Date: Wednesday, October 18, 2006 - 2:07 am

hmm I see, curious though, I must have do sth stupid :|

well the result file is here:=20
http://madism.org/~madcoder/dotfiles/vim/ftplugin/git.vim

I've not access to my git repo from here, feel free to grab it and=20
commit it, I don't care if there is not my name on it.

and as of gitEmail you're right I don't use it, I wanted to to hilight=20
the email address in the gitAuthor zone, but well, basically, it sucks,=20
that makes too many colors.
=2D-=20
=C2=B7O=C2=B7  Pierre Habouzit
=C2=B7=C2=B7O                                                madcoder@debia=
n.org
OOO                                                http://www.madism.org
From: Jeff King
Date: Wednesday, October 18, 2006 - 2:46 am

Do things like tw really have anything to do with the ftplugin?

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

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'

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
-

From: Jeff King
Date: Tuesday, October 17, 2006 - 11:59 pm

I think this is a good change (along with commenting), but please write
a more descriptive commit message than "be more vim-ish" (I wouldn't
mind seeing this and the highlighting change broken into two patches,

You mention gitEmail but never define it. Are people using other things
besides Signed-off-by? I think we might do better to simply write:
  syn region gitCommentHeader start=/^[^ ]\+:/ end=/$/ contains=gitCommentValue
  syn region gitCommentValue contained start=/\s/ end=/$/

Highlighting only the header is inconsistent with other highlighting
(e.g., all of "new file: foo" is highlighted), but it looks so ugly to
highlight the whole line, so I think this is fine.

-Peff
-

Previous thread: What's in git.git by Junio C Hamano on Tuesday, October 17, 2006 - 12:44 am. (6 messages)

Next thread: Re: [PATCH 1/2] Delete ref $frotz by moving ref file to "deleted-$frotz~ref". by Jakub Narebski on Tuesday, October 17, 2006 - 2:24 am. (1 message)