gpt4 book ai didi

python - jupyter lab 中的缩进自动换行是否可行?

转载 作者:行者123 更新时间:2023-12-05 08:07:10 24 4
gpt4 key购买 nike

Jupyterlab 正在像这样进行软包装(使用设置 "lineWrap": "on"):

wrong

但我更喜欢这样的东西,就像我在所有其他文本编辑器(emacs、intellij、vim...)中都有它一样:

right

这可能吗? :)

最佳答案

JupyterLab 正在使用 CodeMirror,并且有一个用于缩进软包装行的 hack,发表于 https://codemirror.net/demo/indentwrap.html .

该页面的代码:

  var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
mode: "text/html"
});
var charWidth = editor.defaultCharWidth(), basePadding = 4;
editor.on("renderLine", function(cm, line, elt) {
var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;
elt.style.textIndent = "-" + off + "px";
elt.style.paddingLeft = (basePadding + off) + "px";
});
editor.refresh();

这只是第一步,我不知道如何在 JupyterLab 中应用该技巧(因为 CodeMirror 在该环境中不是全局变量)。我希望有人能够在此基础上进行构建...

关于python - jupyter lab 中的缩进自动换行是否可行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56969431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com