emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Zeller <michael.dylan.zeller@gmail.com>
To: Scot Becker <scot.becker@gmail.com>
Cc: Org-mode ml <emacs-orgmode@gnu.org>
Subject: Re: org-style folding for a .emacs
Date: Mon, 13 Jul 2009 16:07:52 -0700	[thread overview]
Message-ID: <87bpnonpvb.fsf@zeller.michaelzeller.com> (raw)
In-Reply-To: <e0e1fe620907131423v5ac3b416u1c1ee37f6c0a9cdf@mail.gmail.com> (Scot Becker's message of "Mon, 13 Jul 2009 22:23:51 +0100")

Scot,

I've found a similar solution in a previous thread:
http://thread.gmane.org/gmane.emacs.orgmode/12094/focus=12105

In summary, add the following to your ~/.emacs.el:

  ;; outline-minor-mode
(defun prompt-for-outline-regexp (new-regexp)
  "ask the user for a local value of outline-regexp in this buffer"
  (interactive "Outline regexp: ")
  (set (make-local-variable 'outline-regexp) new-regexp)
)

(global-set-key (kbd "<f9>") 'prompt-for-outline-regexp) 

(defun th-outline-regexp ()
 "Calculate the outline regexp for the current mode."
 (let ((comment-starter (replace-regexp-in-string
                         "[[:space:]]+" "" comment-start)))
   (when (string= comment-start ";")
     (setq comment-starter ";;"))
   (concat "^" comment-starter "\\*+")))

(defun th-outline-minor-mode-init ()
 (interactive)
 (setq outline-regexp (th-outline-regexp)))

(add-hook 'outline-minor-mode-hook
          'th-outline-minor-mode-init)

(global-set-key [M-tab] 'org-cycle)
(global-set-key [M-left] 'hide-body)
(global-set-key [M-right] 'show-all)
(global-set-key [M-up] 'outline-previous-heading)
(global-set-key [M-down] 'outline-next-heading)
(global-set-key [C-M-left] 'hide-sublevels)
(global-set-key [C-M-right] 'show-children)
(global-set-key [C-M-up] 'outline-previous-visible-heading)
(global-set-key [C-M-down] 'outline-next-visible-heading)

and add the following as the top line of your ~/.emacs.el:

; -*- mode: emacs-lisp; mode: outline-minor; -*-

Now you can add ;;* and ;;**, etc as headings in your .emacs.el and
cycle using M-tab, M-left and M-right will collapse or expand all
headings respectively. I am guessing you mean to make segments such as
;;* SHORTCUTS and ;;* VARIABLES, this will do that, but not too much
more.

I haven't tried hideshow before, but this solution has worked for me in
other modes, particularly in R-mode, where you use #*, #**, etc,
instead. Just remember to activate outline-minor-mode.

Thanks go to Tassilo Horn,
~Michael Zeller

Scot Becker <scot.becker@gmail.com> writes:

> Does anyone have a recipe for easy org-style folding of an elisp file?
>  I'd like to divide my .emacs into segments to make it easier to
> oversee and navigate.
>
> Scot
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  parent reply	other threads:[~2009-07-13 23:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-13 21:23 org-style folding for a .emacs Scot Becker
2009-07-13 22:56 ` Eric S Fraga
2009-07-13 23:07 ` Michael Zeller [this message]
2009-07-14 11:55   ` Sébastien Vauban
2009-07-15  3:12     ` Michael Zeller
2009-07-15 15:52       ` Sébastien Vauban
2009-07-13 23:26 ` Dan Davison
2009-07-14 11:01   ` Scot Becker
2009-07-15  5:17     ` Eric Schulte
2009-07-15 21:02       ` Sébastien Vauban
2009-07-16 23:31         ` Eric Schulte
2009-07-28 14:39           ` Sébastien Vauban
2009-07-30  0:51             ` Eric Schulte
2009-07-16  1:02 ` Daniel Clemente
2009-07-16 19:50 ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bpnonpvb.fsf@zeller.michaelzeller.com \
    --to=michael.dylan.zeller@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=scot.becker@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).