From cae4f72aa1290c353aa8d0898cac0781ef2ee538 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Fri, 13 May 2016 14:14:41 +0100 Subject: [PATCH] Abort functions at first error. --- autoload/gitgutter.vim | 30 +++++++++---------- autoload/gitgutter/async.vim | 22 +++++++------- autoload/gitgutter/debug.vim | 4 +-- autoload/gitgutter/diff.vim | 36 +++++++++++------------ autoload/gitgutter/highlight.vim | 16 +++++----- autoload/gitgutter/hunk.vim | 26 ++++++++--------- autoload/gitgutter/sign.vim | 18 ++++++------ autoload/gitgutter/utility.vim | 50 ++++++++++++++++---------------- plugin/gitgutter.vim | 2 +- 9 files changed, 102 insertions(+), 102 deletions(-) diff --git a/autoload/gitgutter.vim b/autoload/gitgutter.vim index ced323a..d47ef7c 100644 --- a/autoload/gitgutter.vim +++ b/autoload/gitgutter.vim @@ -2,7 +2,7 @@ let s:nomodeline = (v:version > 703 || (v:version == 703 && has('patch442'))) ? " Primary functions {{{ -function! gitgutter#all() +function! gitgutter#all() abort for buffer_id in tabpagebuflist() let file = expand('#' . buffer_id . ':p') if !empty(file) @@ -13,7 +13,7 @@ endfunction " bufnr: (integer) the buffer to process. " 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) if gitgutter#utility#is_active() if g:gitgutter_sign_column_always @@ -37,7 +37,7 @@ function! gitgutter#process_buffer(bufnr, realtime) endfunction -function! gitgutter#handle_diff(diff) +function! gitgutter#handle_diff(diff) abort call gitgutter#debug#log(a:diff) call setbufvar(gitgutter#utility#bufnr(), 'gitgutter_tracked', 1) @@ -58,7 +58,7 @@ function! gitgutter#handle_diff(diff) call gitgutter#utility#save_last_seen_change() endfunction -function! gitgutter#disable() +function! gitgutter#disable() abort " get list of all buffers (across all tabs) let buflist = [] for i in range(tabpagenr('$')) @@ -78,12 +78,12 @@ function! gitgutter#disable() let g:gitgutter_enabled = 0 endfunction -function! gitgutter#enable() +function! gitgutter#enable() abort let g:gitgutter_enabled = 1 call gitgutter#all() endfunction -function! gitgutter#toggle() +function! gitgutter#toggle() abort if g:gitgutter_enabled call gitgutter#disable() else @@ -95,7 +95,7 @@ endfunction " Line highlights {{{ -function! gitgutter#line_highlights_disable() +function! gitgutter#line_highlights_disable() abort let g:gitgutter_highlight_lines = 0 call gitgutter#highlight#define_sign_line_highlights() @@ -107,7 +107,7 @@ function! gitgutter#line_highlights_disable() redraw! endfunction -function! gitgutter#line_highlights_enable() +function! gitgutter#line_highlights_enable() abort let old_highlight_lines = g:gitgutter_highlight_lines let g:gitgutter_highlight_lines = 1 @@ -120,7 +120,7 @@ function! gitgutter#line_highlights_enable() redraw! endfunction -function! gitgutter#line_highlights_toggle() +function! gitgutter#line_highlights_toggle() abort if g:gitgutter_highlight_lines call gitgutter#line_highlights_disable() else @@ -132,7 +132,7 @@ endfunction " Signs {{{ -function! gitgutter#signs_enable() +function! gitgutter#signs_enable() abort let old_signs = g:gitgutter_signs let g:gitgutter_signs = 1 @@ -143,7 +143,7 @@ function! gitgutter#signs_enable() endif endfunction -function! gitgutter#signs_disable() +function! gitgutter#signs_disable() abort let g:gitgutter_signs = 0 call gitgutter#highlight#define_sign_text_highlights() @@ -153,7 +153,7 @@ function! gitgutter#signs_disable() endif endfunction -function! gitgutter#signs_toggle() +function! gitgutter#signs_toggle() abort if g:gitgutter_signs call gitgutter#signs_disable() else @@ -165,7 +165,7 @@ endfunction " Hunks {{{ -function! gitgutter#stage_hunk() +function! gitgutter#stage_hunk() abort if gitgutter#utility#is_active() " Ensure the working copy of the file is up to date. " It doesn't make sense to stage a hunk otherwise. @@ -187,7 +187,7 @@ function! gitgutter#stage_hunk() endif endfunction -function! gitgutter#undo_hunk() +function! gitgutter#undo_hunk() abort if gitgutter#utility#is_active() " Ensure the working copy of the file is up to date. " It doesn't make sense to stage a hunk otherwise. @@ -209,7 +209,7 @@ function! gitgutter#undo_hunk() endif endfunction -function! gitgutter#preview_hunk() +function! gitgutter#preview_hunk() abort if gitgutter#utility#is_active() " Ensure the working copy of the file is up to date. " It doesn't make sense to stage a hunk otherwise. diff --git a/autoload/gitgutter/async.vim b/autoload/gitgutter/async.vim index 1e4f932..443039c 100644 --- a/autoload/gitgutter/async.vim +++ b/autoload/gitgutter/async.vim @@ -5,7 +5,7 @@ function! gitgutter#async#available() return s:available endfunction -function! gitgutter#async#execute(cmd) +function! gitgutter#async#execute(cmd) abort let bufnr = gitgutter#utility#bufnr() if has('nvim') @@ -40,7 +40,7 @@ function! gitgutter#async#execute(cmd) 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) let current_buffer = gitgutter#utility#bufnr() @@ -70,13 +70,13 @@ endfunction " 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 s:accumulate_job_output(s:channel_id(a:channel), a:line) 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) let channel_id = s:channel_id(a:channel) @@ -91,7 +91,7 @@ function! gitgutter#async#handle_diff_job_vim_close(channel) 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. return matchstr(a:channel, '\d\+') endfunction @@ -122,7 +122,7 @@ endfunction " vim: " id: channel's id " arg: buffer number -function! s:job_started(id, ...) +function! s:job_started(id, ...) abort if a:0 " vim let s:jobs[a:id] = {'output': [], 'buffer': a:1} else " nvim @@ -130,16 +130,16 @@ function! s:job_started(id, ...) endif endfunction -function! s:is_job_started(id) +function! s:is_job_started(id) abort return has_key(s:jobs, a:id) 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) endfunction " Returns a string -function! s:job_output(id) +function! s:job_output(id) abort if has_key(s:jobs, a:id) return gitgutter#utility#stringify(s:jobs[a:id].output) else @@ -147,11 +147,11 @@ function! s:job_output(id) endif endfunction -function! s:job_buffer(id) +function! s:job_buffer(id) abort return s:jobs[a:id].buffer endfunction -function! s:job_finished(id) +function! s:job_finished(id) abort if has_key(s:jobs, a:id) unlet s:jobs[a:id] endif diff --git a/autoload/gitgutter/debug.vim b/autoload/gitgutter/debug.vim index a731f0c..ad96a90 100644 --- a/autoload/gitgutter/debug.vim +++ b/autoload/gitgutter/debug.vim @@ -77,7 +77,7 @@ function! gitgutter#debug#output(text) endfunction " 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 s:new_log_session && gitgutter#async#available() if exists('*ch_logfile') @@ -107,7 +107,7 @@ function! gitgutter#debug#log(message, ...) endif endfunction -function! s:format_for_log(data) +function! s:format_for_log(data) abort if type(a:data) == 1 return join(split(a:data,'\n'),"\n") elseif type(a:data) == 3 diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 002f059..894be30 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -52,7 +52,7 @@ let s:temp_buffer = tempname() " 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 " 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. " bash doesn't mind the parentheses; fish doesn't want them. let cmd = s:fish ? '' : '(' @@ -141,7 +141,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff) endif endfunction -function! gitgutter#diff#parse_diff(diff) +function! gitgutter#diff#parse_diff(diff) abort let hunks = [] for line in split(a:diff, '\n') let hunk_info = gitgutter#diff#parse_hunk(line) @@ -152,7 +152,7 @@ function! gitgutter#diff#parse_diff(diff) return hunks endfunction -function! gitgutter#diff#parse_hunk(line) +function! gitgutter#diff#parse_hunk(line) abort let matches = matchlist(a:line, s:hunk_re) if len(matches) > 0 let from_line = str2nr(matches[1]) @@ -165,7 +165,7 @@ function! gitgutter#diff#parse_hunk(line) end endfunction -function! gitgutter#diff#process_hunks(hunks) +function! gitgutter#diff#process_hunks(hunks) abort call gitgutter#hunk#reset() let modified_lines = [] for hunk in a:hunks @@ -175,7 +175,7 @@ function! gitgutter#diff#process_hunks(hunks) endfunction " Returns [ [, ], ...] -function! gitgutter#diff#process_hunk(hunk) +function! gitgutter#diff#process_hunk(hunk) abort let modifications = [] let from_line = a:hunk[0] let from_count = a:hunk[1] @@ -208,27 +208,27 @@ function! gitgutter#diff#process_hunk(hunk) return modifications 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 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 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 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 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 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 while offset < a:to_count let line_number = a:to_line + offset @@ -237,7 +237,7 @@ function! gitgutter#diff#process_added(modifications, from_count, to_count, to_l endwhile 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 call add(a:modifications, [1, 'removed_first_line']) else @@ -245,7 +245,7 @@ function! gitgutter#diff#process_removed(modifications, from_count, to_count, to endif 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 while offset < a:to_count let line_number = a:to_line + offset @@ -254,7 +254,7 @@ function! gitgutter#diff#process_modified(modifications, from_count, to_count, t endwhile 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 while offset < a:from_count let line_number = a:to_line + offset @@ -268,7 +268,7 @@ function! gitgutter#diff#process_modified_and_added(modifications, from_count, t endwhile 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 while offset < a:to_count let line_number = a:to_line + offset @@ -282,7 +282,7 @@ endfunction " " diff - the full diff for the buffer " 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') if a:type == 'stage' || a:type == 'undo' @@ -296,7 +296,7 @@ endfunction " " diff - the diff to process " 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 keep_line = a:keep_header 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 " " 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 adj_diff = [] for line in split(a:diff_for_hunk, '\n') diff --git a/autoload/gitgutter/highlight.vim b/autoload/gitgutter/highlight.vim index 616ac61..e3b774b 100644 --- a/autoload/gitgutter/highlight.vim +++ b/autoload/gitgutter/highlight.vim @@ -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 highlight! link SignColumn LineNr else @@ -6,7 +6,7 @@ function! gitgutter#highlight#define_sign_column_highlight() endif endfunction -function! gitgutter#highlight#define_highlights() +function! gitgutter#highlight#define_highlights() abort let [guibg, ctermbg] = gitgutter#highlight#get_background_colors('SignColumn') " Highlights used by the signs. @@ -34,7 +34,7 @@ function! gitgutter#highlight#define_highlights() highlight default link GitGutterChangeDeleteLine GitGutterChangeLine endfunction -function! gitgutter#highlight#define_signs() +function! gitgutter#highlight#define_signs() abort sign define GitGutterLineAdded sign define GitGutterLineModified sign define GitGutterLineRemoved @@ -47,7 +47,7 @@ function! gitgutter#highlight#define_signs() call gitgutter#highlight#define_sign_line_highlights() 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 GitGutterLineModified text=" . g:gitgutter_sign_modified 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 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 " 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 @@ -75,7 +75,7 @@ function! gitgutter#highlight#define_sign_text_highlights() endif endfunction -function! gitgutter#highlight#define_sign_line_highlights() +function! gitgutter#highlight#define_sign_line_highlights() abort if g:gitgutter_highlight_lines sign define GitGutterLineAdded linehl=GitGutterAddLine sign define GitGutterLineModified linehl=GitGutterChangeLine @@ -91,7 +91,7 @@ function! gitgutter#highlight#define_sign_line_highlights() endif endfunction -function! gitgutter#highlight#get_background_colors(group) +function! gitgutter#highlight#get_background_colors(group) abort redir => highlight silent execute 'silent highlight ' . a:group redir END @@ -106,7 +106,7 @@ function! gitgutter#highlight#get_background_colors(group) return [guibg, ctermbg] endfunction -function! gitgutter#highlight#match_highlight(highlight, pattern) +function! gitgutter#highlight#match_highlight(highlight, pattern) abort let matches = matchlist(a:highlight, a:pattern) if len(matches) == 0 return 'NONE' diff --git a/autoload/gitgutter/hunk.vim b/autoload/gitgutter/hunk.vim index 24a9a78..13afb94 100644 --- a/autoload/gitgutter/hunk.vim +++ b/autoload/gitgutter/hunk.vim @@ -2,35 +2,35 @@ let s:summary = [0, 0, 0] let s:hunks = [] -function! gitgutter#hunk#set_hunks(hunks) +function! gitgutter#hunk#set_hunks(hunks) abort let s:hunks = a:hunks endfunction -function! gitgutter#hunk#hunks() +function! gitgutter#hunk#hunks() abort return s:hunks endfunction -function! gitgutter#hunk#summary() +function! gitgutter#hunk#summary() abort return s:summary endfunction -function! gitgutter#hunk#reset() +function! gitgutter#hunk#reset() abort let s:summary = [0, 0, 0] endfunction -function! gitgutter#hunk#increment_lines_added(count) +function! gitgutter#hunk#increment_lines_added(count) abort let s:summary[0] += a:count endfunction -function! gitgutter#hunk#increment_lines_modified(count) +function! gitgutter#hunk#increment_lines_modified(count) abort let s:summary[1] += a:count endfunction -function! gitgutter#hunk#increment_lines_removed(count) +function! gitgutter#hunk#increment_lines_removed(count) abort let s:summary[2] += a:count endfunction -function! gitgutter#hunk#next_hunk(count) +function! gitgutter#hunk#next_hunk(count) abort if gitgutter#utility#is_active() let current_line = line('.') let hunk_count = 0 @@ -47,7 +47,7 @@ function! gitgutter#hunk#next_hunk(count) endif endfunction -function! gitgutter#hunk#prev_hunk(count) +function! gitgutter#hunk#prev_hunk(count) abort if gitgutter#utility#is_active() let current_line = line('.') let hunk_count = 0 @@ -67,7 +67,7 @@ endfunction " Returns the hunk the cursor is currently in or an empty list if the cursor " isn't in a hunk. -function! gitgutter#hunk#current_hunk() +function! gitgutter#hunk#current_hunk() abort let current_hunk = [] for hunk in s:hunks @@ -80,7 +80,7 @@ function! gitgutter#hunk#current_hunk() return current_hunk endfunction -function! gitgutter#hunk#cursor_in_hunk(hunk) +function! gitgutter#hunk#cursor_in_hunk(hunk) abort let current_line = line('.') 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 " 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 for hunk in s:hunks if gitgutter#hunk#cursor_in_hunk(hunk) @@ -108,7 +108,7 @@ function! gitgutter#hunk#line_adjustment_for_current_hunk() return adj endfunction -function! gitgutter#hunk#text_object(inner) +function! gitgutter#hunk#text_object(inner) abort let hunk = gitgutter#hunk#current_hunk() if empty(hunk) diff --git a/autoload/gitgutter/sign.vim b/autoload/gitgutter/sign.vim index e520c50..6bd5efa 100644 --- a/autoload/gitgutter/sign.vim +++ b/autoload/gitgutter/sign.vim @@ -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. -function! gitgutter#sign#clear_signs() +function! gitgutter#sign#clear_signs() abort let bufnr = gitgutter#utility#bufnr() call gitgutter#sign#find_current_signs() @@ -25,7 +25,7 @@ endfunction " " modified_lines: list of [, ] " 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() 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 -function! gitgutter#sign#add_dummy_sign() +function! gitgutter#sign#add_dummy_sign() abort let bufnr = gitgutter#utility#bufnr() if !getbufvar(bufnr, 'gitgutter_dummy_sign') execute "sign place" s:dummy_sign_id "line=" . 9999 "name=GitGutterDummy buffer=" . bufnr @@ -53,7 +53,7 @@ function! gitgutter#sign#add_dummy_sign() endif endfunction -function! gitgutter#sign#remove_dummy_sign(force) +function! gitgutter#sign#remove_dummy_sign(force) abort let bufnr = gitgutter#utility#bufnr() if getbufvar(bufnr, 'gitgutter_dummy_sign') && (a:force || !g:gitgutter_sign_column_always) 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 gitgutter_signs = {} " : {'id': , 'name': } let other_signs = [] " [, ...] " 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 signs_to_remove = [] " list of [, ...] let remove_all_signs = 1 @@ -126,7 +126,7 @@ function! gitgutter#sign#obsolete_gitgutter_signs_to_remove(new_gitgutter_signs_ 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() if a:all_signs && s:supports_star && empty(getbufvar(bufnr, 'gitgutter_other_signs')) let dummy_sign_present = getbufvar(bufnr, 'gitgutter_dummy_sign') @@ -142,7 +142,7 @@ function! gitgutter#sign#remove_signs(sign_ids, all_signs) 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 other_signs = getbufvar(bufnr, 'gitgutter_other_signs') let old_gitgutter_signs = getbufvar(bufnr, 'gitgutter_gitgutter_signs') @@ -166,7 +166,7 @@ function! gitgutter#sign#upsert_new_gitgutter_signs(modified_lines) endfunction -function! gitgutter#sign#next_sign_id() +function! gitgutter#sign#next_sign_id() abort let next_id = s:next_sign_id let s:next_sign_id += 1 return next_id diff --git a/autoload/gitgutter/utility.vim b/autoload/gitgutter/utility.vim index 32856d5..6e0c886 100644 --- a/autoload/gitgutter/utility.vim +++ b/autoload/gitgutter/utility.vim @@ -3,14 +3,14 @@ let s:using_xolox_shell = -1 let s:exit_code = 0 let s:fish = &shell =~# 'fish' -function! gitgutter#utility#warn(message) +function! gitgutter#utility#warn(message) abort echohl WarningMsg echo 'vim-gitgutter: ' . a:message echohl None let v:warningmsg = a:message endfunction -function! gitgutter#utility#warn_once(message, key) +function! gitgutter#utility#warn_once(message, key) abort if empty(getbufvar(s:bufnr, a:key)) call setbufvar(s:bufnr, a:key, '1') echohl WarningMsg @@ -22,7 +22,7 @@ endfunction " 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. -function! gitgutter#utility#is_active() +function! gitgutter#utility#is_active() abort return g:gitgutter_enabled && \ !pumvisible() && \ gitgutter#utility#is_file_buffer() && @@ -30,11 +30,11 @@ function! gitgutter#utility#is_active() \ gitgutter#utility#not_git_dir() endfunction -function! gitgutter#utility#not_git_dir() +function! gitgutter#utility#not_git_dir() abort return gitgutter#utility#full_path_to_directory_of_file() !~ '[/\\]\.git\($\|[/\\]\)' endfunction -function! gitgutter#utility#is_file_buffer() +function! gitgutter#utility#is_file_buffer() abort return empty(getbufvar(s:bufnr, '&buftype')) endfunction @@ -45,7 +45,7 @@ endfunction " " See: " 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_/.-]\+$' return a:arg elseif &shell =~# 'cmd' || gitgutter#utility#using_xolox_shell() @@ -55,7 +55,7 @@ function! gitgutter#utility#shellescape(arg) endif endfunction -function! gitgutter#utility#set_buffer(bufnr) +function! gitgutter#utility#set_buffer(bufnr) abort let s:bufnr = a:bufnr let s:file = resolve(bufname(a:bufnr)) endfunction @@ -68,43 +68,43 @@ function! gitgutter#utility#file() return s:file endfunction -function! gitgutter#utility#filename() +function! gitgutter#utility#filename() abort return fnamemodify(s:file, ':t') endfunction -function! gitgutter#utility#extension() +function! gitgutter#utility#extension() abort return fnamemodify(s:file, ':e') 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') endfunction -function! gitgutter#utility#directory_of_file() +function! gitgutter#utility#directory_of_file() abort return fnamemodify(s:file, ':h') endfunction -function! gitgutter#utility#exists_file() +function! gitgutter#utility#exists_file() abort return filereadable(s:file) endfunction -function! gitgutter#utility#has_unsaved_changes() +function! gitgutter#utility#has_unsaved_changes() abort return getbufvar(s:bufnr, "&mod") 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') 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')) endfunction -function! gitgutter#utility#shell_error() +function! gitgutter#utility#shell_error() abort return gitgutter#utility#using_xolox_shell() ? s:exit_code : v:shell_error endfunction -function! gitgutter#utility#using_xolox_shell() +function! gitgutter#utility#using_xolox_shell() abort if s:using_xolox_shell == -1 if !g:gitgutter_avoid_cmd_prompt_on_windows let s:using_xolox_shell = 0 @@ -119,7 +119,7 @@ function! gitgutter#utility#using_xolox_shell() return s:using_xolox_shell endfunction -function! gitgutter#utility#system(cmd, ...) +function! gitgutter#utility#system(cmd, ...) abort call gitgutter#debug#log(a:cmd, a:000) if gitgutter#utility#using_xolox_shell() @@ -136,7 +136,7 @@ function! gitgutter#utility#system(cmd, ...) return output 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') 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')) @@ -147,11 +147,11 @@ function! gitgutter#utility#file_relative_to_repo_root() return file_path_relative_to_repo_root 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 endfunction -function! gitgutter#utility#highlight_name_for_change(text) +function! gitgutter#utility#highlight_name_for_change(text) abort if a:text ==# 'added' return 'GitGutterLineAdded' elseif a:text ==# 'removed' @@ -165,20 +165,20 @@ function! gitgutter#utility#highlight_name_for_change(text) endif endfunction -function! gitgutter#utility#strip_trailing_new_line(line) +function! gitgutter#utility#strip_trailing_new_line(line) abort return substitute(a:line, '\n$', '', '') endfunction -function! gitgutter#utility#git_version() +function! gitgutter#utility#git_version() abort return matchstr(system('git --version'), '[0-9.]\+') endfunction " 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(), '\.') return major > 1 || (major == 1 && minor > 7) || (minor == 7 && patch > 1) endfunction -function! gitgutter#utility#stringify(list) +function! gitgutter#utility#stringify(list) abort return join(a:list, "\n")."\n" endfunction diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 608f73f..db7ac44 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -17,7 +17,7 @@ if !exists("*gettabvar") let g:gitgutter_eager = 0 endif -function! s:set(var, default) +function! s:set(var, default) abort if !exists(a:var) if type(a:default) execute 'let' a:var '=' string(a:default)