##// END OF EJS Templates
Initial implementation of latex->unicode completer.
Brian E. Granger -
Show More
@@ -79,12 +79,13 b' import sys'
79 from IPython.config.configurable import Configurable
79 from IPython.config.configurable import Configurable
80 from IPython.core.error import TryNext
80 from IPython.core.error import TryNext
81 from IPython.core.inputsplitter import ESC_MAGIC
81 from IPython.core.inputsplitter import ESC_MAGIC
82 from IPython.core.latex_symbols import latex_symbols
82 from IPython.utils import generics
83 from IPython.utils import generics
83 from IPython.utils import io
84 from IPython.utils import io
84 from IPython.utils.decorators import undoc
85 from IPython.utils.decorators import undoc
85 from IPython.utils.dir2 import dir2
86 from IPython.utils.dir2 import dir2
86 from IPython.utils.process import arg_split
87 from IPython.utils.process import arg_split
87 from IPython.utils.py3compat import builtin_mod, string_types
88 from IPython.utils.py3compat import builtin_mod, string_types, PY3
88 from IPython.utils.traitlets import CBool, Enum
89 from IPython.utils.traitlets import CBool, Enum
89
90
90 #-----------------------------------------------------------------------------
91 #-----------------------------------------------------------------------------
@@ -601,7 +602,6 b' class IPCompleter(Completer):'
601 self.magic_matches,
602 self.magic_matches,
602 self.python_func_kw_matches,
603 self.python_func_kw_matches,
603 self.dict_key_matches,
604 self.dict_key_matches,
604 self.latex_matches
605 ]
605 ]
606
606
607 def all_completions(self, text):
607 def all_completions(self, text):
@@ -970,10 +970,12 b' class IPCompleter(Completer):'
970 return [leading + k + suf for k in matches]
970 return [leading + k + suf for k in matches]
971
971
972 def latex_matches(self, text):
972 def latex_matches(self, text):
973 if text.startswith('\\foo'):
973 slashpos = text.rfind('\\')
974 return ['foo']
974 if slashpos > -1:
975 else:
975 s = text[slashpos:]
976 return []
976 if s in latex_symbols:
977 return s, [latex_symbols[s]]
978 return u'', []
977
979
978 def dispatch_custom_completer(self, text):
980 def dispatch_custom_completer(self, text):
979 #io.rprint("Custom! '%s' %s" % (text, self.custom_completers)) # dbg
981 #io.rprint("Custom! '%s' %s" % (text, self.custom_completers)) # dbg
@@ -1048,13 +1050,18 b' class IPCompleter(Completer):'
1048 matches : list
1050 matches : list
1049 A list of completion matches.
1051 A list of completion matches.
1050 """
1052 """
1051 io.rprint('\nCOMP1 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
1053 # io.rprint('\nCOMP1 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
1052
1054
1053 # if the cursor position isn't given, the only sane assumption we can
1055 # if the cursor position isn't given, the only sane assumption we can
1054 # make is that it's at the end of the line (the common case)
1056 # make is that it's at the end of the line (the common case)
1055 if cursor_pos is None:
1057 if cursor_pos is None:
1056 cursor_pos = len(line_buffer) if text is None else len(text)
1058 cursor_pos = len(line_buffer) if text is None else len(text)
1057
1059
1060 latex_text = text if not line_buffer else line_buffer[:cursor_pos]
1061 latex_text, latex_matches = self.latex_matches(latex_text)
1062 if latex_matches:
1063 return latex_text, latex_matches
1064
1058 # if text is either None or an empty string, rely on the line buffer
1065 # if text is either None or an empty string, rely on the line buffer
1059 if not text:
1066 if not text:
1060 text = self.splitter.split_line(line_buffer, cursor_pos)
1067 text = self.splitter.split_line(line_buffer, cursor_pos)
@@ -1065,7 +1072,7 b' class IPCompleter(Completer):'
1065
1072
1066 self.line_buffer = line_buffer
1073 self.line_buffer = line_buffer
1067 self.text_until_cursor = self.line_buffer[:cursor_pos]
1074 self.text_until_cursor = self.line_buffer[:cursor_pos]
1068 io.rprint('COMP2 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
1075 # io.rprint('COMP2 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
1069
1076
1070 # Start with a clean slate of completions
1077 # Start with a clean slate of completions
1071 self.matches[:] = []
1078 self.matches[:] = []
General Comments 0
You need to be logged in to leave comments. Login now