首页 > 解决方案 > jupyter lab 中的缩进自动换行可能吗?

问题描述

Jupyterlab 正在做这样的软包装(使用设置"lineWrap": "on"):

错误的

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

正确的

这可能吗?:)

标签: pythonindentationword-wrapjupyter-lab

解决方案


JupyterLab is using CodeMirror and there is a hack for indentation of soft-wrap lines, published on https://codemirror.net/demo/indentwrap.html.

Code from that page:

  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();

It's just a first step and I have no idea how to apply that hack inside JupyterLab (since CodeMirror is not a global variable in that environment). I hope someone will be able to build on top of this...


推荐阅读