Skip to content

Commit

Permalink
highlight ! commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Jul 4, 2020
1 parent 023bbf7 commit a1d4834
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spyder/plugins/ipythonconsole/widgets/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
from IPython.core.inputtransformer2 import TransformerManager
else:
from IPython.core.inputsplitter import IPythonInputSplitter
from IPython.lib.lexers import IPythonLexer, IPython3Lexer
from pygments.lexer import bygroups
from pygments.token import Keyword, Operator, Text
from pygments.util import ClassNotFound


class SpyderIPy3Lexer(IPython3Lexer):
# Detect !cmd command and highlight them
tokens = IPython3Lexer.tokens
tokens['root'].insert(0,
(r'(!)(\w+)(.*\n)', bygroups(Operator, Keyword, Text))
)


class SpyderIPy2Lexer(IPythonLexer):
tokens = IPython3Lexer.tokens
tokens['root'].insert(0,
(r'(!)(\w+)(.*\n)', bygroups(Operator, Keyword, Text))
)


class DebuggingWidget(DebuggingHistoryWidget):
Expand Down Expand Up @@ -206,6 +225,23 @@ def reset(self, clear=False):
password=password)

# --- Private API --------------------------------------------------
def _handle_kernel_info_reply(self, rep):
"""Handle kernel info replies."""
super(DebuggingWidget, self)._handle_kernel_info_reply(rep)
pygments_lexer = rep['content']['language_info'].get(
'pygments_lexer', '')
try:
# add custom lexer
if pygments_lexer == 'ipython3':
lexer = SpyderIPy3Lexer()
elif pygments_lexer == 'ipython2':
lexer = SpyderIPy2Lexer()
else:
return
self._highlighter._lexer = lexer
except ClassNotFound:
pass

def _redefine_complete_for_dbg(self, client):
"""Redefine kernel client's complete method to work while debugging."""

Expand Down

0 comments on commit a1d4834

Please sign in to comment.