emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sébastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
To: emacs-orgmode-mXXj517/zsQ@public.gmane.org
Subject: Re: org-style folding for a .emacs
Date: Wed, 15 Jul 2009 17:52:25 +0200	[thread overview]
Message-ID: <87zlb6vt8m.fsf@mundaneum.com> (raw)
In-Reply-To: 87iqhu63mw.fsf@zeller.michaelzeller.com

Hello Michael,

>>>> 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.
>>
>> I asked myself this question a couple of days ago. Telepathy. For real.
>> Good it has been asked, and answered.
>>
>>> In summary, add the following to your ~/.emacs.el:
>>>
>>> (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 "\\*+")))
>>>
>>> [...]
>>>
>>> (add-hook 'outline-minor-mode-hook
>>>           'th-outline-minor-mode-init)
>>>
>>> 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.
>>
>> Done. Though, is there a way to get the font used for org-levels in the
>> Emacs config file? That would really greatly improve the readability, then!
>
> Try changing th-outline-minor-mode-init to:
>
> (defun th-outline-minor-mode-init ()
>  (interactive)
>  (setq outline-regexp (th-outline-regexp))
>  ;; highlight the headings
>  ;; see http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
>  ;; use M-x customize-apropos face to customize faces
>  ;; to find the corresponding face for each outline level see org-faces.el
>  (let ((heading-1-regexp (concat (substring outline-regexp 0 -1) "\\{1\\} \\(.*\\)"))
>        (heading-2-regexp (concat (substring outline-regexp 0 -1) "\\{2\\} \\(.*\\)"))
>        (heading-3-regexp (concat (substring outline-regexp 0 -1) "\\{3,\\} \\(.*\\)")))
>    (font-lock-add-keywords
>     nil
>     `((,heading-1-regexp 1 font-lock-function-name-face t)
>       (,heading-2-regexp 1 font-lock-variable-name-face t)
>       (,heading-3-regexp 1 font-lock-keyword-face       t)))))
>
> That should atleast highlight the first three headings properly and make
> it more readable. I'm not quite sure how to make it cycle through the 8
> colors like org-mode does.

You know what?  You really are wonderful ;-)  This is making my month...

Though, I slightly adapted your code (that was in what's possible for me) so
that I get exactly the same faces as within a real Org file:

--8<---------------cut here---------------start------------->8---
(defun th-outline-minor-mode-init ()
  (interactive)
  (setq outline-regexp (th-outline-regexp))

  ;; highlight the headings
  ;; see http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html
  ;; use M-x customize-apropos face to customize faces
  ;; to find the corresponding face for each outline level see org-faces.el
  (let ((heading-1-regexp (concat (substring outline-regexp 0 -1) "\\{1\\} \\(.*\\)"))
        (heading-2-regexp (concat (substring outline-regexp 0 -1) "\\{2\\} \\(.*\\)"))
        (heading-3-regexp (concat (substring outline-regexp 0 -1) "\\{3\\} \\(.*\\)"))
        (heading-4-regexp (concat (substring outline-regexp 0 -1) "\\{4,\\} \\(.*\\)"))
        )
    (font-lock-add-keywords
     nil
     `((,heading-1-regexp 1 'org-level-1 t)
       (,heading-2-regexp 1 'org-level-2 t)
       (,heading-3-regexp 1 'org-level-3 t)
       (,heading-4-regexp 1 'org-level-4 t)))))
--8<---------------cut here---------------end--------------->8---

That way, having those faces defined (inspired by the resistors color code):

--8<---------------cut here---------------start------------->8---
(org-level-1 ((t (:foreground "cornflower blue" :weight bold :height 1.8 :family "Arial"))))
(org-level-2 ((t (:foreground "LimeGreen" :weight bold :height 1.6 :family "Arial"))))
(org-level-3 ((t (:foreground "orange" :weight bold :height 1.3 :family "Arial"))))
--8<---------------cut here---------------end--------------->8---

I get a much, much, much more readable emacs file -- nice, moreover as mine is
really huge!


> Hope that helps,

Oohhh yeeeessss!

Best regards,
  Seb

-- 
Sébastien Vauban



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2009-07-15 15:52 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
2009-07-14 11:55   ` Sébastien Vauban
2009-07-15  3:12     ` Michael Zeller
2009-07-15 15:52       ` Sébastien Vauban [this message]
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=87zlb6vt8m.fsf@mundaneum.com \
    --to=wxhgmqzgwmuf-genee64ty+gs+fvcfc7uqw@public.gmane.org \
    --cc=emacs-orgmode-mXXj517/zsQ@public.gmane.org \
    /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).