Mix org-mode and c-mode in emacs

I want to add org-mode and c-mode to Emacs. Everything inside the comment should be org-mode, the rest should be the default in main mode C-mode:

/* Org-mode here ** Section 1 text ** Section 2 text Org-mode should end here */ func1() { } 

I tried using nXhtml multi-major-mode, I think there are other modes that also support multi-modes. My problem is that if I type TAB on "section 2", then everything below "Section 2" will be minimized and made invisible. But I would like to contain an area that org-mode is folding / expanding into the comments section. TAB should only fold / unfold to "* /".

I wonder how can I achieve this?

+6
source share
2 answers

I found a solution: http://lists.gnu.org/archive/html/emacs-orgmode/2011-01/msg00036.html lists the patch for 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))))))) 

This patch should be applied manually, but it is not so difficult. It adds a *# marker, which will destroy the indent. @bzg pointed out the Mx orgstruct-mode RET , credits it. Now I can write in c.mode using orgstruct-mode in the background (multicurrency mode is no longer required):

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

And I will have org mode in the comments, section 1 and section 2 will add up to the mark *# .

+2
source

You can try Mx orgstruct-mode RET .

+3
source

Source: https://habr.com/ru/post/916914/


All Articles