在Emacs中混合使用org-mode和c-mode

8

我想在Emacs中混合使用org-modec-mode。所有在注释中的内容应该是org-mode,其余部分应该是默认的主要模式c-mode

/*
Org-mode here
** Section 1
  text
** Section 2
  text
Org-mode should end here
*/

func1()
{
}

我尝试使用nXhtml多主模式,我猜还有其他模式支持多模式。我的问题是,如果我在“section 2”上按TAB键,那么所有在“Section 2”下方的内容都将被折叠并隐藏。但是我希望包含org-mode折叠/展开到注释部分的区域。TAB键应只折叠/展开到“*/”。 我想知道如何实现这一点?

1
你可以使用 babel - jfs
1
不完全是我想要的:整个文件应保持为常规c文件。我希望在c注释中使用org-mode功能。 - Konrad Eisele
2个回答

3

You can try M-x orgstruct-mode RET.


谢谢你的建议。我通过修补org-mode并使用你的orgstruct-mode而不是多重major-mode得到了解决方案,它运行得非常好。我已经发布了答案。 - Konrad Eisele

3
我找到了一个解决方案: http://lists.gnu.org/archive/html/emacs-orgmode/2011-01/msg00036.html 上列出了一个适用于org-mode的补丁。
--- emacs-23.2/lisp/org/org.el  2010-04-04 00:26:08.000000000 +0200
+++ src/c51/mk/org.el   2011-01-02 20:26:10.266860827 +0100
@@ -5245,6 +5245,8 @@
 (defun org-cycle-internal-local ()
   "Do the local cycling action."
   (org-back-to-heading)
+  (cond 
+   ((not (looking-at (concat outline-regexp "\s*#" )))
   (let ((goal-column 0) eoh eol eos level has-children children-skipped)
     ;; First, some boundaries
     (save-excursion
@@ -5318,7 +5320,7 @@
       (hide-subtree)
       (message "FOLDED")
       (setq org-cycle-subtree-status 'folded)
-      (run-hook-with-args 'org-cycle-hook 'folded)))))
+      (run-hook-with-args 'org-cycle-hook 'folded)))))))

 ;;;###autoload
 (defun org-global-cycle (&optional arg)
--- emacs-23.2/lisp/outline.el  2010-04-04 00:26:04.000000000 +0200
+++ src/c51/mk/outline.el   2011-01-02 20:35:17.303609833 +0100
@@ -913,8 +913,15 @@
       ;; Then unhide the top level headers.
       (outline-map-region
        (lambda ()
-    (if (<= (funcall outline-level) levels)
-        (outline-show-heading)))
+    (if (<= (funcall outline-level) level)
+          (if (looking-at (concat outline-regexp "\s*#" ))
+          (progn
+            (outline-show-heading )
+            (show-entry ))
+        (outline-show-heading))))
+;;       (lambda ()
+;;  (if (<= (funcall outline-level) levels)
+;;      (outline-show-heading)))
        beg end)))
   (run-hooks 'outline-view-change-hook))

@@ -994,7 +1001,11 @@
       (outline-map-region
        (lambda ()
     (if (<= (funcall outline-level) level)
-        (outline-show-heading)))
+          (if (looking-at (concat outline-regexp "\s*#" ))
+          (progn
+            (outline-show-heading )
+            (show-entry ))
+          (outline-show-heading))))
        (point)
        (progn (outline-end-of-subtree)
          (if (eobp) (point-max) (1+ (point)))))))

这个补丁需要手动应用,但并不难。它添加了标记*#来打破缩进。@bzg指出了M-x orgstruct-mode RET模式,感谢他。现在我可以在后台使用orgstruct-mode写C代码,无需再使用多个major mode:

/*
Org-mode here
** Section 1
  text
** Section 2
  text
*#
Org-mode should end here
*/

我会在评论中使用org-mode,Section 1和Section 2将折叠,直到*#标记。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接