Emacs 有没有办法让org babel正确地缩进noweb纠结的代码?

Emacs 有没有办法让org babel正确地缩进noweb纠结的代码?,emacs,formatting,org-mode,org-babel,noweb,Emacs,Formatting,Org Mode,Org Babel,Noweb,纠结于此: #+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.

纠结于此:

#+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
我已经启用了org src preserve indentation,但它无法保存不存在的内容。如果代码编辑窗口看不到以前源代码块中的部分,则无法正确设置它。最后,我不想在每次启动新的源代码块时都必须遍历前面的所有代码片段来确定缩进应该开始什么

当前的破解方法是把源代码弄得乱七八糟,在新的缓冲区中打开乱七八糟的文件,选择all并运行c-indent-line-or-region,但我希望还有比这更好的方法


组织模式版本:8.2.5h

如前所述,挂入
组织babel post tangle钩子
是一种方法。我使用以下方法:

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

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

我认为,您可以调用
indent region
或类似于post-tangle钩子。
(defun tnez/src-cleanup ()
  (indent-region (point-min) (point-max)))

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