diff --git a/powerline/config_files/config.json b/powerline/config_files/config.json index e9a627e7..4da4e9b1 100644 --- a/powerline/config_files/config.json +++ b/powerline/config_files/config.json @@ -39,10 +39,10 @@ "help": "help", "quickfix": "quickfix", - "powerline.matchers.plugin.nerdtree.nerdtree": "plugin/nerdtree", - "powerline.matchers.plugin.ctrlp.ctrlp": "plugin/ctrlp", - "powerline.matchers.plugin.gundo.gundo": "plugin/gundo", - "powerline.matchers.plugin.gundo.gundo_preview": "plugin/gundo-preview" + "powerline.matchers.plugin.nerdtree.nerdtree": "plugin_nerdtree", + "powerline.matchers.plugin.ctrlp.ctrlp": "plugin_ctrlp", + "powerline.matchers.plugin.gundo.gundo": "plugin_gundo", + "powerline.matchers.plugin.gundo.gundo_preview": "plugin_gundo-preview" } }, "wm": { diff --git a/powerline/config_files/themes/tmux/default.json b/powerline/config_files/themes/tmux/default.json index 7d475c96..ecf6fbb1 100644 --- a/powerline/config_files/themes/tmux/default.json +++ b/powerline/config_files/themes/tmux/default.json @@ -4,18 +4,8 @@ "uptime": { "before": "⇑ " }, - "external_ip": { - "before": "ⓦ " - }, "date": { "before": "⌚ " - }, - "email_imap_alert": { - "before": "✉ ", - "args": { - "username": "", - "password": "" - } } }, "segments": { diff --git a/powerline/config_files/themes/vim/plugin/ctrlp.json b/powerline/config_files/themes/vim/plugin_ctrlp.json similarity index 100% rename from powerline/config_files/themes/vim/plugin/ctrlp.json rename to powerline/config_files/themes/vim/plugin_ctrlp.json diff --git a/powerline/config_files/themes/vim/plugin/gundo-preview.json b/powerline/config_files/themes/vim/plugin_gundo-preview.json similarity index 85% rename from powerline/config_files/themes/vim/plugin/gundo-preview.json rename to powerline/config_files/themes/vim/plugin_gundo-preview.json index 3ce202ea..cd3b00fe 100644 --- a/powerline/config_files/themes/vim/plugin/gundo-preview.json +++ b/powerline/config_files/themes/vim/plugin_gundo-preview.json @@ -1,5 +1,4 @@ { - "default_module": "powerline.segments.plugin.gundo", "segments": { "left": [ { diff --git a/powerline/config_files/themes/vim/plugin/gundo.json b/powerline/config_files/themes/vim/plugin_gundo.json similarity index 85% rename from powerline/config_files/themes/vim/plugin/gundo.json rename to powerline/config_files/themes/vim/plugin_gundo.json index 0c1a336a..0d6a448e 100644 --- a/powerline/config_files/themes/vim/plugin/gundo.json +++ b/powerline/config_files/themes/vim/plugin_gundo.json @@ -1,5 +1,4 @@ { - "default_module": "powerline.segments.plugin.gundo", "segments": { "left": [ { diff --git a/powerline/config_files/themes/vim/plugin/nerdtree.json b/powerline/config_files/themes/vim/plugin_nerdtree.json similarity index 100% rename from powerline/config_files/themes/vim/plugin/nerdtree.json rename to powerline/config_files/themes/vim/plugin_nerdtree.json diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index 37c1c180..2570df41 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -43,9 +43,22 @@ def context_key(context): return key_sep.join((c[0] for c in context)) -class DelayedEchoErr(object): - def __init__(self, echoerr): +class EchoErr(object): + __slots__ = ('echoerr', 'logger',) + + def __init__(self, echoerr, logger): self.echoerr = echoerr + self.logger = logger + + def __call__(self, *args, **kwargs): + self.echoerr(*args, **kwargs) + + +class DelayedEchoErr(EchoErr): + __slots__ = ('echoerr', 'logger', 'errs') + + def __init__(self, echoerr): + super(DelayedEchoErr, self).__init__(echoerr, echoerr.logger) self.errs = [] def __call__(self, *args, **kwargs): @@ -331,7 +344,9 @@ class Spec(object): if khadproblem: hadproblem = True if proceed: - valspec.match(value[key], value.mark, data, context + ((key, value[key]),), echoerr) + proceed, vhadproblem = valspec.match(value[key], value.mark, data, context + ((key, value[key]),), echoerr) + if vhadproblem: + hadproblem = True break else: hadproblem = True @@ -603,7 +618,9 @@ def check_segment_module(module, data, context, echoerr): with WithPath(data['import_paths']): try: __import__(unicode(module)) - except ImportError: + except ImportError as e: + if echoerr.logger.level >= logging.DEBUG: + echoerr.logger.exception(e) echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)), problem='failed to import module {0}'.format(module), problem_mark=module.mark) @@ -984,13 +1001,19 @@ theme_spec = (Spec( ).context_message('Error while loading theme')) -def check(path=None): +def check(path=None, debug=False): search_paths = [path] if path else Powerline.get_config_paths() + logger = logging.getLogger('powerline-lint') + logger.setLevel(logging.DEBUG if debug else logging.ERROR) + logger.addHandler(logging.StreamHandler()) + + ee = EchoErr(echoerr, logger) + dirs = { - 'themes': defaultdict(lambda: []), - 'colorschemes': defaultdict(lambda: []) - } + 'themes': defaultdict(lambda: []), + 'colorschemes': defaultdict(lambda: []) + } for path in reversed(search_paths): for subdir in ('themes', 'colorschemes'): d = os.path.join(path, subdir) @@ -1004,14 +1027,16 @@ def check(path=None): sys.stderr.write('Path {0} is supposed to be a directory, but it is not\n'.format(d)) configs = { - 'themes': defaultdict(lambda: {}), - 'colorschemes': defaultdict(lambda: {}) - } + 'themes': defaultdict(lambda: {}), + 'colorschemes': defaultdict(lambda: {}) + } for subdir in ('themes', 'colorschemes'): for ext in dirs[subdir]: for d in dirs[subdir][ext]: for config in os.listdir(d): - if config.endswith('.json'): + if os.path.isdir(os.path.join(d, config)): + dirs[subdir][ext].append(os.path.join(d, config)) + elif config.endswith('.json'): configs[subdir][ext][config[:-5]] = os.path.join(d, config) diff = set(configs['themes']) ^ set(configs['colorschemes']) @@ -1022,7 +1047,7 @@ def check(path=None): ext, 'configuration' if (ext in dirs['themes'] and ext in dirs['colorschemes']) else 'directory', 'themes' if ext in configs['themes'] else 'colorschemes', - )) + )) lhadproblem = [False] @@ -1044,7 +1069,7 @@ def check(path=None): sys.stderr.write(str(e) + '\n') hadproblem = True else: - if main_spec.match(main_config, data={'configs': configs}, context=(('', main_config),))[1]: + if main_spec.match(main_config, data={'configs': configs}, context=(('', main_config),), echoerr=ee)[1]: hadproblem = True import_paths = [os.path.expanduser(path) for path in main_config.get('common', {}).get('paths', [])] @@ -1060,7 +1085,7 @@ def check(path=None): sys.stderr.write(str(e) + '\n') hadproblem = True else: - if colors_spec.match(colors_config, context=(('', colors_config),))[1]: + if colors_spec.match(colors_config, context=(('', colors_config),), echoerr=ee)[1]: hadproblem = True if lhadproblem[0]: @@ -1084,7 +1109,7 @@ def check(path=None): spec = vim_colorscheme_spec else: spec = colorscheme_spec - if spec.match(config, context=(('', config),), data=data)[1]: + if spec.match(config, context=(('', config),), data=data, echoerr=ee)[1]: hadproblem = True theme_configs = defaultdict(lambda: {}) @@ -1105,6 +1130,6 @@ def check(path=None): 'main_config': main_config, 'ext_theme_configs': configs, 'colors_config': colors_config} for theme, config in configs.items(): data['theme'] = theme - if theme_spec.match(config, context=(('', config),), data=data)[1]: + if theme_spec.match(config, context=(('', config),), data=data, echoerr=ee)[1]: hadproblem = True return hadproblem diff --git a/powerline/matchers/plugin/ctrlp.py b/powerline/matchers/plugin/ctrlp.py index 50b374a7..d6754798 100644 --- a/powerline/matchers/plugin/ctrlp.py +++ b/powerline/matchers/plugin/ctrlp.py @@ -1,19 +1,22 @@ # vim:fileencoding=utf-8:noet import os -import vim +try: + import vim -vim.command('''function! Powerline_plugin_ctrlp_main(...) - let b:powerline_ctrlp_type = 'main' - let b:powerline_ctrlp_args = a:000 -endfunction''') + vim.command('''function! Powerline_plugin_ctrlp_main(...) + let b:powerline_ctrlp_type = 'main' + let b:powerline_ctrlp_args = a:000 + endfunction''') -vim.command('''function! Powerline_plugin_ctrlp_prog(...) - let b:powerline_ctrlp_type = 'prog' - let b:powerline_ctrlp_args = a:000 -endfunction''') + vim.command('''function! Powerline_plugin_ctrlp_prog(...) + let b:powerline_ctrlp_type = 'prog' + let b:powerline_ctrlp_args = a:000 + endfunction''') -vim.command('''let g:ctrlp_status_func = { 'main': 'Powerline_plugin_ctrlp_main', 'prog': 'Powerline_plugin_ctrlp_prog' }''') + vim.command('''let g:ctrlp_status_func = { 'main': 'Powerline_plugin_ctrlp_main', 'prog': 'Powerline_plugin_ctrlp_prog' }''') +except ImportError: + vim = object() # NOQA def ctrlp(matcher_info): diff --git a/powerline/segments/plugin/ctrlp.py b/powerline/segments/plugin/ctrlp.py index d8b4e3d8..e5893d7d 100644 --- a/powerline/segments/plugin/ctrlp.py +++ b/powerline/segments/plugin/ctrlp.py @@ -1,10 +1,18 @@ # vim:fileencoding=utf-8:noet -import vim +try: + import vim +except ImportError: + vim = object() # NOQA + from powerline.bindings.vim import getbufvar def ctrlp(pl, side): + ''' + + Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``, ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``, ``ctrlp.progress`` or ``file_name``, ``ctrlp.progress`` or ``file_name``. + ''' ctrlp_type = getbufvar('%', 'powerline_ctrlp_type') ctrlp_args = getbufvar('%', 'powerline_ctrlp_args') @@ -12,6 +20,10 @@ def ctrlp(pl, side): def ctrlp_stl_left_main(pl, focus, byfname, regex, prev, item, next, marked): + ''' + + Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``. + ''' marked = marked[2:-1] segments = [] @@ -54,6 +66,10 @@ def ctrlp_stl_left_main(pl, focus, byfname, regex, prev, item, next, marked): def ctrlp_stl_right_main(pl, focus, byfname, regex, prev, item, next, marked): + ''' + + Highlight groups used: ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``. + ''' segments = [ { 'contents': focus, @@ -72,6 +88,10 @@ def ctrlp_stl_right_main(pl, focus, byfname, regex, prev, item, next, marked): def ctrlp_stl_left_prog(pl, progress): + ''' + + Highlight groups used: ``ctrlp.progress`` or ``file_name``. + ''' return [ { 'contents': 'Loading...', @@ -81,6 +101,10 @@ def ctrlp_stl_left_prog(pl, progress): def ctrlp_stl_right_prog(pl, progress): + ''' + + Highlight groups used: ``ctrlp.progress`` or ``file_name``. + ''' return [ { 'contents': progress, diff --git a/powerline/segments/plugin/nerdtree.py b/powerline/segments/plugin/nerdtree.py index c12ce777..39eb5aec 100644 --- a/powerline/segments/plugin/nerdtree.py +++ b/powerline/segments/plugin/nerdtree.py @@ -1,6 +1,9 @@ # vim:fileencoding=utf-8:noet -import vim +try: + import vim +except ImportError: + vim = object() # NOQA from powerline.bindings.vim import getbufvar from powerline.segments.vim import window_cached @@ -8,6 +11,10 @@ from powerline.segments.vim import window_cached @window_cached def nerdtree(pl): + '''Return directory that is shown by the current buffer. + + Highlight groups used: ``nerdtree.path`` or ``file_name``. + ''' ntr = getbufvar('%', 'NERDTreeRoot') if not ntr: return diff --git a/powerline/segments/plugin/syntastic.py b/powerline/segments/plugin/syntastic.py index 4c470dd9..71a411fa 100644 --- a/powerline/segments/plugin/syntastic.py +++ b/powerline/segments/plugin/syntastic.py @@ -1,12 +1,25 @@ # vim:fileencoding=utf-8:noet -import vim +try: + import vim +except ImportError: + vim = object() # NOQA from powerline.segments.vim import window_cached @window_cached -def syntastic(pl): +def syntastic(pl, err_format='ERR:  {first_line} ({num}) ', warn_format='WARN:  {first_line} ({num}) '): + '''Show whether syntastic has found any errors or warnings + + :param str err_format: + Format string for errors. + + :param str warn_format: + Format string for warnings. + + Highlight groups used: ``syntastic.warning`` or ``warning``, ``syntastic.error`` or ``error``. + ''' if not int(vim.eval('exists("g:SyntasticLoclist")')): return has_errors = int(vim.eval('g:SyntasticLoclist.current().hasErrorsOrWarningsToDisplay()')) @@ -17,12 +30,12 @@ def syntastic(pl): segments = [] if errors: segments.append({ - 'contents': 'ERR:  {line} ({num}) '.format(line=errors[0]['lnum'], num=len(errors)), - 'highlight_group': ['syntastic.error', 'error', 'background'], - }) + 'contents': err_format.format(first_line=errors[0]['lnum'], num=len(errors)), + 'highlight_group': ['syntastic.error', 'error'], + }) if warnings: segments.append({ - 'contents': 'WARN:  {line} ({num}) '.format(line=warnings[0]['lnum'], num=len(warnings)), - 'highlight_group': ['syntastic.warning', 'warning', 'background'], - }) + 'contents': warn_format.format(first_line=warnings[0]['lnum'], num=len(warnings)), + 'highlight_group': ['syntastic.warning', 'warning'], + }) return segments diff --git a/powerline/segments/plugin/tagbar.py b/powerline/segments/plugin/tagbar.py index 07e260f8..24e8db52 100644 --- a/powerline/segments/plugin/tagbar.py +++ b/powerline/segments/plugin/tagbar.py @@ -1,6 +1,9 @@ # vim:fileencoding=utf-8:noet -import vim +try: + import vim +except ImportError: + vim = object() # NOQA from powerline.segments.vim import window_cached diff --git a/scripts/powerline-lint b/scripts/powerline-lint index 6d20e38f..d8a05ca3 100755 --- a/scripts/powerline-lint +++ b/scripts/powerline-lint @@ -8,7 +8,8 @@ import sys parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-p', '--config_path', metavar='PATH') +parser.add_argument('-d', '--debug', action='store_const', const=True) if __name__ == '__main__': args = parser.parse_args() - sys.exit(check(args.config_path)) + sys.exit(check(args.config_path, args.debug))