Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
gajim
gajim-plugins
Commits
c21a78b7
Commit
c21a78b7
authored
Feb 18, 2019
by
Florian Münchbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[syntax_highlight] By default, do not highlight but only set monospaced font
parent
7e068624
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
19 deletions
+40
-19
syntax_highlight/chat_syntax_highlighter.py
syntax_highlight/chat_syntax_highlighter.py
+1
-1
syntax_highlight/plugin_config.py
syntax_highlight/plugin_config.py
+31
-14
syntax_highlight/plugin_config_dialog.py
syntax_highlight/plugin_config_dialog.py
+3
-2
syntax_highlight/syntax_highlight.py
syntax_highlight/syntax_highlight.py
+3
-2
syntax_highlight/types.py
syntax_highlight/types.py
+2
-0
No files found.
syntax_highlight/chat_syntax_highlighter.py
View file @
c21a78b7
...
...
@@ -62,7 +62,7 @@ class ChatSyntaxHighlighter:
if
lexer
is
None
:
iterator
=
buf
.
get_iter_at_mark
(
start_mark
)
buf
.
insert
(
iterator
,
'
\n
'
)
el
se
:
el
if
not
self
.
config
.
is_internal_none_lexer
(
lexer
)
:
tokens
=
pygments
.
lex
(
code
,
lexer
)
formatter
=
GTKFormatter
(
style
=
style
,
start_mark
=
start_mark
)
...
...
syntax_highlight/plugin_config.py
View file @
c21a78b7
...
...
@@ -3,10 +3,15 @@ from gajim.plugins.helpers import log_calls, log
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
MatchType
,
LineBreakOptions
,
CodeMarkerOptions
,
\
PLUGIN_INTERNAL_NONE_LEXER_ID
class
SyntaxHighlighterConfig
:
PLUGIN_INTERNAL_NONE_LEXER
=
(
'None (monospace only)'
,
PLUGIN_INTERNAL_NONE_LEXER_ID
)
def
_create_lexer_list
(
self
):
# The list we create here contains the plain text name and the lexer's
# id string
lexers
=
[]
# Iteration over get_all_lexers() seems to be broken somehow. Workarround
...
...
@@ -16,8 +21,17 @@ class SyntaxHighlighterConfig:
if
lexer
[
1
]
is
not
None
and
lexer
[
1
]:
lexers
.
append
((
lexer
[
0
],
lexer
[
1
][
0
]))
lexers
.
sort
()
# Insert our internal "none" type at top of the list.
lexers
.
insert
(
0
,
self
.
PLUGIN_INTERNAL_NONE_LEXER
)
return
lexers
def
is_internal_none_lexer
(
self
,
lexer
):
return
(
lexer
==
PLUGIN_INTERNAL_NONE_LEXER_ID
)
def
get_internal_none_lexer
(
self
,
lexer
):
return
self
.
PLUGIN_INTERNAL_NONE_LEXER
def
get_lexer_by_name
(
self
,
name
):
lexer
=
None
try
:
...
...
@@ -48,20 +62,23 @@ class SyntaxHighlighterConfig:
self
.
config
[
'line_break'
]
=
option
def
set_default_lexer
(
self
,
name
):
lexer
=
get_lexer_by_name
(
name
)
if
lexer
is
None
and
self
.
default_lexer
is
None
:
log
.
error
(
"Failed to get default lexer by name."
\
"Falling back to simply using the first in the list."
)
lexer
=
self
.
lexer_list
[
0
]
name
=
lexer
[
0
]
self
.
default_lexer
=
(
name
,
lexer
)
if
lexer
is
None
and
self
.
default_lexer
is
not
None
:
log
.
info
(
"Failed to get default lexer by name, keeping previous"
\
"setting (lexer = %s)."
,
self
.
default_lexer
[
0
])
name
=
self
.
default_lexer
[
0
]
if
not
self
.
is_internal_none_lexer
(
name
):
lexer
=
get_lexer_by_name
(
name
)
if
lexer
is
None
and
self
.
default_lexer
is
None
:
log
.
error
(
"Failed to get default lexer by name."
\
"Falling back to simply using the first in the list."
)
lexer
=
self
.
lexer_list
[
0
]
name
=
lexer
[
0
]
self
.
default_lexer
=
(
name
,
lexer
)
if
lexer
is
None
and
self
.
default_lexer
is
not
None
:
log
.
info
(
"Failed to get default lexer by name, keeping previous"
\
"setting (lexer = %s)."
,
self
.
default_lexer
[
0
])
name
=
self
.
default_lexer
[
0
]
else
:
self
.
default_lexer
=
(
name
,
lexer
)
else
:
self
.
default_lexer
=
(
name
,
lexer
)
self
.
default_lexer
=
self
.
PLUGIN_INTERNAL_NONE_LEXER
self
.
config
[
'default_lexer'
]
=
name
...
...
syntax_highlight/plugin_config_dialog.py
View file @
c21a78b7
...
...
@@ -136,9 +136,10 @@ class SyntaxHighlighterPluginConfiguration(GajimPluginConfigDialog):
code
=
start_iter
.
get_text
(
buf
.
get_end_iter
())
lexer
=
self
.
config
.
get_default_lexer
()
tokens
=
pygments
.
lex
(
code
,
lexer
)
if
not
self
.
config
.
is_internal_none_lexer
(
lexer
):
tokens
=
pygments
.
lex
(
code
,
lexer
)
pygments
.
format
(
tokens
,
formatter
,
buf
)
pygments
.
format
(
tokens
,
formatter
,
buf
)
buf
.
delete_mark
(
start_mark
)
...
...
syntax_highlight/syntax_highlight.py
View file @
c21a78b7
...
...
@@ -6,7 +6,8 @@ import importlib
from
gajim.plugins.helpers
import
log_calls
,
log
from
gajim.plugins
import
GajimPlugin
from
.types
import
MatchType
,
LineBreakOptions
,
CodeMarkerOptions
from
.types
import
MatchType
,
LineBreakOptions
,
CodeMarkerOptions
,
\
PLUGIN_INTERNAL_NONE_LEXER_ID
log
=
logging
.
getLogger
(
'gajim.plugin_system.syntax_highlight'
)
...
...
@@ -93,7 +94,7 @@ class SyntaxHighlighterPlugin(GajimPlugin):
self
.
ccontrol
=
{}
self
.
config_default_values
=
{
'default_lexer'
:
(
'python'
,
''
),
'default_lexer'
:
(
PLUGIN_INTERNAL_NONE_LEXER_ID
,
''
),
'line_break'
:
(
LineBreakOptions
.
MULTILINE
,
''
),
'style'
:
(
'default'
,
''
),
'font'
:
(
'Monospace 10'
,
''
),
...
...
syntax_highlight/types.py
View file @
c21a78b7
from
enum
import
Enum
,
IntEnum
,
unique
PLUGIN_INTERNAL_NONE_LEXER_ID
=
'_syntax_highlight_internal_none_type'
class
MatchType
(
Enum
):
INLINE
=
0
MULTILINE
=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment