Abort functions at first error.

This commit is contained in:
Andy Stewart
2016-05-13 14:14:41 +01:00
parent 264d7f3a66
commit cae4f72aa1
9 changed files with 102 additions and 102 deletions

View File

@@ -2,7 +2,7 @@ let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ?
" Primary functions {{{ " Primary functions {{{
function! gitgutter#all() function! gitgutter#all() abort
for buffer_id in tabpagebuflist() for buffer_id in tabpagebuflist()
let file = expand('#' . buffer_id . ':p') let file = expand('#' . buffer_id . ':p')
if !empty(file) if !empty(file)
@@ -13,7 +13,7 @@ endfunction
" bufnr: (integer) the buffer to process. " bufnr: (integer) the buffer to process.
" realtime: (boolean) when truthy, do a realtime diff; otherwise do a disk-based diff. " realtime: (boolean) when truthy, do a realtime diff; otherwise do a disk-based diff.
function! gitgutter#process_buffer(bufnr, realtime) function! gitgutter#process_buffer(bufnr, realtime) abort
call gitgutter#utility#set_buffer(a:bufnr) call gitgutter#utility#set_buffer(a:bufnr)
if gitgutter#utility#is_active() if gitgutter#utility#is_active()
if g:gitgutter_sign_column_always if g:gitgutter_sign_column_always
@@ -37,7 +37,7 @@ function! gitgutter#process_buffer(bufnr, realtime)
endfunction endfunction
function! gitgutter#handle_diff(diff) function! gitgutter#handle_diff(diff) abort
call gitgutter#debug#log(a:diff) call gitgutter#debug#log(a:diff)
call setbufvar(gitgutter#utility#bufnr(), 'gitgutter_tracked', 1) call setbufvar(gitgutter#utility#bufnr(), 'gitgutter_tracked', 1)
@@ -58,7 +58,7 @@ function! gitgutter#handle_diff(diff)
call gitgutter#utility#save_last_seen_change() call gitgutter#utility#save_last_seen_change()
endfunction endfunction
function! gitgutter#disable() function! gitgutter#disable() abort
" get list of all buffers (across all tabs) " get list of all buffers (across all tabs)
let buflist = [] let buflist = []
for i in range(tabpagenr('$')) for i in range(tabpagenr('$'))
@@ -78,12 +78,12 @@ function! gitgutter#disable()
let g:gitgutter_enabled = 0 let g:gitgutter_enabled = 0
endfunction endfunction
function! gitgutter#enable() function! gitgutter#enable() abort
let g:gitgutter_enabled = 1 let g:gitgutter_enabled = 1
call gitgutter#all() call gitgutter#all()
endfunction endfunction
function! gitgutter#toggle() function! gitgutter#toggle() abort
if g:gitgutter_enabled if g:gitgutter_enabled
call gitgutter#disable() call gitgutter#disable()
else else
@@ -95,7 +95,7 @@ endfunction
" Line highlights {{{ " Line highlights {{{
function! gitgutter#line_highlights_disable() function! gitgutter#line_highlights_disable() abort
let g:gitgutter_highlight_lines = 0 let g:gitgutter_highlight_lines = 0
call gitgutter#highlight#define_sign_line_highlights() call gitgutter#highlight#define_sign_line_highlights()
@@ -107,7 +107,7 @@ function! gitgutter#line_highlights_disable()
redraw! redraw!
endfunction endfunction
function! gitgutter#line_highlights_enable() function! gitgutter#line_highlights_enable() abort
let old_highlight_lines = g:gitgutter_highlight_lines let old_highlight_lines = g:gitgutter_highlight_lines
let g:gitgutter_highlight_lines = 1 let g:gitgutter_highlight_lines = 1
@@ -120,7 +120,7 @@ function! gitgutter#line_highlights_enable()
redraw! redraw!
endfunction endfunction
function! gitgutter#line_highlights_toggle() function! gitgutter#line_highlights_toggle() abort
if g:gitgutter_highlight_lines if g:gitgutter_highlight_lines
call gitgutter#line_highlights_disable() call gitgutter#line_highlights_disable()
else else
@@ -132,7 +132,7 @@ endfunction
" Signs {{{ " Signs {{{
function! gitgutter#signs_enable() function! gitgutter#signs_enable() abort
let old_signs = g:gitgutter_signs let old_signs = g:gitgutter_signs
let g:gitgutter_signs = 1 let g:gitgutter_signs = 1
@@ -143,7 +143,7 @@ function! gitgutter#signs_enable()
endif endif
endfunction endfunction
function! gitgutter#signs_disable() function! gitgutter#signs_disable() abort
let g:gitgutter_signs = 0 let g:gitgutter_signs = 0
call gitgutter#highlight#define_sign_text_highlights() call gitgutter#highlight#define_sign_text_highlights()
@@ -153,7 +153,7 @@ function! gitgutter#signs_disable()
endif endif
endfunction endfunction
function! gitgutter#signs_toggle() function! gitgutter#signs_toggle() abort
if g:gitgutter_signs if g:gitgutter_signs
call gitgutter#signs_disable() call gitgutter#signs_disable()
else else
@@ -165,7 +165,7 @@ endfunction
" Hunks {{{ " Hunks {{{
function! gitgutter#stage_hunk() function! gitgutter#stage_hunk() abort
if gitgutter#utility#is_active() if gitgutter#utility#is_active()
" Ensure the working copy of the file is up to date. " Ensure the working copy of the file is up to date.
" It doesn't make sense to stage a hunk otherwise. " It doesn't make sense to stage a hunk otherwise.
@@ -187,7 +187,7 @@ function! gitgutter#stage_hunk()
endif endif
endfunction endfunction
function! gitgutter#undo_hunk() function! gitgutter#undo_hunk() abort
if gitgutter#utility#is_active() if gitgutter#utility#is_active()
" Ensure the working copy of the file is up to date. " Ensure the working copy of the file is up to date.
" It doesn't make sense to stage a hunk otherwise. " It doesn't make sense to stage a hunk otherwise.
@@ -209,7 +209,7 @@ function! gitgutter#undo_hunk()
endif endif
endfunction endfunction
function! gitgutter#preview_hunk() function! gitgutter#preview_hunk() abort
if gitgutter#utility#is_active() if gitgutter#utility#is_active()
" Ensure the working copy of the file is up to date. " Ensure the working copy of the file is up to date.
" It doesn't make sense to stage a hunk otherwise. " It doesn't make sense to stage a hunk otherwise.

View File

@@ -5,7 +5,7 @@ function! gitgutter#async#available()
return s:available return s:available
endfunction endfunction
function! gitgutter#async#execute(cmd) function! gitgutter#async#execute(cmd) abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
if has('nvim') if has('nvim')
@@ -40,7 +40,7 @@ function! gitgutter#async#execute(cmd)
endfunction endfunction
function! gitgutter#async#handle_diff_job_nvim(job_id, data, event) function! gitgutter#async#handle_diff_job_nvim(job_id, data, event) abort
call gitgutter#debug#log('job_id: '.a:job_id.', event: '.a:event.', buffer: '.self.buffer) call gitgutter#debug#log('job_id: '.a:job_id.', event: '.a:event.', buffer: '.self.buffer)
let current_buffer = gitgutter#utility#bufnr() let current_buffer = gitgutter#utility#bufnr()
@@ -70,13 +70,13 @@ endfunction
" Channel is in NL mode. " Channel is in NL mode.
function! gitgutter#async#handle_diff_job_vim(channel, line) function! gitgutter#async#handle_diff_job_vim(channel, line) abort
call gitgutter#debug#log('channel: '.a:channel.', line: '.a:line) call gitgutter#debug#log('channel: '.a:channel.', line: '.a:line)
call s:accumulate_job_output(s:channel_id(a:channel), a:line) call s:accumulate_job_output(s:channel_id(a:channel), a:line)
endfunction endfunction
function! gitgutter#async#handle_diff_job_vim_close(channel) function! gitgutter#async#handle_diff_job_vim_close(channel) abort
call gitgutter#debug#log('channel: '.a:channel) call gitgutter#debug#log('channel: '.a:channel)
let channel_id = s:channel_id(a:channel) let channel_id = s:channel_id(a:channel)
@@ -91,7 +91,7 @@ function! gitgutter#async#handle_diff_job_vim_close(channel)
endfunction endfunction
function! s:channel_id(channel) function! s:channel_id(channel) abort
" This seems to be the only way to get info about the channel once closed. " This seems to be the only way to get info about the channel once closed.
return matchstr(a:channel, '\d\+') return matchstr(a:channel, '\d\+')
endfunction endfunction
@@ -122,7 +122,7 @@ endfunction
" vim: " vim:
" id: channel's id " id: channel's id
" arg: buffer number " arg: buffer number
function! s:job_started(id, ...) function! s:job_started(id, ...) abort
if a:0 " vim if a:0 " vim
let s:jobs[a:id] = {'output': [], 'buffer': a:1} let s:jobs[a:id] = {'output': [], 'buffer': a:1}
else " nvim else " nvim
@@ -130,16 +130,16 @@ function! s:job_started(id, ...)
endif endif
endfunction endfunction
function! s:is_job_started(id) function! s:is_job_started(id) abort
return has_key(s:jobs, a:id) return has_key(s:jobs, a:id)
endfunction endfunction
function! s:accumulate_job_output(id, line) function! s:accumulate_job_output(id, line) abort
call add(s:jobs[a:id].output, a:line) call add(s:jobs[a:id].output, a:line)
endfunction endfunction
" Returns a string " Returns a string
function! s:job_output(id) function! s:job_output(id) abort
if has_key(s:jobs, a:id) if has_key(s:jobs, a:id)
return gitgutter#utility#stringify(s:jobs[a:id].output) return gitgutter#utility#stringify(s:jobs[a:id].output)
else else
@@ -147,11 +147,11 @@ function! s:job_output(id)
endif endif
endfunction endfunction
function! s:job_buffer(id) function! s:job_buffer(id) abort
return s:jobs[a:id].buffer return s:jobs[a:id].buffer
endfunction endfunction
function! s:job_finished(id) function! s:job_finished(id) abort
if has_key(s:jobs, a:id) if has_key(s:jobs, a:id)
unlet s:jobs[a:id] unlet s:jobs[a:id]
endif endif

View File

@@ -77,7 +77,7 @@ function! gitgutter#debug#output(text)
endfunction endfunction
" assumes optional args are calling function's optional args " assumes optional args are calling function's optional args
function! gitgutter#debug#log(message, ...) function! gitgutter#debug#log(message, ...) abort
if g:gitgutter_log if g:gitgutter_log
if s:new_log_session && gitgutter#async#available() if s:new_log_session && gitgutter#async#available()
if exists('*ch_logfile') if exists('*ch_logfile')
@@ -107,7 +107,7 @@ function! gitgutter#debug#log(message, ...)
endif endif
endfunction endfunction
function! s:format_for_log(data) function! s:format_for_log(data) abort
if type(a:data) == 1 if type(a:data) == 1
return join(split(a:data,'\n'),"\n") return join(split(a:data,'\n'),"\n")
elseif type(a:data) == 3 elseif type(a:data) == 3

View File

@@ -52,7 +52,7 @@ let s:temp_buffer = tempname()
" After running the diff we pass it through grep where available to reduce " After running the diff we pass it through grep where available to reduce
" subsequent processing by the plugin. If grep is not available the plugin " subsequent processing by the plugin. If grep is not available the plugin
" does the filtering instead. " does the filtering instead.
function! gitgutter#diff#run_diff(realtime, preserve_full_diff) function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort
" Wrap compound commands in parentheses to make Windows happy. " Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses; fish doesn't want them. " bash doesn't mind the parentheses; fish doesn't want them.
let cmd = s:fish ? '' : '(' let cmd = s:fish ? '' : '('
@@ -141,7 +141,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff)
endif endif
endfunction endfunction
function! gitgutter#diff#parse_diff(diff) function! gitgutter#diff#parse_diff(diff) abort
let hunks = [] let hunks = []
for line in split(a:diff, '\n') for line in split(a:diff, '\n')
let hunk_info = gitgutter#diff#parse_hunk(line) let hunk_info = gitgutter#diff#parse_hunk(line)
@@ -152,7 +152,7 @@ function! gitgutter#diff#parse_diff(diff)
return hunks return hunks
endfunction endfunction
function! gitgutter#diff#parse_hunk(line) function! gitgutter#diff#parse_hunk(line) abort
let matches = matchlist(a:line, s:hunk_re) let matches = matchlist(a:line, s:hunk_re)
if len(matches) > 0 if len(matches) > 0
let from_line = str2nr(matches[1]) let from_line = str2nr(matches[1])
@@ -165,7 +165,7 @@ function! gitgutter#diff#parse_hunk(line)
end end
endfunction endfunction
function! gitgutter#diff#process_hunks(hunks) function! gitgutter#diff#process_hunks(hunks) abort
call gitgutter#hunk#reset() call gitgutter#hunk#reset()
let modified_lines = [] let modified_lines = []
for hunk in a:hunks for hunk in a:hunks
@@ -175,7 +175,7 @@ function! gitgutter#diff#process_hunks(hunks)
endfunction endfunction
" Returns [ [<line_number (number)>, <name (string)>], ...] " Returns [ [<line_number (number)>, <name (string)>], ...]
function! gitgutter#diff#process_hunk(hunk) function! gitgutter#diff#process_hunk(hunk) abort
let modifications = [] let modifications = []
let from_line = a:hunk[0] let from_line = a:hunk[0]
let from_count = a:hunk[1] let from_count = a:hunk[1]
@@ -208,27 +208,27 @@ function! gitgutter#diff#process_hunk(hunk)
return modifications return modifications
endfunction endfunction
function! gitgutter#diff#is_added(from_count, to_count) function! gitgutter#diff#is_added(from_count, to_count) abort
return a:from_count == 0 && a:to_count > 0 return a:from_count == 0 && a:to_count > 0
endfunction endfunction
function! gitgutter#diff#is_removed(from_count, to_count) function! gitgutter#diff#is_removed(from_count, to_count) abort
return a:from_count > 0 && a:to_count == 0 return a:from_count > 0 && a:to_count == 0
endfunction endfunction
function! gitgutter#diff#is_modified(from_count, to_count) function! gitgutter#diff#is_modified(from_count, to_count) abort
return a:from_count > 0 && a:to_count > 0 && a:from_count == a:to_count return a:from_count > 0 && a:to_count > 0 && a:from_count == a:to_count
endfunction endfunction
function! gitgutter#diff#is_modified_and_added(from_count, to_count) function! gitgutter#diff#is_modified_and_added(from_count, to_count) abort
return a:from_count > 0 && a:to_count > 0 && a:from_count < a:to_count return a:from_count > 0 && a:to_count > 0 && a:from_count < a:to_count
endfunction endfunction
function! gitgutter#diff#is_modified_and_removed(from_count, to_count) function! gitgutter#diff#is_modified_and_removed(from_count, to_count) abort
return a:from_count > 0 && a:to_count > 0 && a:from_count > a:to_count return a:from_count > 0 && a:to_count > 0 && a:from_count > a:to_count
endfunction endfunction
function! gitgutter#diff#process_added(modifications, from_count, to_count, to_line) function! gitgutter#diff#process_added(modifications, from_count, to_count, to_line) abort
let offset = 0 let offset = 0
while offset < a:to_count while offset < a:to_count
let line_number = a:to_line + offset let line_number = a:to_line + offset
@@ -237,7 +237,7 @@ function! gitgutter#diff#process_added(modifications, from_count, to_count, to_l
endwhile endwhile
endfunction endfunction
function! gitgutter#diff#process_removed(modifications, from_count, to_count, to_line) function! gitgutter#diff#process_removed(modifications, from_count, to_count, to_line) abort
if a:to_line == 0 if a:to_line == 0
call add(a:modifications, [1, 'removed_first_line']) call add(a:modifications, [1, 'removed_first_line'])
else else
@@ -245,7 +245,7 @@ function! gitgutter#diff#process_removed(modifications, from_count, to_count, to
endif endif
endfunction endfunction
function! gitgutter#diff#process_modified(modifications, from_count, to_count, to_line) function! gitgutter#diff#process_modified(modifications, from_count, to_count, to_line) abort
let offset = 0 let offset = 0
while offset < a:to_count while offset < a:to_count
let line_number = a:to_line + offset let line_number = a:to_line + offset
@@ -254,7 +254,7 @@ function! gitgutter#diff#process_modified(modifications, from_count, to_count, t
endwhile endwhile
endfunction endfunction
function! gitgutter#diff#process_modified_and_added(modifications, from_count, to_count, to_line) function! gitgutter#diff#process_modified_and_added(modifications, from_count, to_count, to_line) abort
let offset = 0 let offset = 0
while offset < a:from_count while offset < a:from_count
let line_number = a:to_line + offset let line_number = a:to_line + offset
@@ -268,7 +268,7 @@ function! gitgutter#diff#process_modified_and_added(modifications, from_count, t
endwhile endwhile
endfunction endfunction
function! gitgutter#diff#process_modified_and_removed(modifications, from_count, to_count, to_line) function! gitgutter#diff#process_modified_and_removed(modifications, from_count, to_count, to_line) abort
let offset = 0 let offset = 0
while offset < a:to_count while offset < a:to_count
let line_number = a:to_line + offset let line_number = a:to_line + offset
@@ -282,7 +282,7 @@ endfunction
" "
" diff - the full diff for the buffer " diff - the full diff for the buffer
" type - stage | undo | preview " type - stage | undo | preview
function! gitgutter#diff#generate_diff_for_hunk(diff, type) function! gitgutter#diff#generate_diff_for_hunk(diff, type) abort
let diff_for_hunk = gitgutter#diff#discard_hunks(a:diff, a:type == 'stage' || a:type == 'undo') let diff_for_hunk = gitgutter#diff#discard_hunks(a:diff, a:type == 'stage' || a:type == 'undo')
if a:type == 'stage' || a:type == 'undo' if a:type == 'stage' || a:type == 'undo'
@@ -296,7 +296,7 @@ endfunction
" "
" diff - the diff to process " diff - the diff to process
" keep_header - truthy to keep the diff header and hunk summary, falsy to discard it " keep_header - truthy to keep the diff header and hunk summary, falsy to discard it
function! gitgutter#diff#discard_hunks(diff, keep_header) function! gitgutter#diff#discard_hunks(diff, keep_header) abort
let modified_diff = [] let modified_diff = []
let keep_line = a:keep_header let keep_line = a:keep_header
for line in split(a:diff, '\n') for line in split(a:diff, '\n')
@@ -323,7 +323,7 @@ endfunction
" staging - truthy if the hunk is to be staged, falsy if it is to be undone " staging - truthy if the hunk is to be staged, falsy if it is to be undone
" "
" TODO: push this down to #discard_hunks? " TODO: push this down to #discard_hunks?
function! gitgutter#diff#adjust_hunk_summary(diff_for_hunk, staging) function! gitgutter#diff#adjust_hunk_summary(diff_for_hunk, staging) abort
let line_adjustment = gitgutter#hunk#line_adjustment_for_current_hunk() let line_adjustment = gitgutter#hunk#line_adjustment_for_current_hunk()
let adj_diff = [] let adj_diff = []
for line in split(a:diff_for_hunk, '\n') for line in split(a:diff_for_hunk, '\n')

View File

@@ -1,4 +1,4 @@
function! gitgutter#highlight#define_sign_column_highlight() function! gitgutter#highlight#define_sign_column_highlight() abort
if g:gitgutter_override_sign_column_highlight if g:gitgutter_override_sign_column_highlight
highlight! link SignColumn LineNr highlight! link SignColumn LineNr
else else
@@ -6,7 +6,7 @@ function! gitgutter#highlight#define_sign_column_highlight()
endif endif
endfunction endfunction
function! gitgutter#highlight#define_highlights() function! gitgutter#highlight#define_highlights() abort
let [guibg, ctermbg] = gitgutter#highlight#get_background_colors('SignColumn') let [guibg, ctermbg] = gitgutter#highlight#get_background_colors('SignColumn')
" Highlights used by the signs. " Highlights used by the signs.
@@ -34,7 +34,7 @@ function! gitgutter#highlight#define_highlights()
highlight default link GitGutterChangeDeleteLine GitGutterChangeLine highlight default link GitGutterChangeDeleteLine GitGutterChangeLine
endfunction endfunction
function! gitgutter#highlight#define_signs() function! gitgutter#highlight#define_signs() abort
sign define GitGutterLineAdded sign define GitGutterLineAdded
sign define GitGutterLineModified sign define GitGutterLineModified
sign define GitGutterLineRemoved sign define GitGutterLineRemoved
@@ -47,7 +47,7 @@ function! gitgutter#highlight#define_signs()
call gitgutter#highlight#define_sign_line_highlights() call gitgutter#highlight#define_sign_line_highlights()
endfunction endfunction
function! gitgutter#highlight#define_sign_text() function! gitgutter#highlight#define_sign_text() abort
execute "sign define GitGutterLineAdded text=" . g:gitgutter_sign_added execute "sign define GitGutterLineAdded text=" . g:gitgutter_sign_added
execute "sign define GitGutterLineModified text=" . g:gitgutter_sign_modified execute "sign define GitGutterLineModified text=" . g:gitgutter_sign_modified
execute "sign define GitGutterLineRemoved text=" . g:gitgutter_sign_removed execute "sign define GitGutterLineRemoved text=" . g:gitgutter_sign_removed
@@ -55,7 +55,7 @@ function! gitgutter#highlight#define_sign_text()
execute "sign define GitGutterLineModifiedRemoved text=" . g:gitgutter_sign_modified_removed execute "sign define GitGutterLineModifiedRemoved text=" . g:gitgutter_sign_modified_removed
endfunction endfunction
function! gitgutter#highlight#define_sign_text_highlights() function! gitgutter#highlight#define_sign_text_highlights() abort
" Once a sign's text attribute has been defined, it cannot be undefined or " Once a sign's text attribute has been defined, it cannot be undefined or
" set to an empty value. So to make signs' text disappear (when toggling " set to an empty value. So to make signs' text disappear (when toggling
" off or disabling) we make them invisible by setting their foreground colours " off or disabling) we make them invisible by setting their foreground colours
@@ -75,7 +75,7 @@ function! gitgutter#highlight#define_sign_text_highlights()
endif endif
endfunction endfunction
function! gitgutter#highlight#define_sign_line_highlights() function! gitgutter#highlight#define_sign_line_highlights() abort
if g:gitgutter_highlight_lines if g:gitgutter_highlight_lines
sign define GitGutterLineAdded linehl=GitGutterAddLine sign define GitGutterLineAdded linehl=GitGutterAddLine
sign define GitGutterLineModified linehl=GitGutterChangeLine sign define GitGutterLineModified linehl=GitGutterChangeLine
@@ -91,7 +91,7 @@ function! gitgutter#highlight#define_sign_line_highlights()
endif endif
endfunction endfunction
function! gitgutter#highlight#get_background_colors(group) function! gitgutter#highlight#get_background_colors(group) abort
redir => highlight redir => highlight
silent execute 'silent highlight ' . a:group silent execute 'silent highlight ' . a:group
redir END redir END
@@ -106,7 +106,7 @@ function! gitgutter#highlight#get_background_colors(group)
return [guibg, ctermbg] return [guibg, ctermbg]
endfunction endfunction
function! gitgutter#highlight#match_highlight(highlight, pattern) function! gitgutter#highlight#match_highlight(highlight, pattern) abort
let matches = matchlist(a:highlight, a:pattern) let matches = matchlist(a:highlight, a:pattern)
if len(matches) == 0 if len(matches) == 0
return 'NONE' return 'NONE'

View File

@@ -2,35 +2,35 @@
let s:summary = [0, 0, 0] let s:summary = [0, 0, 0]
let s:hunks = [] let s:hunks = []
function! gitgutter#hunk#set_hunks(hunks) function! gitgutter#hunk#set_hunks(hunks) abort
let s:hunks = a:hunks let s:hunks = a:hunks
endfunction endfunction
function! gitgutter#hunk#hunks() function! gitgutter#hunk#hunks() abort
return s:hunks return s:hunks
endfunction endfunction
function! gitgutter#hunk#summary() function! gitgutter#hunk#summary() abort
return s:summary return s:summary
endfunction endfunction
function! gitgutter#hunk#reset() function! gitgutter#hunk#reset() abort
let s:summary = [0, 0, 0] let s:summary = [0, 0, 0]
endfunction endfunction
function! gitgutter#hunk#increment_lines_added(count) function! gitgutter#hunk#increment_lines_added(count) abort
let s:summary[0] += a:count let s:summary[0] += a:count
endfunction endfunction
function! gitgutter#hunk#increment_lines_modified(count) function! gitgutter#hunk#increment_lines_modified(count) abort
let s:summary[1] += a:count let s:summary[1] += a:count
endfunction endfunction
function! gitgutter#hunk#increment_lines_removed(count) function! gitgutter#hunk#increment_lines_removed(count) abort
let s:summary[2] += a:count let s:summary[2] += a:count
endfunction endfunction
function! gitgutter#hunk#next_hunk(count) function! gitgutter#hunk#next_hunk(count) abort
if gitgutter#utility#is_active() if gitgutter#utility#is_active()
let current_line = line('.') let current_line = line('.')
let hunk_count = 0 let hunk_count = 0
@@ -47,7 +47,7 @@ function! gitgutter#hunk#next_hunk(count)
endif endif
endfunction endfunction
function! gitgutter#hunk#prev_hunk(count) function! gitgutter#hunk#prev_hunk(count) abort
if gitgutter#utility#is_active() if gitgutter#utility#is_active()
let current_line = line('.') let current_line = line('.')
let hunk_count = 0 let hunk_count = 0
@@ -67,7 +67,7 @@ endfunction
" Returns the hunk the cursor is currently in or an empty list if the cursor " Returns the hunk the cursor is currently in or an empty list if the cursor
" isn't in a hunk. " isn't in a hunk.
function! gitgutter#hunk#current_hunk() function! gitgutter#hunk#current_hunk() abort
let current_hunk = [] let current_hunk = []
for hunk in s:hunks for hunk in s:hunks
@@ -80,7 +80,7 @@ function! gitgutter#hunk#current_hunk()
return current_hunk return current_hunk
endfunction endfunction
function! gitgutter#hunk#cursor_in_hunk(hunk) function! gitgutter#hunk#cursor_in_hunk(hunk) abort
let current_line = line('.') let current_line = line('.')
if current_line == 1 && a:hunk[2] == 0 if current_line == 1 && a:hunk[2] == 0
@@ -96,7 +96,7 @@ endfunction
" Returns the number of lines the current hunk is offset from where it would " Returns the number of lines the current hunk is offset from where it would
" be if any changes above it in the file didn't exist. " be if any changes above it in the file didn't exist.
function! gitgutter#hunk#line_adjustment_for_current_hunk() function! gitgutter#hunk#line_adjustment_for_current_hunk() abort
let adj = 0 let adj = 0
for hunk in s:hunks for hunk in s:hunks
if gitgutter#hunk#cursor_in_hunk(hunk) if gitgutter#hunk#cursor_in_hunk(hunk)
@@ -108,7 +108,7 @@ function! gitgutter#hunk#line_adjustment_for_current_hunk()
return adj return adj
endfunction endfunction
function! gitgutter#hunk#text_object(inner) function! gitgutter#hunk#text_object(inner) abort
let hunk = gitgutter#hunk#current_hunk() let hunk = gitgutter#hunk#current_hunk()
if empty(hunk) if empty(hunk)

View File

@@ -11,7 +11,7 @@ let s:supports_star = v:version > 703 || (v:version == 703 && has("patch596"))
" Removes gitgutter's signs (excluding dummy sign) from the buffer being processed. " Removes gitgutter's signs (excluding dummy sign) from the buffer being processed.
function! gitgutter#sign#clear_signs() function! gitgutter#sign#clear_signs() abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
call gitgutter#sign#find_current_signs() call gitgutter#sign#find_current_signs()
@@ -25,7 +25,7 @@ endfunction
" "
" modified_lines: list of [<line_number (number)>, <name (string)>] " modified_lines: list of [<line_number (number)>, <name (string)>]
" where name = 'added|removed|modified|modified_removed' " where name = 'added|removed|modified|modified_removed'
function! gitgutter#sign#update_signs(modified_lines) function! gitgutter#sign#update_signs(modified_lines) abort
call gitgutter#sign#find_current_signs() call gitgutter#sign#find_current_signs()
let new_gitgutter_signs_line_numbers = map(copy(a:modified_lines), 'v:val[0]') let new_gitgutter_signs_line_numbers = map(copy(a:modified_lines), 'v:val[0]')
@@ -45,7 +45,7 @@ function! gitgutter#sign#update_signs(modified_lines)
endfunction endfunction
function! gitgutter#sign#add_dummy_sign() function! gitgutter#sign#add_dummy_sign() abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
if !getbufvar(bufnr, 'gitgutter_dummy_sign') if !getbufvar(bufnr, 'gitgutter_dummy_sign')
execute "sign place" s:dummy_sign_id "line=" . 9999 "name=GitGutterDummy buffer=" . bufnr execute "sign place" s:dummy_sign_id "line=" . 9999 "name=GitGutterDummy buffer=" . bufnr
@@ -53,7 +53,7 @@ function! gitgutter#sign#add_dummy_sign()
endif endif
endfunction endfunction
function! gitgutter#sign#remove_dummy_sign(force) function! gitgutter#sign#remove_dummy_sign(force) abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
if getbufvar(bufnr, 'gitgutter_dummy_sign') && (a:force || !g:gitgutter_sign_column_always) if getbufvar(bufnr, 'gitgutter_dummy_sign') && (a:force || !g:gitgutter_sign_column_always)
execute "sign unplace" s:dummy_sign_id "buffer=" . bufnr execute "sign unplace" s:dummy_sign_id "buffer=" . bufnr
@@ -67,7 +67,7 @@ endfunction
" "
function! gitgutter#sign#find_current_signs() function! gitgutter#sign#find_current_signs() abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
let gitgutter_signs = {} " <line_number (string)>: {'id': <id (number)>, 'name': <name (string)>} let gitgutter_signs = {} " <line_number (string)>: {'id': <id (number)>, 'name': <name (string)>}
let other_signs = [] " [<line_number (number),...] let other_signs = [] " [<line_number (number),...]
@@ -109,7 +109,7 @@ endfunction
" Returns a list of [<id (number)>, ...] " Returns a list of [<id (number)>, ...]
" Sets `s:remove_all_old_signs` as a side-effect. " Sets `s:remove_all_old_signs` as a side-effect.
function! gitgutter#sign#obsolete_gitgutter_signs_to_remove(new_gitgutter_signs_line_numbers) function! gitgutter#sign#obsolete_gitgutter_signs_to_remove(new_gitgutter_signs_line_numbers) abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
let signs_to_remove = [] " list of [<id (number)>, ...] let signs_to_remove = [] " list of [<id (number)>, ...]
let remove_all_signs = 1 let remove_all_signs = 1
@@ -126,7 +126,7 @@ function! gitgutter#sign#obsolete_gitgutter_signs_to_remove(new_gitgutter_signs_
endfunction endfunction
function! gitgutter#sign#remove_signs(sign_ids, all_signs) function! gitgutter#sign#remove_signs(sign_ids, all_signs) abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
if a:all_signs && s:supports_star && empty(getbufvar(bufnr, 'gitgutter_other_signs')) if a:all_signs && s:supports_star && empty(getbufvar(bufnr, 'gitgutter_other_signs'))
let dummy_sign_present = getbufvar(bufnr, 'gitgutter_dummy_sign') let dummy_sign_present = getbufvar(bufnr, 'gitgutter_dummy_sign')
@@ -142,7 +142,7 @@ function! gitgutter#sign#remove_signs(sign_ids, all_signs)
endfunction endfunction
function! gitgutter#sign#upsert_new_gitgutter_signs(modified_lines) function! gitgutter#sign#upsert_new_gitgutter_signs(modified_lines) abort
let bufnr = gitgutter#utility#bufnr() let bufnr = gitgutter#utility#bufnr()
let other_signs = getbufvar(bufnr, 'gitgutter_other_signs') let other_signs = getbufvar(bufnr, 'gitgutter_other_signs')
let old_gitgutter_signs = getbufvar(bufnr, 'gitgutter_gitgutter_signs') let old_gitgutter_signs = getbufvar(bufnr, 'gitgutter_gitgutter_signs')
@@ -166,7 +166,7 @@ function! gitgutter#sign#upsert_new_gitgutter_signs(modified_lines)
endfunction endfunction
function! gitgutter#sign#next_sign_id() function! gitgutter#sign#next_sign_id() abort
let next_id = s:next_sign_id let next_id = s:next_sign_id
let s:next_sign_id += 1 let s:next_sign_id += 1
return next_id return next_id

View File

@@ -3,14 +3,14 @@ let s:using_xolox_shell = -1
let s:exit_code = 0 let s:exit_code = 0
let s:fish = &shell =~# 'fish' let s:fish = &shell =~# 'fish'
function! gitgutter#utility#warn(message) function! gitgutter#utility#warn(message) abort
echohl WarningMsg echohl WarningMsg
echo 'vim-gitgutter: ' . a:message echo 'vim-gitgutter: ' . a:message
echohl None echohl None
let v:warningmsg = a:message let v:warningmsg = a:message
endfunction endfunction
function! gitgutter#utility#warn_once(message, key) function! gitgutter#utility#warn_once(message, key) abort
if empty(getbufvar(s:bufnr, a:key)) if empty(getbufvar(s:bufnr, a:key))
call setbufvar(s:bufnr, a:key, '1') call setbufvar(s:bufnr, a:key, '1')
echohl WarningMsg echohl WarningMsg
@@ -22,7 +22,7 @@ endfunction
" Returns truthy when the buffer's file should be processed; and falsey when it shouldn't. " Returns truthy when the buffer's file should be processed; and falsey when it shouldn't.
" This function does not and should not make any system calls. " This function does not and should not make any system calls.
function! gitgutter#utility#is_active() function! gitgutter#utility#is_active() abort
return g:gitgutter_enabled && return g:gitgutter_enabled &&
\ !pumvisible() && \ !pumvisible() &&
\ gitgutter#utility#is_file_buffer() && \ gitgutter#utility#is_file_buffer() &&
@@ -30,11 +30,11 @@ function! gitgutter#utility#is_active()
\ gitgutter#utility#not_git_dir() \ gitgutter#utility#not_git_dir()
endfunction endfunction
function! gitgutter#utility#not_git_dir() function! gitgutter#utility#not_git_dir() abort
return gitgutter#utility#full_path_to_directory_of_file() !~ '[/\\]\.git\($\|[/\\]\)' return gitgutter#utility#full_path_to_directory_of_file() !~ '[/\\]\.git\($\|[/\\]\)'
endfunction endfunction
function! gitgutter#utility#is_file_buffer() function! gitgutter#utility#is_file_buffer() abort
return empty(getbufvar(s:bufnr, '&buftype')) return empty(getbufvar(s:bufnr, '&buftype'))
endfunction endfunction
@@ -45,7 +45,7 @@ endfunction
" "
" See: " See:
" https://github.com/tpope/vim-fugitive/blob/8f0b8edfbd246c0026b7a2388e1d883d579ac7f6/plugin/fugitive.vim#L29-L37 " https://github.com/tpope/vim-fugitive/blob/8f0b8edfbd246c0026b7a2388e1d883d579ac7f6/plugin/fugitive.vim#L29-L37
function! gitgutter#utility#shellescape(arg) function! gitgutter#utility#shellescape(arg) abort
if a:arg =~ '^[A-Za-z0-9_/.-]\+$' if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
return a:arg return a:arg
elseif &shell =~# 'cmd' || gitgutter#utility#using_xolox_shell() elseif &shell =~# 'cmd' || gitgutter#utility#using_xolox_shell()
@@ -55,7 +55,7 @@ function! gitgutter#utility#shellescape(arg)
endif endif
endfunction endfunction
function! gitgutter#utility#set_buffer(bufnr) function! gitgutter#utility#set_buffer(bufnr) abort
let s:bufnr = a:bufnr let s:bufnr = a:bufnr
let s:file = resolve(bufname(a:bufnr)) let s:file = resolve(bufname(a:bufnr))
endfunction endfunction
@@ -68,43 +68,43 @@ function! gitgutter#utility#file()
return s:file return s:file
endfunction endfunction
function! gitgutter#utility#filename() function! gitgutter#utility#filename() abort
return fnamemodify(s:file, ':t') return fnamemodify(s:file, ':t')
endfunction endfunction
function! gitgutter#utility#extension() function! gitgutter#utility#extension() abort
return fnamemodify(s:file, ':e') return fnamemodify(s:file, ':e')
endfunction endfunction
function! gitgutter#utility#full_path_to_directory_of_file() function! gitgutter#utility#full_path_to_directory_of_file() abort
return fnamemodify(s:file, ':p:h') return fnamemodify(s:file, ':p:h')
endfunction endfunction
function! gitgutter#utility#directory_of_file() function! gitgutter#utility#directory_of_file() abort
return fnamemodify(s:file, ':h') return fnamemodify(s:file, ':h')
endfunction endfunction
function! gitgutter#utility#exists_file() function! gitgutter#utility#exists_file() abort
return filereadable(s:file) return filereadable(s:file)
endfunction endfunction
function! gitgutter#utility#has_unsaved_changes() function! gitgutter#utility#has_unsaved_changes() abort
return getbufvar(s:bufnr, "&mod") return getbufvar(s:bufnr, "&mod")
endfunction endfunction
function! gitgutter#utility#has_fresh_changes() function! gitgutter#utility#has_fresh_changes() abort
return getbufvar(s:bufnr, 'changedtick') != getbufvar(s:bufnr, 'gitgutter_last_tick') return getbufvar(s:bufnr, 'changedtick') != getbufvar(s:bufnr, 'gitgutter_last_tick')
endfunction endfunction
function! gitgutter#utility#save_last_seen_change() function! gitgutter#utility#save_last_seen_change() abort
call setbufvar(s:bufnr, 'gitgutter_last_tick', getbufvar(s:bufnr, 'changedtick')) call setbufvar(s:bufnr, 'gitgutter_last_tick', getbufvar(s:bufnr, 'changedtick'))
endfunction endfunction
function! gitgutter#utility#shell_error() function! gitgutter#utility#shell_error() abort
return gitgutter#utility#using_xolox_shell() ? s:exit_code : v:shell_error return gitgutter#utility#using_xolox_shell() ? s:exit_code : v:shell_error
endfunction endfunction
function! gitgutter#utility#using_xolox_shell() function! gitgutter#utility#using_xolox_shell() abort
if s:using_xolox_shell == -1 if s:using_xolox_shell == -1
if !g:gitgutter_avoid_cmd_prompt_on_windows if !g:gitgutter_avoid_cmd_prompt_on_windows
let s:using_xolox_shell = 0 let s:using_xolox_shell = 0
@@ -119,7 +119,7 @@ function! gitgutter#utility#using_xolox_shell()
return s:using_xolox_shell return s:using_xolox_shell
endfunction endfunction
function! gitgutter#utility#system(cmd, ...) function! gitgutter#utility#system(cmd, ...) abort
call gitgutter#debug#log(a:cmd, a:000) call gitgutter#debug#log(a:cmd, a:000)
if gitgutter#utility#using_xolox_shell() if gitgutter#utility#using_xolox_shell()
@@ -136,7 +136,7 @@ function! gitgutter#utility#system(cmd, ...)
return output return output
endfunction endfunction
function! gitgutter#utility#file_relative_to_repo_root() function! gitgutter#utility#file_relative_to_repo_root() abort
let file_path_relative_to_repo_root = getbufvar(s:bufnr, 'gitgutter_repo_relative_path') let file_path_relative_to_repo_root = getbufvar(s:bufnr, 'gitgutter_repo_relative_path')
if empty(file_path_relative_to_repo_root) if empty(file_path_relative_to_repo_root)
let dir_path_relative_to_repo_root = gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git rev-parse --show-prefix')) let dir_path_relative_to_repo_root = gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file('git rev-parse --show-prefix'))
@@ -147,11 +147,11 @@ function! gitgutter#utility#file_relative_to_repo_root()
return file_path_relative_to_repo_root return file_path_relative_to_repo_root
endfunction endfunction
function! gitgutter#utility#command_in_directory_of_file(cmd) function! gitgutter#utility#command_in_directory_of_file(cmd) abort
return 'cd '.gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()) . (s:fish ? '; and ' : ' && ') . a:cmd return 'cd '.gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()) . (s:fish ? '; and ' : ' && ') . a:cmd
endfunction endfunction
function! gitgutter#utility#highlight_name_for_change(text) function! gitgutter#utility#highlight_name_for_change(text) abort
if a:text ==# 'added' if a:text ==# 'added'
return 'GitGutterLineAdded' return 'GitGutterLineAdded'
elseif a:text ==# 'removed' elseif a:text ==# 'removed'
@@ -165,20 +165,20 @@ function! gitgutter#utility#highlight_name_for_change(text)
endif endif
endfunction endfunction
function! gitgutter#utility#strip_trailing_new_line(line) function! gitgutter#utility#strip_trailing_new_line(line) abort
return substitute(a:line, '\n$', '', '') return substitute(a:line, '\n$', '', '')
endfunction endfunction
function! gitgutter#utility#git_version() function! gitgutter#utility#git_version() abort
return matchstr(system('git --version'), '[0-9.]\+') return matchstr(system('git --version'), '[0-9.]\+')
endfunction endfunction
" True for git v1.7.2+. " True for git v1.7.2+.
function! gitgutter#utility#git_supports_command_line_config_override() function! gitgutter#utility#git_supports_command_line_config_override() abort
let [major, minor, patch; _] = split(gitgutter#utility#git_version(), '\.') let [major, minor, patch; _] = split(gitgutter#utility#git_version(), '\.')
return major > 1 || (major == 1 && minor > 7) || (minor == 7 && patch > 1) return major > 1 || (major == 1 && minor > 7) || (minor == 7 && patch > 1)
endfunction endfunction
function! gitgutter#utility#stringify(list) function! gitgutter#utility#stringify(list) abort
return join(a:list, "\n")."\n" return join(a:list, "\n")."\n"
endfunction endfunction

View File

@@ -17,7 +17,7 @@ if !exists("*gettabvar")
let g:gitgutter_eager = 0 let g:gitgutter_eager = 0
endif endif
function! s:set(var, default) function! s:set(var, default) abort
if !exists(a:var) if !exists(a:var)
if type(a:default) if type(a:default)
execute 'let' a:var '=' string(a:default) execute 'let' a:var '=' string(a:default)