mirror of
https://github.com/powerline/powerline.git
synced 2025-07-24 22:36:01 +02:00
Create a way to log to the list in Vim
This commit is contained in:
parent
d51a50223e
commit
1c1d33dbbf
@ -31,6 +31,12 @@ Vim configuration can be overridden using the following options:
|
|||||||
If this variable is set to a true value it will prevent Powerline from reporting
|
If this variable is set to a true value it will prevent Powerline from reporting
|
||||||
an error when loaded in a copy of vim without the necessary Python support.
|
an error when loaded in a copy of vim without the necessary Python support.
|
||||||
|
|
||||||
|
``g:powerline_use_var_handler``
|
||||||
|
This variable may be set to either 0 or 1. If it is set to 1 then Vim will
|
||||||
|
save log in ``g:powerline_log_messages`` variable in addition to whatever
|
||||||
|
was configured in :ref:`log_* options <config-common-log>`. Level is always
|
||||||
|
:ref:`log_level <config-common-log_level>`, same for format.
|
||||||
|
|
||||||
Powerline script overrides
|
Powerline script overrides
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
@ -98,6 +98,8 @@ Common configuration is a subdictionary that is a value of ``common`` key in
|
|||||||
Defines path which will hold powerline logs. If not present, logging will be
|
Defines path which will hold powerline logs. If not present, logging will be
|
||||||
done to stderr.
|
done to stderr.
|
||||||
|
|
||||||
|
.. _config-common-log_level:
|
||||||
|
|
||||||
``log_level``
|
``log_level``
|
||||||
String, determines logging level. Defaults to ``WARNING``.
|
String, determines logging level. Defaults to ``WARNING``.
|
||||||
|
|
||||||
|
@ -424,6 +424,14 @@ class Powerline(object):
|
|||||||
Usually returns encoding of the current locale.
|
Usually returns encoding of the current locale.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def create_logger(self):
|
||||||
|
'''Create logger
|
||||||
|
|
||||||
|
This function is used to create logger unless it was already specified
|
||||||
|
at initialization.
|
||||||
|
'''
|
||||||
|
return create_logger(self.common_config, self.default_log_stream)
|
||||||
|
|
||||||
def create_renderer(self, load_main=False, load_colors=False, load_colorscheme=False, load_theme=False):
|
def create_renderer(self, load_main=False, load_colors=False, load_colorscheme=False, load_theme=False):
|
||||||
'''(Re)create renderer object. Can be used after Powerline object was
|
'''(Re)create renderer object. Can be used after Powerline object was
|
||||||
successfully initialized. If any of the below parameters except
|
successfully initialized. If any of the below parameters except
|
||||||
@ -461,7 +469,7 @@ class Powerline(object):
|
|||||||
self.import_paths = self.common_config['paths']
|
self.import_paths = self.common_config['paths']
|
||||||
|
|
||||||
if not self.logger:
|
if not self.logger:
|
||||||
self.logger = create_logger(self.common_config, self.default_log_stream)
|
self.logger = self.create_logger()
|
||||||
|
|
||||||
if not self.pl:
|
if not self.pl:
|
||||||
self.pl = PowerlineLogger(self.use_daemon_threads, self.logger, self.ext)
|
self.pl = PowerlineLogger(self.use_daemon_threads, self.logger, self.ext)
|
||||||
|
@ -3,14 +3,16 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
|
||||||
import vim
|
import vim
|
||||||
|
|
||||||
from powerline.bindings.vim import vim_get_func, vim_getvar, get_vim_encoding
|
from powerline.bindings.vim import vim_get_func, vim_getvar, get_vim_encoding, python_to_vim
|
||||||
from powerline import Powerline, FailedUnicode
|
from powerline import Powerline, FailedUnicode
|
||||||
from powerline.lib.dict import mergedicts
|
from powerline.lib.dict import mergedicts
|
||||||
|
from powerline.lib.unicode import u
|
||||||
|
|
||||||
|
|
||||||
def _override_from(config, override_varname):
|
def _override_from(config, override_varname):
|
||||||
@ -22,6 +24,24 @@ def _override_from(config, override_varname):
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
class VimVarHandler(logging.Handler):
|
||||||
|
'''Vim-specific handler which emits messages to Vim global variables
|
||||||
|
|
||||||
|
Used variable: ``g:powerline_log_messages``.
|
||||||
|
'''
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(VimVarHandler, self).__init__(*args, **kwargs)
|
||||||
|
vim.command('unlet! g:powerline_log_messages')
|
||||||
|
vim.command('let g:powerline_log_messages = []')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def emit(record):
|
||||||
|
message = u(record.message)
|
||||||
|
if record.exc_text:
|
||||||
|
message += '\n' + u(record.exc_text)
|
||||||
|
vim.eval(b'add(g:powerline_log_messages, ' + python_to_vim(message) + b')')
|
||||||
|
|
||||||
|
|
||||||
class VimPowerline(Powerline):
|
class VimPowerline(Powerline):
|
||||||
def init(self, pyeval='PowerlinePyeval', **kwargs):
|
def init(self, pyeval='PowerlinePyeval', **kwargs):
|
||||||
super(VimPowerline, self).init('vim', **kwargs)
|
super(VimPowerline, self).init('vim', **kwargs)
|
||||||
@ -31,6 +51,18 @@ class VimPowerline(Powerline):
|
|||||||
|
|
||||||
default_log_stream = sys.stdout
|
default_log_stream = sys.stdout
|
||||||
|
|
||||||
|
def create_logger(self):
|
||||||
|
logger = super(VimPowerline, self).create_logger()
|
||||||
|
try:
|
||||||
|
if int(vim_getvar('powerline_use_var_handler')):
|
||||||
|
formatter = logging.Formatter(self.common_config['log_format'])
|
||||||
|
handler = VimVarHandler(getattr(logging, self.common_config['log_level']))
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
return logger
|
||||||
|
|
||||||
def add_local_theme(self, key, config):
|
def add_local_theme(self, key, config):
|
||||||
'''Add local themes at runtime (during vim session).
|
'''Add local themes at runtime (during vim session).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user