3

I know that outline mode works like this in Emacs org mode

* Heading 1  
** Heading 2    

Is it possible to configure Emacs to take a different identifier than the *to identify headings?
I have a few files where I want to use a particular character (or character combination) where I have certain character combinations like C %% MODULE which mark the beginning of every module within the program.

So If I have a mechanism to use the C %% MODULE instead of * I do not have to add additional headings to enable the folding mechanism within my program.

Which file would I have to modify to have this functionality changed?

Just to provide more clarity, my code looks as shown below
enter image description here I have developed this in org mode. When I paste this into my system, I will have to manually delete the preceeding * and paste it.
But I was looking for a cleaner solution and if possible I could customize org-mode further to meet my requirements.

  • I'm confused about whether this is actually an org-mode question. Headings aside, are these files using org-mode syntax? Or do you just want to be able to use folding in some non-org files? – phils Aug 10 '16 at 11:42
  • @Prasanna Can you please talk about the goal you want to achieve by doing that? – Kaushal Modi Aug 10 '16 at 12:01
  • 1
    @Prasanna Have a look at outshine package. I use that for same kind of 'module' navigation, folding, etc in non-org code files. Here's an example. The difference in this example is that ;;;, ;;;;, .. are used as 'module' delimiters. You can configure outshine to match the delimiters you want. – Kaushal Modi Aug 10 '16 at 13:13
  • 4
    It sounds like you're talking about outline-mode rather than org-mode, which is built on top of outline-mode. If so, the least intensive option is probably to modify outline-regexp and friends. – Dan Aug 10 '16 at 13:16
  • 1
    Have a look also at the hide-show library to create your own regexp for folding modules: emacswiki.org/emacs/HideShow – lawlist Aug 10 '16 at 14:28
2

This doesn't seem to be possible in org-mode, but if you need just the folding feature, you may use outline-mode instead of org-mode, where you can change the value of outline-regexp.

(setq outline-regexp "C %% ")

Folding/unfolding are much less intuitive in outline-mode but you can add org-mode visibility cycling to outline mode with:

(add-hook 'outline-mode-hook
  (lambda () 
     (define-key outline-mode-map [(tab)] 'org-cycle)
     (define-key outline-mode-map [(shift tab)] 'org-global-cycle)))
  • The org mode visibility cycling hook doesn't seem to work. What could be wrong?. Pushing the TAB key just moves the text by 4 spaces :-( – Prasanna Aug 19 '16 at 19:18
  • @Prasanna Have you enabled outline-mode? What is TAB bound to (C-h k TAB)? – JeanPierre Aug 19 '16 at 19:24
  • I have enabled the outline-mode (major mode). I do not know how to find the key-binding yet. I will find out and update you. I will also try the key binding in your comment to see if it works – Prasanna Aug 20 '16 at 4:07
  • @Prasanna C-h k (describe-key) is the command to find what function a key is bound to. – JeanPierre Aug 21 '16 at 19:18
1

You can use org-bullets

https://github.com/sabof/org-bullets

 (require 'org-bullets)
 (setq org-bullets-bullet-list '("☯" "○" "✸" "✿" "~"))
 (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
  • That just changes the display, right? – phils Aug 10 '16 at 11:38
  • 1
    @phils I think that's the best bet? Because I think that actual changes to the file will break all kinds of regexps for headline matching. – Kaushal Modi Aug 10 '16 at 12:00
  • As far as I can tell, the files in question already use a different syntax. The question is a little confusing, though. – phils Aug 10 '16 at 12:51
  • I already use the expression shown above, in my .emacs file. This is not what I want. I want to use C %% MODULE to mark the line as a heading one. I do not need levels too. Just even one level is good. – Prasanna Aug 10 '16 at 13:06
0

In outline-minor-mode, to get <tab> and S-<tab> to act a bit more like org-mode:

(add-hook 'outline-minor-mode-hook
      (lambda ()
        (define-key outline-minor-mode-map (kbd "<tab>") 'outline-cycle)
        (define-key outline-minor-mode-map (kbd "S-<iso-lefttab>")
          '(lambda ()
             (interactive)
             (save-excursion
               (goto-char (point-min))
               (outline-show-all)
               (outline-hide-leaves))))))
  • How is this related to the question? – DoMiNeLa10 Dec 16 '18 at 13:21
  • The user shares his outline-mode hook for code folding, this is as addition to the discussion in the comments. Perhaps it will be more complete if the other links and examples referred to in the comments be added as an edit to this answer. – manandearth Dec 16 '18 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.