Commit e419bfc1 authored by Florian Münchbach's avatar Florian Münchbach

[syntax_highlight] Code cleanup

parent c21a78b7
......@@ -4,7 +4,7 @@ import pygments
from gi.repository import Gtk
from gajim.plugins.helpers import log_calls, log
from gajim.plugins.helpers import log
from .gtkformatter import GTKFormatter
......@@ -183,7 +183,6 @@ class ChatSyntaxHighlighter:
buf.begin_user_action()
for num, (text_to_insert, match_type) in enumerate(split_text):
marker = [("", 0), ("", 0)]
language = None
end_of_message = num == (len(split_text) - 1)
......@@ -269,5 +268,3 @@ class ChatSyntaxHighlighter:
self.last_end_mark = None
self.config = config
self.textview = textview
from gajim.plugins.helpers import log_calls, log
from gajim.plugins.helpers import log
from gi.repository import Gdk
from pygments.lexers import get_lexer_by_name, get_all_lexers
from pygments.styles import get_all_styles
from .types import MatchType, LineBreakOptions, CodeMarkerOptions, \
from .types import LineBreakOptions, CodeMarkerOptions, \
PLUGIN_INTERNAL_NONE_LEXER_ID
class SyntaxHighlighterConfig:
......@@ -27,9 +29,9 @@ class SyntaxHighlighterConfig:
return lexers
def is_internal_none_lexer(self, lexer):
return (lexer == PLUGIN_INTERNAL_NONE_LEXER_ID)
return lexer == PLUGIN_INTERNAL_NONE_LEXER_ID
def get_internal_none_lexer(self, lexer):
def get_internal_none_lexer(self):
return self.PLUGIN_INTERNAL_NONE_LEXER
def get_lexer_by_name(self, name):
......@@ -154,5 +156,3 @@ class SyntaxHighlighterConfig:
self.style_list = []
self.config = config
self.default_lexer = None
import logging
import re
import pygments
from gi.repository import Gtk, Gdk
......@@ -6,13 +6,11 @@ from gi.repository.Pango import FontDescription
from gajim.plugins.gui import GajimPluginConfigDialog
from gajim.plugins.helpers import log_calls, log
from gajim.plugins.helpers import log_calls
from .gtkformatter import GTKFormatter
from .types import MatchType, LineBreakOptions, CodeMarkerOptions
log = logging.getLogger('gajim.plugin_system.syntax_highlight')
from .types import LineBreakOptions, CodeMarkerOptions
class SyntaxHighlighterPluginConfiguration(GajimPluginConfigDialog):
@log_calls('SyntaxHighlighterPluginConfiguration')
......
import logging
import re
import sys
import importlib
if sys.version_info >= (3, 4):
from importlib.util import find_spec as find_module
else:
from importlib import find_loader as find_module
from gajim.plugins.helpers import log_calls, log
from gajim.plugins import GajimPlugin
......@@ -12,13 +16,14 @@ from .types import MatchType, LineBreakOptions, CodeMarkerOptions, \
log = logging.getLogger('gajim.plugin_system.syntax_highlight')
def try_loading_pygments():
success = importlib.find_loader('pygments') is not None
success = find_module('pygments') is not None
if success:
try:
from .chat_syntax_highlighter import ChatSyntaxHighlighter
from .plugin_config_dialog import SyntaxHighlighterPluginConfiguration
from .plugin_config import SyntaxHighlighterConfig
global SyntaxHighlighterPluginConfiguration, ChatSyntaxHighlighter, SyntaxHighlighterConfig
global SyntaxHighlighterPluginConfiguration, ChatSyntaxHighlighter, \
SyntaxHighlighterConfig
success = True
log.debug("pygments loaded.")
except Exception as exception:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment