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

标签 python indentation word-wrap jupyter-lab

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/

相关文章:

python - 用表中的单个 unicode 替换字母数字子字符串

formatting - 同时在多行中添加空格 - 在 Pycharm 中

word-wrap - WebStorm 可以设置自动换行吗?我需要默认设置所有文件都应该自动换行

python - 使用 Xpath 选择所有 dd 标签,直到新的 dl 标签

python - 在python中导入C dll函数

python - 迭代时从列表中删除

eclipse - 使用 Eclipse 将空格替换为制表符

vim - 如何在 Vim 中将文本换行到一定长度?

Android TextView SingleLine 字段隐藏长文本

css - 移动设备上的 Bootstrap Wordwrap 问题