2

纠结这个:

#+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,但它无法保留不存在的内容。如果代码编辑窗口看不到前面源代码块中的部分,则无法正确设置。最后,我不想在每次开始一个新的源代码块时都通过所有之前的代码片段来确定缩进应该从什么开始。

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

组织模式版本:8.2.5h

4

1 回答 1

2

如前所述,挂钩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)
于 2016-02-24T21:44:36.487 回答