Skip to content
Browse files

hi

  • Loading branch information...
1 parent a360449 commit 15af61e6e9c8248c185db71bfd871d0a632275a1 @theIntuitionist committed Sep 13, 2011
View
25 bin/jslint
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+target = File.expand_path(ARGV.first)
+
+if RUBY_PLATFORM =~ /win32/i
+ js_cmd = 'cscript'
+ runjslint_ext = 'wsf'
+ plugin_path = File.join(ENV['HOME'], 'vimfiles')
+else
+ if ENV['JS_CMD']
+ js_cmd = ENV['JS_CMD']
+ else
+ js_cmd = 'js'
+ end
+ runjslint_ext = 'js'
+ plugin_path = File.join(ENV['HOME'], '.vim')
+end
+
+Dir.chdir(File.join(plugin_path, 'ftplugin', 'javascript', 'jslint')) do |dir|
+ IO.popen("#{js_cmd} runjslint.#{runjslint_ext}", 'r+') do |jslint|
+ jslint.write(File.open(target, 'r') { |f| f.read })
+ jslint.close_write
+ $stdout.write(jslint.read)
+ end
+end
View
95 doc/git-vim.txt
@@ -0,0 +1,95 @@
+*git-vim.txt* Git Bindings for Vim
+
+==============================================================================
+CONTENTS *git-vim-contents*
+
+ 1. Introduction.............................|git-vim|
+ 2. Commands.................................|git-vim-commands|
+ 3. Keymaps..................................|git-vim-keymaps|
+ 4. License..................................|git-vim-license|
+
+==============================================================================
+1. Introduction *git-vim*
+
+Git-vim provides:
+
+* Plugin files for calling git functions from inside Vim
+* Syntax files for git displays
+
+==============================================================================
+2. Commands *git-vim-commands*
+
+:GitAdd <file>
+ git-add <file> or current file if not specified.
+
+:GitCommit <args>
+ git-commit.
+
+:GitStatus
+ Show git-status of current file or repository.
+
+:GitLog
+ Show git-log of current file or repository.
+
+:GitCheckout <args>
+ git-checkout. Completes git commits.
+
+:GitDiff <args>
+ git-diff. Completes git commits.
+
+:GitPull <args>
+ git-pull.
+
+:GitPullRebase
+ git-pull —rebase.
+
+:GitPush <args>
+ git-push. Defaults to +git push origin <current-branch>+.
+
+:GitCatFile <args>
+ git-cat-file.
+
+:Git <args>
+ Does any git command.
+
+:GitVimDiffMerge
+ Experimental. Call this command on unmerged file to enter vimdiff mode.
+
+:GitVimDiffMergeDone
+ Call this command after merging.
+
+==============================================================================
+3. Keymaps *git-vim-keymaps*
+
+<Leader>gd
+ :GitDiff
+
+<Leader>gD
+ :GitDiff —cached
+
+<Leader>gs
+ :GitStatus
+
+<Leader>gl
+ :GitLog
+
+<Leader>ga
+ :GitAdd
+
+<Leader>gA
+ :GitAdd <cfile>
+
+<Leader>gc
+ :GitCommit
+
+In the git-status buffer:
+
+<Enter>
+ :GitAdd <cfile>
+
+==============================================================================
+4. License *git-vim-license*
+
+The MIT License
+
+ vim:tw=78:ts=8:ft=help
View
268 ftplugin/javascript/jslint.vim
@@ -0,0 +1,268 @@
+
+" Global Options
+"
+" Enable/Disable highlighting of errors in source.
+" Default is Enable
+" To disable the highlighting put the line
+" let g:JSLintHighlightErrorLine = 0
+" in your .vimrc
+"
+if exists("b:did_jslint_plugin")
+ finish
+else
+ let b:did_jslint_plugin = 1
+endif
+
+let s:install_dir = expand('<sfile>:p:h')
+
+au BufLeave <buffer> call s:JSLintClear()
+
+au BufEnter <buffer> call s:JSLint()
+au InsertLeave <buffer> call s:JSLint()
+"au InsertEnter <buffer> call s:JSLint()
+au BufWritePost <buffer> call s:JSLint()
+
+" due to http://tech.groups.yahoo.com/group/vimdev/message/52115
+if(!has("win32") || v:version>702)
+ au CursorHold <buffer> call s:JSLint()
+ au CursorHoldI <buffer> call s:JSLint()
+
+ au CursorHold <buffer> call s:GetJSLintMessage()
+endif
+
+au CursorMoved <buffer> call s:GetJSLintMessage()
+
+if !exists("g:JSLintHighlightErrorLine")
+ let g:JSLintHighlightErrorLine = 1
+endif
+
+if !exists("*s:JSLintUpdate")
+ function s:JSLintUpdate()
+ silent call s:JSLint()
+ call s:GetJSLintMessage()
+ endfunction
+endif
+
+if !exists(":JSLintUpdate")
+ command JSLintUpdate :call s:JSLintUpdate()
+endif
+if !exists(":JSLintToggle")
+ command JSLintToggle :let b:jslint_disabled = exists('b:jslint_disabled') ? b:jslint_disabled ? 0 : 1 : 1
+endif
+
+noremap <buffer><silent> dd dd:JSLintUpdate<CR>
+noremap <buffer><silent> dw dw:JSLintUpdate<CR>
+noremap <buffer><silent> u u:JSLintUpdate<CR>
+noremap <buffer><silent> <C-R> <C-R>:JSLintUpdate<CR>
+
+" Set up command and parameters
+if has("win32")
+ let s:cmd = 'cscript /NoLogo '
+ let s:runjslint_ext = 'wsf'
+else
+ let s:runjslint_ext = 'js'
+ if exists("$JS_CMD")
+ let s:cmd = "$JS_CMD"
+ elseif executable('/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc')
+ let s:cmd = '/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc'
+ elseif executable('node')
+ let s:cmd = 'node'
+ elseif executable('js')
+ let s:cmd = 'js'
+ else
+ echoerr('No JS interpreter found. Checked for jsc, js (spidermonkey), and node')
+ endif
+endif
+let s:plugin_path = s:install_dir . "/jslint/"
+if has('win32')
+ let s:plugin_path = substitute(s:plugin_path, '/', '\', 'g')
+endif
+let s:cmd = "cd " . s:plugin_path . " && " . s:cmd . " " . s:plugin_path . "runjslint." . s:runjslint_ext
+
+let s:jslintrc_file = expand('~/.jslintrc')
+if filereadable(s:jslintrc_file)
+ let s:jslintrc = readfile(s:jslintrc_file)
+else
+ let s:jslintrc = []
+end
+
+
+" WideMsg() prints [long] message up to (&columns-1) length
+" guaranteed without "Press Enter" prompt.
+if !exists("*s:WideMsg")
+ function s:WideMsg(msg)
+ let x=&ruler | let y=&showcmd
+ set noruler noshowcmd
+ redraw
+ echo a:msg
+ let &ruler=x | let &showcmd=y
+ endfun
+endif
+
+
+function! s:JSLintClear()
+ " Delete previous matches
+ let s:matches = getmatches()
+ for s:matchId in s:matches
+ if s:matchId['group'] == 'JSLintError'
+ call matchdelete(s:matchId['id'])
+ endif
+ endfor
+ let b:matched = []
+ let b:matchedlines = {}
+ let b:cleared = 1
+endfunction
+
+function! s:JSLint()
+ if exists("b:jslint_disabled") && b:jslint_disabled == 1
+ return
+ endif
+
+ highlight link JSLintError SpellBad
+
+ if exists("b:cleared")
+ if b:cleared == 0
+ call s:JSLintClear()
+ endif
+ let b:cleared = 1
+ endif
+
+ let b:matched = []
+ let b:matchedlines = {}
+
+ " Detect range
+ if a:firstline == a:lastline
+ " Skip a possible shebang line, e.g. for node.js script.
+ if getline(1)[0:1] == "#!"
+ let b:firstline = 2
+ else
+ let b:firstline = 1
+ endif
+ let b:lastline = '$'
+ else
+ let b:firstline = a:firstline
+ let b:lastline = a:lastline
+ endif
+
+ let b:qf_list = []
+ let b:qf_window_count = -1
+
+ let lines = join(s:jslintrc + getline(b:firstline, b:lastline), "\n")
+ if len(lines) == 0
+ return
+ endif
+ let b:jslint_output = system(s:cmd, lines . "\n")
+ if v:shell_error
+ echoerr 'could not invoke JSLint!'
+ let b:jslint_disabled = 1
+ end
+
+ for error in split(b:jslint_output, "\n")
+ " Match {line}:{char}:{message}
+ let b:parts = matchlist(error, '\v(\d+):(\d+):([A-Z]+):(.*)')
+ if !empty(b:parts)
+ let l:line = b:parts[1] + (b:firstline - 1 - len(s:jslintrc)) " Get line relative to selection
+ let l:errorMessage = b:parts[4]
+
+ " Store the error for an error under the cursor
+ let s:matchDict = {}
+ let s:matchDict['lineNum'] = l:line
+ let s:matchDict['message'] = l:errorMessage
+ let b:matchedlines[l:line] = s:matchDict
+ if b:parts[3] == 'ERROR'
+ let l:errorType = 'E'
+ else
+ let l:errorType = 'W'
+ endif
+ if g:JSLintHighlightErrorLine == 1
+ let s:mID = matchadd('JSLintError', '\v%' . l:line . 'l\S.*(\S|$)')
+ endif
+ " Add line to match list
+ call add(b:matched, s:matchDict)
+
+ " Store the error for the quickfix window
+ let l:qf_item = {}
+ let l:qf_item.bufnr = bufnr('%')
+ let l:qf_item.filename = expand('%')
+ let l:qf_item.lnum = l:line
+ let l:qf_item.text = l:errorMessage
+ let l:qf_item.type = l:errorType
+
+ " Add line to quickfix list
+ call add(b:qf_list, l:qf_item)
+ endif
+ endfor
+
+ if exists("s:jslint_qf")
+ " if jslint quickfix window is already created, reuse it
+ call s:ActivateJSLintQuickFixWindow()
+ call setqflist(b:qf_list, 'r')
+ else
+ " one jslint quickfix window for all buffers
+ call setqflist(b:qf_list, '')
+ let s:jslint_qf = s:GetQuickFixStackCount()
+ endif
+ let b:cleared = 0
+endfunction
+
+let b:showing_message = 0
+
+if !exists("*s:GetJSLintMessage")
+ function s:GetJSLintMessage()
+ let s:cursorPos = getpos(".")
+
+ " Bail if RunJSLint hasn't been called yet
+ if !exists('b:matchedlines')
+ return
+ endif
+
+ if has_key(b:matchedlines, s:cursorPos[1])
+ let s:jslintMatch = get(b:matchedlines, s:cursorPos[1])
+ call s:WideMsg(s:jslintMatch['message'])
+ let b:showing_message = 1
+ return
+ endif
+
+ if b:showing_message == 1
+ echo
+ let b:showing_message = 0
+ endif
+ endfunction
+endif
+
+if !exists("*s:GetQuickFixStackCount")
+ function s:GetQuickFixStackCount()
+ let l:stack_count = 0
+ try
+ silent colder 9
+ catch /E380:/
+ endtry
+
+ try
+ for i in range(9)
+ silent cnewer
+ let l:stack_count = l:stack_count + 1
+ endfor
+ catch /E381:/
+ return l:stack_count
+ endtry
+ endfunction
+endif
+
+if !exists("*s:ActivateJSLintQuickFixWindow")
+ function s:ActivateJSLintQuickFixWindow()
+ try
+ silent colder 9 " go to the bottom of quickfix stack
+ catch /E380:/
+ endtry
+
+ if s:jslint_qf > 0
+ try
+ exe "silent cnewer " . s:jslint_qf
+ catch /E381:/
+ echoerr "Could not activate JSLint Quickfix Window."
+ endtry
+ endif
+ endfunction
+endif
+
View
6,935 ftplugin/javascript/jslint/jslint-core.js
6,935 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
97 ftplugin/javascript/jslint/runjslint.js
@@ -0,0 +1,97 @@
+/*jslint laxbreak: true */
+
+if (typeof require != 'undefined') {
+ JSLINT = require('./jslint-core').JSLINT;
+ print = require('sys').puts;
+} else {
+ load('jslint-core.js');
+}
+
+// Import extra libraries if running in Rhino.
+if (typeof importPackage != 'undefined') {
+ importPackage(java.io);
+ importPackage(java.lang);
+}
+
+var readSTDIN = (function() {
+ // readSTDIN() definition for nodejs
+ if (typeof process != 'undefined' && process.openStdin) {
+ return function readSTDIN(callback) {
+ var stdin = process.openStdin()
+ , body = [];
+
+ stdin.on('data', function(chunk) {
+ body.push(chunk);
+ });
+
+ stdin.on('end', function(chunk) {
+ callback(body.join('\n'));
+ });
+ };
+
+ // readSTDIN() definition for Rhino
+ } else if (typeof BufferedReader != 'undefined') {
+ return function readSTDIN(callback) {
+ // setup the input buffer and output buffer
+ var stdin = new BufferedReader(new InputStreamReader(System['in'])),
+ lines = [];
+
+ // read stdin buffer until EOF (or skip)
+ while (stdin.ready()){
+ lines.push(stdin.readLine());
+ }
+
+ callback(lines.join('\n'));
+ };
+
+ // readSTDIN() definition for Spidermonkey
+ } else if (typeof readline != 'undefined') {
+ return function readSTDIN(callback) {
+ var line
+ , input = []
+ , emptyCount = 0
+ , i;
+
+ line = readline();
+ while (emptyCount < 25) {
+ input.push(line);
+ if (line) {
+ emptyCount = 0;
+ } else {
+ emptyCount += 1;
+ }
+ line = readline();
+ }
+
+ input.splice(-emptyCount);
+ callback(input.join('\n'));
+ };
+ }
+})();
+
+readSTDIN(function(body) {
+ var ok = JSLINT(body)
+ , i
+ , error
+ , errorType
+ , nextError
+ , errorCount
+ , WARN = 'WARNING'
+ , ERROR = 'ERROR';
+
+ if (!ok) {
+ errorCount = JSLINT.errors.length;
+ for (i = 0; i < errorCount; i += 1) {
+ error = JSLINT.errors[i];
+ errorType = WARN;
+ nextError = i < errorCount ? JSLINT.errors[i+1] : null;
+ if (error && error.reason && error.reason.match(/^Stopping/) === null) {
+ // If jslint stops next, this was an actual error
+ if (nextError && nextError.reason && nextError.reason.match(/^Stopping/) !== null) {
+ errorType = ERROR;
+ }
+ print([error.line, error.character, errorType, error.reason].join(":"));
+ }
+ }
+ }
+});
View
39 ftplugin/javascript/jslint/runjslint.wsf
@@ -0,0 +1,39 @@
+<job>
+<script src="jslint-core.js" language="javascript"></script>
+<script language="javascript">
+/*global JSLINT load readline WScript */
+
+var readSTDIN = function() {
+ var line,
+ input = [],
+ emptyCount = 0,
+ i;
+
+ var stdIn = WScript.stdIn,
+ stdOut = WScript.stdOut;
+
+ while (!stdIn.atEndofStream) {
+ line = stdIn.readLine();
+ input.push(line);
+ }
+
+ return input.join("\n");
+};
+
+var body = readSTDIN() || arguments[0],
+ ok = JSLINT(body),
+ i,
+ error,
+ errorCount;
+
+if (!ok) {
+ errorCount = JSLINT.errors.length;
+ for (i = 0; i < errorCount; i += 1) {
+ error = JSLINT.errors[i];
+ if (error && error.reason && error.reason.match(/^Stopping/) === null) {
+ WScript.echo([error.line, error.character, error.reason].join(":"));
+ }
+ }
+}
+</script>
+</job>
View
372 plugin/git.vim
@@ -0,0 +1,372 @@
+" Author: motemen <motemen@gmail.com>
+" License: The MIT License
+" URL: http://github.com/motemen/git-vim/
+
+if !exists('g:git_command_edit')
+ let g:git_command_edit = 'new'
+endif
+
+if !exists('g:git_bufhidden')
+ let g:git_bufhidden = ''
+endif
+
+if !exists('g:git_bin')
+ let g:git_bin = 'git'
+endif
+
+if !exists('g:git_author_highlight')
+ let g:git_author_highlight = { }
+endif
+
+if !exists('g:git_highlight_blame')
+ let g:git_highlight_blame = 0
+endif
+
+if !exists('g:git_no_map_default') || !g:git_no_map_default
+ nnoremap <Leader>gd :GitDiff<Enter>
+ nnoremap <Leader>gD :GitDiff --cached<Enter>
+ nnoremap <Leader>gs :GitStatus<Enter>
+ nnoremap <Leader>gl :GitLog<Enter>
+ nnoremap <Leader>ga :GitAdd<Enter>
+ nnoremap <Leader>gA :GitAdd <cfile><Enter>
+ nnoremap <Leader>gc :GitCommit<Enter>
+ nnoremap <Leader>gp :GitPullRebase<Enter>
+endif
+
+" Ensure b:git_dir exists.
+function! s:GetGitDir()
+ if !exists('b:git_dir')
+ let b:git_dir = s:SystemGit('rev-parse --git-dir')
+ if !v:shell_error
+ let b:git_dir = fnamemodify(split(b:git_dir, "\n")[0], ':p') . '/'
+ endif
+ endif
+ return b:git_dir
+endfunction
+
+" Returns current git branch.
+" Call inside 'statusline' or 'titlestring'.
+function! GitBranch()
+ let git_dir = <SID>GetGitDir()
+
+ if strlen(git_dir) && filereadable(git_dir . '/HEAD')
+ let lines = readfile(git_dir . '/HEAD')
+ if !len(lines)
+ return ''
+ else
+ return matchstr(lines[0], 'refs/heads/\zs.\+$')
+ endif
+ else
+ return ''
+ endif
+endfunction
+
+" List all git local branches.
+function! ListGitBranches(arg_lead, cmd_line, cursor_pos)
+ let branches = split(s:SystemGit('branch'), '\n')
+ if v:shell_error
+ return []
+ endif
+
+ return map(branches, 'matchstr(v:val, ''^[* ] \zs.*'')')
+endfunction
+
+" List all git commits.
+function! ListGitCommits(arg_lead, cmd_line, cursor_pos)
+ let commits = split(s:SystemGit('log --pretty=format:%h'))
+ if v:shell_error
+ return []
+ endif
+
+ let commits = ['HEAD'] + ListGitBranches(a:arg_lead, a:cmd_line, a:cursor_pos) + commits
+
+ if a:cmd_line =~ '^GitDiff'
+ " GitDiff accepts <commit>..<commit>
+ if a:arg_lead =~ '\.\.'
+ let pre = matchstr(a:arg_lead, '.*\.\.\ze')
+ let commits = map(commits, 'pre . v:val')
+ endif
+ endif
+
+ return filter(commits, 'match(v:val, ''\v'' . a:arg_lead) == 0')
+endfunction
+
+" Show diff.
+function! GitDiff(args)
+ let git_output = s:SystemGit('diff ' . a:args . ' -- ' . s:Expand('%'))
+ if !strlen(git_output)
+ echo "No output from git command"
+ return
+ endif
+
+ call <SID>OpenGitBuffer(git_output)
+ setlocal filetype=git-diff
+endfunction
+
+" Show Status.
+function! GitStatus()
+ let git_output = s:SystemGit('status')
+ call <SID>OpenGitBuffer(git_output)
+ setlocal filetype=git-status
+ nnoremap <buffer> <Enter> :GitAdd <cfile><Enter>:call <SID>RefreshGitStatus()<Enter>
+ nnoremap <buffer> - :silent !git reset HEAD -- =expand('<cfile>')<Enter><Enter>:call <SID>RefreshGitStatus()<Enter>
+endfunction
+
+function! s:RefreshGitStatus()
+ let pos_save = getpos('.')
+ GitStatus
+ call setpos('.', pos_save)
+endfunction
+
+" Show Log.
+function! GitLog(args)
+ let git_output = s:SystemGit('log ' . a:args . ' -- ' . s:Expand('%'))
+ call <SID>OpenGitBuffer(git_output)
+ setlocal filetype=git-log
+endfunction
+
+" Add file to index.
+function! GitAdd(expr)
+ let file = s:Expand(strlen(a:expr) ? a:expr : '%')
+
+ call GitDoCommand('add ' . file)
+endfunction
+
+" Commit.
+function! GitCommit(args)
+ let git_dir = <SID>GetGitDir()
+
+ let args = a:args
+
+ if args !~ '\v\k@<!(-a|--all)>' && s:SystemGit('diff --cached --stat') =~ '^\(\s\|\n\)*$'
+ let args .= ' -a'
+ endif
+
+ " Create COMMIT_EDITMSG file
+ let editor_save = $EDITOR
+ let $EDITOR = ''
+ let git_output = s:SystemGit('commit ' . args)
+ let $EDITOR = editor_save
+
+ let cur_dir = getcwd()
+ execute printf('%s %sCOMMIT_EDITMSG', g:git_command_edit, git_dir)
+ execute printf("lcd %s", cur_dir)
+
+ setlocal filetype=git-status bufhidden=wipe
+ augroup GitCommit
+ autocmd BufWritePre <buffer> g/^#\|^\s*$/d | setlocal fileencoding=utf-8
+ execute printf("autocmd BufEnter <buffer> lcd %s", cur_dir)
+ execute printf("autocmd BufWritePost <buffer> call GitDoCommand('commit %s -F ' . expand('%%')) | autocmd! GitCommit * <buffer>", args)
+ augroup END
+endfunction
+
+" Checkout.
+function! GitCheckout(args)
+ call GitDoCommand('checkout ' . a:args)
+endfunction
+
+" Push.
+function! GitPush(args)
+" call GitDoCommand('push ' . a:args)
+ " Wanna see progress...
+ let args = a:args
+ if args =~ '^\s*$'
+ let args = 'origin ' . GitBranch()
+ endif
+ execute '!' g:git_bin 'push' args
+endfunction
+
+" Pull.
+function! GitPull(args)
+" call GitDoCommand('pull ' . a:args)
+ " Wanna see progress...
+ execute '!' g:git_bin 'pull' a:args
+endfunction
+
+" Show commit, tree, blobs.
+function! GitCatFile(file)
+ let file = s:Expand(a:file)
+ let git_output = s:SystemGit('cat-file -p ' . file)
+ if !strlen(git_output)
+ echo "No output from git command"
+ return
+ endif
+
+ call <SID>OpenGitBuffer(git_output)
+endfunction
+
+" Show revision and author for each line.
+function! GitBlame(...)
+ let l:git_blame_width = 20
+ let git_output = s:SystemGit('blame -- ' . expand('%'))
+ if !strlen(git_output)
+ echo "No output from git command"
+ return
+ endif
+
+ if strlen(a:1)
+ let l:git_blame_width = a:1
+ endif
+
+ setlocal noscrollbind
+
+ " :/
+ let git_command_edit_save = g:git_command_edit
+ let g:git_command_edit = 'leftabove vnew'
+ call <SID>OpenGitBuffer(git_output)
+ let g:git_command_edit = git_command_edit_save
+
+ setlocal modifiable
+ silent %s/\d\d\d\d\zs \+\d\+).*//
+ exe 'vertical resize ' . git_blame_width
+ setlocal nomodifiable
+ setlocal nowrap scrollbind
+
+ if g:git_highlight_blame
+ call s:DoHighlightGitBlame()
+ endif
+
+ wincmd p
+ setlocal nowrap scrollbind
+
+ syncbind
+endfunction
+
+
+
+
+" Experimental
+function! s:DoHighlightGitBlame()
+ for l in range(1, line('$'))
+ let line = getline(l)
+ let [commit, author] = matchlist(line, '\(\x\+\) (\(.\{-}\)\s* \d\d\d\d-\d\d-\d\d')[1:2]
+ call s:LoadSyntaxRuleFor({ 'author': author })
+ endfor
+endfunction
+
+function! s:LoadSyntaxRuleFor(params)
+ let author = a:params.author
+ let name = 'gitBlameAuthor_' . substitute(author, '\s', '_', 'g')
+ if (!hlID(name))
+ if has_key(g:git_author_highlight, author)
+ execute 'highlight' name g:git_author_highlight[author]
+ else
+ let [n1, n2] = [0, 1]
+ for c in split(author, '\zs')
+ let n1 = (n1 + char2nr(c)) % 8
+ let n2 = (n2 + char2nr(c) * 3) % 8
+ endfor
+ if n1 == n2
+ let n1 = (n2 + 1) % 8
+ endif
+ execute 'highlight' name printf('ctermfg=%d ctermbg=%d', n1, n2)
+ endif
+ execute 'syntax match' name '"\V\^\x\+ (' . escape(author, '\') . '\.\*"'
+ endif
+endfunction
+
+function! GitDoCommand(args)
+ let git_output = s:SystemGit(a:args)
+ let git_output = substitute(git_output, '\n*$', '', '')
+ if v:shell_error
+ echohl Error
+ echo git_output
+ echohl None
+ else
+ echo git_output
+ endif
+endfunction
+
+function! s:SystemGit(args)
+ " workardound for MacVim, on which shell does not inherit environment
+ " variables
+ if has('mac') && &shell =~ 'sh$'
+ return system('EDITOR="" '. g:git_bin . ' ' . a:args)
+ else
+ return system(g:git_bin . ' ' . a:args)
+ endif
+endfunction
+
+" Show vimdiff for merge. (experimental)
+function! GitVimDiffMerge()
+ let file = s:Expand('%')
+ let filetype = &filetype
+ let t:git_vimdiff_original_bufnr = bufnr('%')
+ let t:git_vimdiff_buffers = []
+
+ topleft new
+ setlocal buftype=nofile
+ file `=':2:' . file`
+ call add(t:git_vimdiff_buffers, bufnr('%'))
+ execute 'silent read!git show :2:' . file
+ 0d
+ diffthis
+ let &filetype = filetype
+
+ rightbelow vnew
+ setlocal buftype=nofile
+ file `=':3:' . file`
+ call add(t:git_vimdiff_buffers, bufnr('%'))
+ execute 'silent read!git show :3:' . file
+ 0d
+ diffthis
+ let &filetype = filetype
+endfunction
+
+function! GitVimDiffMergeDone()
+ if exists('t:git_vimdiff_original_bufnr') && exists('t:git_vimdiff_buffers')
+ if getbufline(t:git_vimdiff_buffers[0], 1, '$') == getbufline(t:git_vimdiff_buffers[1], 1, '$')
+ execute 'sbuffer ' . t:git_vimdiff_original_bufnr
+ 0put=getbufline(t:git_vimdiff_buffers[0], 1, '$')
+ normal! jdG
+ update
+ execute 'bdelete ' . t:git_vimdiff_buffers[0]
+ execute 'bdelete ' . t:git_vimdiff_buffers[1]
+ close
+ else
+ echohl Error
+ echo 'There still remains conflict'
+ echohl None
+ endif
+ endif
+endfunction
+
+function! s:OpenGitBuffer(content)
+ if exists('b:is_git_msg_buffer') && b:is_git_msg_buffer
+ enew!
+ else
+ execute g:git_command_edit
+ endif
+
+ setlocal buftype=nofile readonly modifiable
+ execute 'setlocal bufhidden=' . g:git_bufhidden
+
+ silent put=a:content
+ keepjumps 0d
+ setlocal nomodifiable
+
+ let b:is_git_msg_buffer = 1
+endfunction
+
+function! s:Expand(expr)
+ if has('win32')
+ return substitute(expand(a:expr), '\', '/', 'g')
+ else
+ return expand(a:expr)
+ endif
+endfunction
+
+command! -nargs=1 -complete=customlist,ListGitCommits GitCheckout call GitCheckout(<q-args>)
+command! -nargs=* -complete=customlist,ListGitCommits GitDiff call GitDiff(<q-args>)
+command! GitStatus call GitStatus()
+command! -nargs=? GitAdd call GitAdd(<q-args>)
+command! -nargs=* GitLog call GitLog(<q-args>)
+command! -nargs=* GitCommit call GitCommit(<q-args>)
+command! -nargs=1 GitCatFile call GitCatFile(<q-args>)
+command! -nargs=? GitBlame call GitBlame(<q-args>)
+command! -nargs=+ Git call GitDoCommand(<q-args>)
+command! GitVimDiffMerge call GitVimDiffMerge()
+command! GitVimDiffMergeDone call GitVimDiffMergeDone()
+command! -nargs=* GitPull call GitPull(<q-args>)
+command! GitPullRebase call GitPull('--rebase')
+command! -nargs=* GitPush call GitPush(<q-args>)
View
8 syntax/git-diff.vim
@@ -0,0 +1,8 @@
+runtime syntax/diff.vim
+
+syntax match gitDiffStatLine /^ .\{-}\zs[+-]\+$/ contains=gitDiffStatAdd,gitDiffStatDelete
+syntax match gitDiffStatAdd /+/ contained
+syntax match gitDiffStatDelete /-/ contained
+
+highlight gitDiffStatAdd ctermfg=2
+highlight gitDiffStatDelete ctermfg=5
View
3 syntax/git-log.vim
@@ -0,0 +1,3 @@
+syntax match gitLogCommit +^commit \x\{40}+
+
+highlight link gitLogCommit Statement
View
18 syntax/git-status.vim
@@ -0,0 +1,18 @@
+runtime syntax/diff.vim
+setlocal filetype=
+
+syntax match gitStatusComment +^#.*+ contains=ALL
+
+syntax match gitStatusBranch +On branch .\++
+
+syntax match gitStatusUndracked +\t\zs.\++
+syntax match gitStatusNewFile +\t\zsnew file: .\++
+syntax match gitStatusModified +\t\zsmodified: .\++
+
+highlight link gitStatusComment Comment
+
+highlight link gitStatusBranch Title
+
+highlight link gitStatusUndracked diffOnly
+highlight link gitStatusNewFile diffAdded
+highlight link gitStatusModified diffChanged

0 comments on commit 15af61e

Please sign in to comment.
Something went wrong with that request. Please try again.