emacs - 有什么方法可以让 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.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

最佳答案

如前所述, Hook 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)

关于emacs - 有什么方法可以让 org-babel 正确缩进 noweb 纠结的代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24297597/

相关文章:

php - 使用PHP和HTML时,最佳做法是什么?

DataGridViewCellStyle 显示以千为单位的数值数据

html - 在 HTML 文本区域中格式化特殊文本

emacs - 我如何开始使用Emacs的文档?

emacs - Emacs 是否有允许插入一些文本的只读或查看模式?

emacs - 从组织模式导出到 HTML : how to include reference using bibtex

更改主题和添加一些插件时 Emacs 启动缓慢

emacs - 如何使用组织模式与其他作者合作?

unicode - 配置 org 模式以使用 LuaLaTeX

perl - 在 emacs 中调用(缓冲区文件名)时转义空格