From c4c56716fec8f84a6ef5fb0a2e74dd57ea4a931b Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Mon, 3 Nov 2014 11:58:46 +0200 Subject: [PATCH] More naming conventions. --- autoload/syntastic/c.vim | 192 +++++++++++++++++----------------- autoload/syntastic/log.vim | 28 ++--- autoload/syntastic/util.vim | 10 +- plugin/syntastic.vim | 44 ++++---- plugin/syntastic/checker.vim | 6 +- plugin/syntastic/cursor.vim | 12 +-- plugin/syntastic/loclist.vim | 22 ++-- plugin/syntastic/registry.vim | 10 +- 8 files changed, 166 insertions(+), 158 deletions(-) diff --git a/autoload/syntastic/c.vim b/autoload/syntastic/c.vim index 32226482..d19aebce 100644 --- a/autoload/syntastic/c.vim +++ b/autoload/syntastic/c.vim @@ -62,7 +62,7 @@ endfunction " }}}2 " GetLocList() for C-like compilers function! syntastic#c#GetLocList(filetype, subchecker, options) " {{{2 try - let flags = s:_getCflags(a:filetype, a:subchecker, a:options) + let flags = s:_get_cflags(a:filetype, a:subchecker, a:options) catch /\m\C^Syntastic: skip checks$/ return [] endtry @@ -70,9 +70,9 @@ function! syntastic#c#GetLocList(filetype, subchecker, options) " {{{2 let makeprg = syntastic#util#shexpand(g:syntastic_{a:filetype}_compiler) . \ ' ' . flags . ' ' . syntastic#util#shexpand('%') - let errorformat = s:_getCheckerVar('g', a:filetype, a:subchecker, 'errorformat', a:options['errorformat']) + let errorformat = s:_get_checker_var('g', a:filetype, a:subchecker, 'errorformat', a:options['errorformat']) - let postprocess = s:_getCheckerVar('g', a:filetype, a:subchecker, 'remove_include_errors', 0) ? + let postprocess = s:_get_checker_var('g', a:filetype, a:subchecker, 'remove_include_errors', 0) ? \ ['filterForeignErrors'] : [] " process makeprg @@ -91,25 +91,25 @@ function! s:_init() " {{{2 let s:handlers = [] let s:cflags = {} - call s:_regHandler('\m\', 's:_check_php', []) - call s:_regHandler('\m\', 's:_check_python', []) - call s:_regHandler('\m\', 's:_checkPhp', []) + call s:_registerHandler('\m\', 's:_checkPython', []) + call s:_registerHandler('\m\ 0 @@ -81,11 +81,11 @@ function! syntastic#log#debug(level, msg, ...) " {{{2 endfunction " }}}2 function! syntastic#log#debugShowOptions(level, names) " {{{2 - if !s:isDebugEnabled(a:level) + if !s:_isDebugEnabled(a:level) return endif - let leader = s:_logTimestamp() + let leader = s:_log_timestamp() call s:_logRedirect(1) let vlist = copy(type(a:names) == type("") ? [a:names] : a:names) @@ -97,16 +97,16 @@ function! syntastic#log#debugShowOptions(level, names) " {{{2 endfunction " }}}2 function! syntastic#log#debugShowVariables(level, names) " {{{2 - if !s:isDebugEnabled(a:level) + if !s:_isDebugEnabled(a:level) return endif - let leader = s:_logTimestamp() + let leader = s:_log_timestamp() call s:_logRedirect(1) let vlist = type(a:names) == type("") ? [a:names] : a:names for name in vlist - let msg = s:_formatVariable(name) + let msg = s:_format_variable(name) if msg != '' echomsg leader . msg endif @@ -116,7 +116,7 @@ function! syntastic#log#debugShowVariables(level, names) " {{{2 endfunction " }}}2 function! syntastic#log#debugDump(level) " {{{2 - if !s:isDebugEnabled(a:level) + if !s:_isDebugEnabled(a:level) return endif @@ -136,8 +136,8 @@ function! s:_isDebugEnabled_dumb(level) " {{{2 return (g:syntastic_debug / a:level) % 2 endfunction " }}}2 -let s:isDebugEnabled = function(exists('*and') ? 's:_isDebugEnabled_smart' : 's:_isDebugEnabled_dumb') -lockvar s:isDebugEnabled +let s:_isDebugEnabled = function(exists('*and') ? 's:_isDebugEnabled_smart' : 's:_isDebugEnabled_dumb') +lockvar s:_isDebugEnabled function! s:_logRedirect(on) " {{{2 if exists("g:syntastic_debug_file") @@ -154,11 +154,15 @@ function! s:_logRedirect(on) " {{{2 endif endfunction " }}}2 -function! s:_logTimestamp() " {{{2 +" }}}1 + +" Utilities {{{1 + +function! s:_log_timestamp() " {{{2 return 'syntastic: ' . split(reltimestr(reltime(g:_SYNTASTIC_START)))[0] . ': ' endfunction " }}}2 -function! s:_formatVariable(name) " {{{2 +function! s:_format_variable(name) " {{{2 let vals = [] if exists('g:syntastic_' . a:name) call add(vals, 'g:syntastic_' . a:name . ' = ' . strtrans(string(g:syntastic_{a:name}))) diff --git a/autoload/syntastic/util.vim b/autoload/syntastic/util.vim index 27ef34b2..20cd0d4f 100644 --- a/autoload/syntastic/util.vim +++ b/autoload/syntastic/util.vim @@ -141,14 +141,14 @@ endfunction " }}}2 " strwidth() was added in Vim 7.3; if it doesn't exist, we use strlen() " and hope for the best :) -let s:width = function(exists('*strwidth') ? 'strwidth' : 'strlen') -lockvar s:width +let s:_width = function(exists('*strwidth') ? 'strwidth' : 'strlen') +lockvar s:_width function! syntastic#util#screenWidth(str, tabstop) " {{{2 let chunks = split(a:str, "\t", 1) - let width = s:width(chunks[-1]) + let width = s:_width(chunks[-1]) for c in chunks[:-2] - let cwidth = s:width(c) + let cwidth = s:_width(c) let width += cwidth + a:tabstop - cwidth % a:tabstop endfor return width @@ -166,7 +166,7 @@ function! syntastic#util#wideMsg(msg) " {{{2 "convert tabs to spaces so that the tabs count towards the window "width as the proper amount of characters let chunks = split(msg, "\t", 1) - let msg = join(map(chunks[:-2], 'v:val . repeat(" ", &tabstop - s:width(v:val) % &tabstop)'), '') . chunks[-1] + let msg = join(map(chunks[:-2], 'v:val . repeat(" ", &tabstop - s:_width(v:val) % &tabstop)'), '') . chunks[-1] let msg = strpart(msg, 0, &columns - 1) set noruler noshowcmd diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 4a00a1f4..849b67de 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -154,7 +154,7 @@ let s:modemap = g:SyntasticModeMap.Instance() " @vimlint(EVL103, 1, a:argLead) function! s:CompleteCheckerName(argLead, cmdLine, cursorPos) " {{{2 let checker_names = [] - for ft in s:resolveFiletypes() + for ft in s:_resolve_filetypes() call extend(checker_names, s:registry.getNamesOfAvailableCheckers(ft)) endfor return join(checker_names, "\n") @@ -181,8 +181,8 @@ command! -nargs=* -complete=custom,s:CompleteCheckerName SyntasticCheck command! Errors call s:ShowLocList() command! -nargs=? -complete=custom,s:CompleteFiletypes SyntasticInfo \ call s:modemap.modeInfo() - \ call s:registry.echoInfoFor(s:resolveFiletypes()) - \ call s:explainSkip() + \ call s:registry.echoInfoFor(s:_resolve_filetypes()) + \ call s:_explain_skip() command! SyntasticReset \ call s:ClearCache() \ call s:notifiers.refresh(g:SyntasticLoclist.New([])) @@ -256,7 +256,7 @@ function! s:UpdateErrors(auto_invoked, ...) " {{{2 call syntastic#log#debugDump(g:_SYNTASTIC_DEBUG_VARIABLES) call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, 'UpdateErrors' . (a:auto_invoked ? ' (auto)' : '') . \ ': ' . (a:0 ? join(a:000) : 'default checkers')) - if s:skipFile() + if s:_skip_file() return endif @@ -312,13 +312,13 @@ function! s:CacheErrors(checker_names) " {{{2 call s:ClearCache() let newLoclist = g:SyntasticLoclist.New([]) - if !s:skipFile() + if !s:_skip_file() " debug logging {{{3 call syntastic#log#debugShowVariables(g:_SYNTASTIC_DEBUG_TRACE, 'aggregate_errors') call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, 'getcwd() = ' . getcwd()) " }}}3 - let filetypes = s:resolveFiletypes() + let filetypes = s:_resolve_filetypes() let aggregate_errors = syntastic#util#var('aggregate_errors') || len(filetypes) > 1 let decorate_errors = aggregate_errors && syntastic#util#var('id_checkers') let sort_aggregated_errors = aggregate_errors && syntastic#util#var('sort_aggregated_errors') @@ -440,7 +440,7 @@ function! SyntasticMake(options) " {{{2 let old_lc_all = $LC_ALL " }}}3 - call s:bashHack() + call s:_bash_hack() if has_key(a:options, 'errorformat') let &errorformat = a:options['errorformat'] @@ -519,7 +519,7 @@ function! SyntasticMake(options) " {{{2 let &shellredir = old_shellredir " }}}3 - if !s:_running_windows && (s:uname() =~ "FreeBSD" || s:uname() =~ "OpenBSD") + if !s:_running_windows && (s:_os_name() =~ "FreeBSD" || s:_os_name() =~ "OpenBSD") call syntastic#util#redraw(g:syntastic_full_redraws) endif @@ -530,12 +530,12 @@ function! SyntasticMake(options) " {{{2 call syntastic#log#debug(g:_SYNTASTIC_DEBUG_LOCLIST, 'raw loclist:', errors) if has_key(a:options, 'defaults') - call s:addToErrors(errors, a:options['defaults']) + call s:_add_to_errors(errors, a:options['defaults']) endif " Add subtype info if present. if has_key(a:options, 'subtype') - call s:addToErrors(errors, { 'subtype': a:options['subtype'] }) + call s:_add_to_errors(errors, { 'subtype': a:options['subtype'] }) endif if has_key(a:options, 'Postprocess') && !empty(a:options['Postprocess']) @@ -566,12 +566,12 @@ endfunction " }}}2 " Utilities {{{1 -function! s:resolveFiletypes(...) " {{{2 +function! s:_resolve_filetypes(...) " {{{2 let type = a:0 ? a:1 : &filetype return split( get(g:syntastic_filetype_map, type, type), '\m\.' ) endfunction " }}}2 -function! s:ignoreFile(filename) " {{{2 +function! s:_ignore_file(filename) " {{{2 let fname = fnamemodify(a:filename, ':p') for pattern in g:syntastic_ignore_files if fname =~# pattern @@ -582,20 +582,20 @@ function! s:ignoreFile(filename) " {{{2 endfunction " }}}2 " Skip running in special buffers -function! s:skipFile() " {{{2 +function! s:_skip_file() " {{{2 let fname = expand('%') let skip = get(b:, 'syntastic_skip_checks', 0) || (&buftype != '') || - \ !filereadable(fname) || getwinvar(0, '&diff') || s:ignoreFile(fname) || + \ !filereadable(fname) || getwinvar(0, '&diff') || s:_ignore_file(fname) || \ fnamemodify(fname, ':e') =~? g:syntastic_ignore_extensions if skip - call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, 'skipFile: skipping') + call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, '_skip_file: skipping checks') endif return skip endfunction " }}}2 " Explain why checks will be skipped for the current file -function! s:explainSkip(...) " {{{2 - if !a:0 && s:skipFile() +function! s:_explain_skip(...) " {{{2 + if !a:0 && s:_skip_file() let why = [] let fname = expand('%') @@ -611,7 +611,7 @@ function! s:explainSkip(...) " {{{2 if getwinvar(0, '&diff') call add(why, 'diff mode') endif - if s:ignoreFile(fname) + if s:_ignore_file(fname) call add(why, 'filename matching g:syntastic_ignore_files') endif if fnamemodify(fname, ':e') =~? g:syntastic_ignore_extensions @@ -623,7 +623,7 @@ function! s:explainSkip(...) " {{{2 endfunction " }}}2 " Take a list of errors and add default values to them from a:options -function! s:addToErrors(errors, options) " {{{2 +function! s:_add_to_errors(errors, options) " {{{2 for err in a:errors for key in keys(a:options) if !has_key(err, key) || empty(err[key]) @@ -638,12 +638,12 @@ endfunction " }}}2 " XXX: Is this still needed? " The script changes &shellredir to stop the screen " flicking when shelling out to syntax checkers. -function! s:bashHack() " {{{2 +function! s:_bash_hack() " {{{2 if g:syntastic_bash_hack if !exists('s:shell_is_bash') let s:shell_is_bash = \ !s:_running_windows && - \ (s:uname() !~# "FreeBSD") && (s:uname() !~# "OpenBSD") && + \ (s:_os_name() !~# "FreeBSD") && (s:_os_name() !~# "OpenBSD") && \ &shell =~# '\m\= 0 && a:line == a:old_line && a:idx >= 0 if len(a:messages) <= 1 return 1 @@ -113,7 +113,7 @@ function! s:_isSameIndex(line, old_line, column, idx, messages) " {{{2 endif endfunction " }}}2 -function! s:_findIndex(column, messages) " {{{2 +function! s:_find_index(column, messages) " {{{2 let max = len(a:messages) - 1 if max == 0 return 0 diff --git a/plugin/syntastic/loclist.vim b/plugin/syntastic/loclist.vim index fb7cefb7..84a6cd30 100644 --- a/plugin/syntastic/loclist.vim +++ b/plugin/syntastic/loclist.vim @@ -43,10 +43,10 @@ endfunction " }}}2 function! g:SyntasticLoclist.sort() " {{{2 if !self._sorted for e in self._rawLoclist - call s:_setScreenColumn(e) + call s:_set_screen_column(e) endfor - call sort(self._rawLoclist, self._columns ? 's:_compareErrorItemsByColumns' : 's:_compareErrorItemsByLines') + call sort(self._rawLoclist, self._columns ? 's:_compare_error_items_by_columns' : 's:_compare_error_items_by_lines') let self._sorted = 1 endif @@ -243,9 +243,9 @@ function! g:SyntasticLoclist.messages(buf) " {{{2 for l in keys(self._cachedMessages[b]) if len(self._cachedMessages[b][l]) > 1 for e in self._cachedMessages[b][l] - call s:_setScreenColumn(e) + call s:_set_screen_column(e) endfor - call sort(self._cachedMessages[b][l], 's:_compareErrorItemsByColumns') + call sort(self._cachedMessages[b][l], 's:_compare_error_items_by_columns') endif endfor endfor @@ -253,7 +253,7 @@ function! g:SyntasticLoclist.messages(buf) " {{{2 for b in keys(self._cachedMessages) for l in keys(self._cachedMessages[b]) - call s:_removeShadowedItems(self._cachedMessages[b][l]) + call s:_remove_shadowed_items(self._cachedMessages[b][l]) endfor endfor endif @@ -320,7 +320,7 @@ endfunction " }}}2 " }}}1 -" Non-method functions {{{1 +" Public functions {{{1 function! SyntasticLoclistHide() " {{{2 call syntastic#log#debug(g:_SYNTASTIC_DEBUG_NOTIFICATIONS, 'loclist: hide') @@ -329,13 +329,13 @@ endfunction " }}}2 " }}}1 -" Private functions {{{1 +" Utilities {{{1 function! s:_translate(key, val) " {{{2 return 'get(v:val, ' . string(a:key) . ', "") ==? ' . string(a:val) endfunction " }}}2 -function! s:_setScreenColumn(item) " {{{2 +function! s:_set_screen_column(item) " {{{2 if !has_key(a:item, 'scol') let col = get(a:item, 'col', 0) if col != 0 && get(a:item, 'vcol', 0) == 0 @@ -352,7 +352,7 @@ function! s:_setScreenColumn(item) " {{{2 endif endfunction " }}}2 -function! s:_removeShadowedItems(errors) " {{{2 +function! s:_remove_shadowed_items(errors) " {{{2 " keep only the first message at a given column let i = 0 while i < len(a:errors) - 1 @@ -384,7 +384,7 @@ function! s:_removeShadowedItems(errors) " {{{2 endwhile endfunction " }}}2 -function! s:_compareErrorItemsByColumns(a, b) " {{{2 +function! s:_compare_error_items_by_columns(a, b) " {{{2 if a:a['bufnr'] != a:b['bufnr'] " group by file return a:a['bufnr'] - a:b['bufnr'] @@ -402,7 +402,7 @@ function! s:_compareErrorItemsByColumns(a, b) " {{{2 endif endfunction " }}}2 -function! s:_compareErrorItemsByLines(a, b) " {{{2 +function! s:_compare_error_items_by_lines(a, b) " {{{2 if a:a['bufnr'] != a:b['bufnr'] " group by file return a:a['bufnr'] - a:b['bufnr'] diff --git a/plugin/syntastic/registry.vim b/plugin/syntastic/registry.vim index 8f50f8af..26afc04b 100644 --- a/plugin/syntastic/registry.vim +++ b/plugin/syntastic/registry.vim @@ -138,7 +138,7 @@ endfunction " }}}2 " not checked for availability (that is, the corresponding IsAvailable() are " not run). function! g:SyntasticRegistry.getCheckers(ftalias, hints_list) " {{{2 - let ft = s:_normaliseFiletype(a:ftalias) + let ft = s:_normalise_filetype(a:ftalias) call self._loadCheckersFor(ft) let checkers_map = self._checkerMap[ft] @@ -181,13 +181,13 @@ function! g:SyntasticRegistry.getKnownFiletypes() " {{{2 endfunction " }}}2 function! g:SyntasticRegistry.getNamesOfAvailableCheckers(ftalias) " {{{2 - let ft = s:_normaliseFiletype(a:ftalias) + let ft = s:_normalise_filetype(a:ftalias) call self._loadCheckersFor(ft) return keys(filter( copy(self._checkerMap[ft]), 'v:val.isAvailable()' )) endfunction " }}}2 function! g:SyntasticRegistry.echoInfoFor(ftalias_list) " {{{2 - let ft_list = syntastic#util#unique(map( copy(a:ftalias_list), 's:_normaliseFiletype(v:val)' )) + let ft_list = syntastic#util#unique(map( copy(a:ftalias_list), 's:_normalise_filetype(v:val)' )) if len(ft_list) != 1 let available = [] let active = [] @@ -257,11 +257,11 @@ endfunction " }}}2 " }}}1 -" Private functions {{{1 +" Utilities {{{1 "resolve filetype aliases, and replace - with _ otherwise we cant name "syntax checker functions legally for filetypes like "gentoo-metadata" -function! s:_normaliseFiletype(ftalias) " {{{2 +function! s:_normalise_filetype(ftalias) " {{{2 let ft = get(s:_DEFAULT_FILETYPE_MAP, a:ftalias, a:ftalias) let ft = get(g:syntastic_filetype_map, ft, ft) let ft = substitute(ft, '\m-', '_', 'g')