在emacs中混合组织模式和c模式

Kon*_*ele 7 emacs org-mode c-mode

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

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

func1()
{
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用nXhtml多主模式,我猜其他模式也支持多模式.我现在的问题是,如果我在"第2部分"上键入TAB,那么"第2部分"下方的所有部分都将折叠并变为不可见.但我想包含org-mode折叠/展开到评论部分的区域.TAB应该只折叠/展开直到"*/".

我想知道我怎么能做到这一点?

Kon*_*ele 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)))))))
Run Code Online (Sandbox Code Playgroud)

这个补丁必须用手涂抹,并不困难。*#它添加了将打破缩进的标记。@bzg 指出了M-x orgstruct-mode RET模式,归功于他。现在我可以在后台使用 orgstruct-mode 在 c.mode 中编写(不再需要多主要模式):

/*
Org-mode here
** Section 1
  text
** Section 2
  text
*#
Org-mode should end here
*/
Run Code Online (Sandbox Code Playgroud)

我将在注释中添加组织模式,第 1 部分和第 2 部分将折叠直到*#标记为止。