有什么方法可以让org-babel正确缩进现在纠结的代码吗?



纠结这个:

#+BEGIN_SRC C :tangle no :noweb-ref begin
int main() {
  printf("Line 1n");
#+END_SRC
#+BEGIN_SRC C :tangle no :noweb-ref middle
printf("Secondn");
#+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 1n");
printf("Secondn");
}

我有org-src-preserve-indentation打开,但它不能保存不存在的东西。如果代码编辑窗口看不到前一个源代码块中的部分,则无法正确设置它。最后,我不想每次开始一个新的源代码块时,都要遍历前面所有的代码片段来弄清楚缩进应该从哪里开始。

当前的破解方法是纠缠源代码,在新的缓冲区中打开纠缠文件,选择所有并运行c-indent-line-or-region,但我希望有比这更好的方法。

组织模式版本:8.2.5h

如前所述,连接到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)

最新更新