To manage my config I use org-mode. To manage packages inside this I use use-package. Problem is that there are packages that require a lot of configuration like ibuffer and org-mode. Now I'm looking for a way to fold code inside an org-mode elisp source code block. The blocks should be folded based on headlines.

Below is a a workaround solution to archieve that goal above indirectly. The problem with that is that it creates even more source code blocks which is ugly overhead. I tried to use orgstruct++ (which is the more or less exactly the solution I need) inside the elisp block but that does not seem to work either. I get an error, and I presume that orgstruct++ was not intended for use on org-files. Is my goal impossible to achieve?

What I tried inside the elisp source code block

    ;;; -*- orgstruct-heading-prefix-regexp: ";;" -*-
;; Does this and that
;; Does that and this

Workaround example:

*** TLDR - Too Long Didn't Read cheat.sh offline Repository run tldr-update-docs before first run, wait for the download/decompression
**** Use-Package Opening
#+BEGIN_SRC emacs-lisp  
 (use-package tldr
**** Misc Configuration
#+BEGIN_SRC emacs-lisp
(tldr tldr-mode tldr-update-docs my-tldr-only-linux my-tldr-only-osx my-tldr-only-common+linux)
(setq tldr-enabled-categories '("common" "linux" "osx"))
**** Custom Functions
***** Filter TLDR
#+BEGIN_SRC emacs-lisp
    (defun my-tldr-only-osx ()
    (let ((tldr-enabled-categories '("osx")))
      (tldr)))   (defun my-tldr-only-linux ()
    (let ((tldr-enabled-categories '("linux")))
      (tldr)))   (defun my-tldr-only-common+linux ()
    (let ((tldr-enabled-categories '("common" "linux")))
**** Use-Package Closing
#+BEGIN_SRC emacs-lisp
  • To clarify the question, could you explain why you need the Elisp to be within an Org-mode structure? – Stefan Mar 19 '18 at 0:56
  • To harness all the features of org mode for my init file. Org-Mode configs are not that rare. Many people use it. Nice export features, easy to restructure large config parts and great visibility to name just a few. Org-babel reads all the elisp chunks in configuration.org and creates configuration.el. Disadvantage is slower startup but everything comes with a price. – Jens Lange Mar 19 '18 at 21:36

Long before org-mode existed, Emacs had outline-minor-mode which can be used in Elisp buffers, where the convention is to use ;;; to separate major sections, ;;;; for subsection, ;;;;; for subsubsections, .... you get the idea.

;;; .emacs --- My Emacs config file -*- mode: emacs-lisp; mode: outline-minor -*-
;;; Org settings
(bla org bla)
;;; IBuffer settings
(bla ibuffer bla)
;;;; Subfeature settings
(bla ibuffer subfeature bla)

I personally use outline-minor-mode in all Elisp files (so I don't need to -*- ...-*- at the top) and I use a hook to fold everything when visiting such a file, and then use reveal-mode to unfold-as-I-navigate:

(defun sm-outline-minor-mode-hook ()
  (when outline-minor-mode
    (hide-sublevels (if (eq outline-level 'lisp-outline-level) 1000 1))))
(add-hook 'outline-minor-mode-hook 'sm-outline-minor-mode-hook)
  • Well, I would like to stay at org-mode. Your solution implies to "translate" the configuration file to the outline-minor-mode scheme, doesn't it? Or is there a way to use the solution above inside an org-mode elisp code block? I tried but how do I collapse a ;;; subsection? Maybe all puzzle pieces are there but currently I can't make a picture of it. Could outshine possibly help? But it seems to be geared for use in non-org files. – Jens Lange Mar 18 '18 at 17:07

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.