修改或挂钩Jupyter的标签完成 [英] Modify or hook into Jupyter's tab completion
问题描述
我想知道是否可以修改Jupyter Lab或Notebook的制表符完整功能.例如,如果我键入"\ alpha",然后按Tab键,则单元格中将显示UTF-8字符α".
I was wondering if there was a way to modify Jupyter Lab or Notebook's tab-complete functionality. For example, if I type "\alpha", and then press the tab key, I will get the UTF-8 character "α" in the cell.
有什么办法可以使自定义"[无空格的字符串]"制表符补全为某些特定的UTF-8字符或字符串?
Is there any way that I can do a custom "[string without spaces]" to tab-complete into some specific UTF-8 character or string?
例如"\ implies" +标签->⇒"
e.g. "\implies" + tab -> "⇒"
在我的编程生涯中,我可以看到很多用例,因此我想知道Jupyter(实验室或笔记本)是否提供了修改某些将字符串映射到选项卡式设置(或加载到文件中)的功能.输出.还是有一个不同的想法可以用来实现这一目标?
I can see a large number of use cases for this in my programming life, so I was wondering if Jupyter (Lab or Notebook) offered the ability to modify some settings (or load in a file) that maps strings to a tabbed output. Or is there a different idea that you could use to implement this?
谢谢!
推荐答案
Jupyter是基于IPython的,它是完成引擎-我们可以利用它.
Jupyter is (based on) IPython and it's completion engine - we can make use of it.
更新:您可以覆盖 latex_symbols
字典以获取所需的行为:
Update: you can override latex_symbols
dict to get the behavior you want:
from IPython.core.latex_symbols import latex_symbols
latex_symbols['\\implies'] = '⇒'
您应该能够在此示例的基础上使它适用于所有字符.
You should be able to build upon this example to make it work with a whole range of characters.
初始答案/另一种解决方案:您可以使用IPython补全功能,尽管它不能完全按您的意愿工作:它不会替换文本,而只是附加一个特殊字符.这是一个示例:
Initial answer/another solution: you can hook into IPython completers, though it would not work exactly as you wish: it won't replace the text, but just append a special character. Here is an example:
from IPython import get_ipython
def implies_competer(ipython, event):
return ['⇒']
ipython = get_ipython()
ipython.set_hook('complete_command', implies_competer, re_key='.*implies')
然后在您键入时(关键字后面的空格很重要):
Then when you type (the space after the keyword is important):
,然后按 tab
,您将获得:
这篇关于修改或挂钩Jupyter的标签完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!