【问题标题】:Is there a way to disable indentation for one specific org-mode src block at a time?有没有办法一次禁用一个特定组织模式 src 块的缩进?
【发布时间】:2023-02-19 17:06:35
【问题描述】:

我正在使用 spacemacs 开发分支随附的 org-mode 的大部分标准功能,但我无法找到一种方法来根据具体情况禁用源代码块的自动缩进。例如,我使用 tangle 并在编写 groovy 代码或 javascript 的同一个文件中编写 DockerfileDockerfile 是我唯一不想缩进的,这样我就可以突出显示语法。这是没有缩进的样子:

下面是当我编辑文本时自动出现的缩进的样子:

例如,自动缩进适用于 groovy,因此我对此处的自动缩进没有任何问题。 (事实上​​ ,如果我仍然得到 Dockerfile 的语法高亮显示,我可能不会介意太多,除了不尊重背景的奇怪的换行)。这是 groovy 的示例:

如您所见,我尝试了在 org-mode docs 中找到的 :noindent 属性,该属性通常位于 #+STARTUP 指令中。我还搜索了 stack overflow,但我没有发现任何没有禁用所有源块或整个文件的缩进的成果。

【问题讨论】:

    标签: emacs indentation org-mode spacemacs


    【解决方案1】:

    在我的实践中(我不确定这是一个好的做法,只是分享给你):

    • 我将 org-src-tab-acts-natively 设置为 true 以使用该语言的主模式缩进。在您的情况下,它将使用 dockerfile-mode 的格式规则来格式化 src 块。
    • 我为不应自动缩进的内容创建了一个新的主模式plain-mode。就个人而言,我将此模式用于以下情况:
      • 外壳输出
      • ASCII 图表
      • ...
    ;; the example code of plain-mode
    (define-derived-mode plain-mode
      clean-mode "Plain"
      "Major mode for plaintext."
      ;; preserve the auto indentation on line
      (setq-local indent-line-function 'indent-relative)
      ;; disable auto indentation on region
      (setq-local indent-region-function (lambda (start end))))
    
    

    这样,当我格式化它们时,src 块将始终按预期运行。

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 1970-01-01
      • 2013-03-16
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 2022-12-20
      • 1970-01-01
      • 2020-12-21
      相关资源
      最近更新 更多