【问题标题】:Any way to make org-babel properly indent noweb tangled code?有什么方法可以使 org-babel 正确缩进 noweb 纠结的代码?
【发布时间】:2014-06-19 01:54:02
【问题描述】:

纠结这个:

#+BEGIN_SRC C :tangle no :noweb-ref begin
int main() {
  printf("Line 1\n");
#+END_SRC

#+BEGIN_SRC C :tangle no :noweb-ref middle
printf("Second\n");
#+END_SRC

#+BEGIN_SRC C :tangle no :noweb-ref end
}
#+END_SRC

#+BEGIN_SRC C :tangle ~/test.c :noweb no-export
<<begin>>
<<middle>>
<<end>>
#+END_SRC

产生这个:

int main() {
  printf("Line 1\n");
printf("Second\n");
}

我打开了 org-src-preserve-indentation,但它无法保留不存在的内容。如果代码编辑窗口看不到前面源代码块的部分,则无法正确设置。最后,我不想每次开始一个新的源代码块时都必须通过所有以前的 sn-ps 来确定缩进应该开始。

当前的 hack 是 tangle 源代码,在新缓冲区中打开 tangle 文件,全选并运行 c-indent-line-or-region,但我希望有更好的东西比那个。

组织模式版本:8.2.5h

【问题讨论】:

  • 我认为你可以调用indent-region 或类似的后缠钩。

标签: emacs formatting org-mode org-babel noweb


【解决方案1】:

如前所述,连接到org-babel-post-tangle-hook 是可行的方法。我使用以下内容:

(defun tnez/src-cleanup ()
  (indent-region (point-min) (point-max)))

(add-hook 'org-babel-post-tangle-hook 'tnez/src-cleanup)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 2012-12-07
    • 1970-01-01
    相关资源
    最近更新 更多