emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Piotr Zielinski" <piotr.zielinski@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Autocollapse of outline nodes
Date: Mon, 24 Apr 2006 13:15:03 +0100	[thread overview]
Message-ID: <3c12eb8d0604240515l3313b552o2ba25db2e7012f97@mail.gmail.com> (raw)

Hi,

Here's a small piece of code that periodically collapses all org nodes
(trees) which are far away (structurally) from the current cursor
position.  The purpose is to automatically collapse nodes which you
are no longer working on, thereby preventing uncontrolled growth of
the visible size of your .org buffer as the day progresses.

Please send your comments/suggestions, for example, whether this
functionality has already been implemented elsewhere.  Should work
with any outline buffer.

Piotr

;---------------------------
(defun local-fold-from-level (beg end level)
  (hide-region-body beg end)
  (goto-char beg)
  (unless (looking-at outline-regexp)
    (outline-next-visible-heading 1))
  (while (and (<= (point) end) (not (eobp)))
    (when (> (outline-level) level)
      (hide-subtree))
    (outline-next-visible-heading 1)))

(defun local-auto-fold ()
  (save-excursion
    (let ((point (point)))
      (beginning-of-buffer)
      (unless (looking-at outline-regexp)
	(outline-next-visible-heading 1))
      (while (not (eobp))
	(let ((end (save-excursion (outline-end-of-subtree) (point))))
	  (if (or (< end point) (> (point) point))
	      (local-fold-from-level (point) end (outline-level))
	    (outline-next-visible-heading 1)))))))
	
(defun local-auto-fold-all ()
  (save-excursion
    (dolist (buffer (buffer-list))
      (set-buffer buffer)
      (when (eq major-mode 'org-mode)
	(local-auto-fold)))))
		
(run-with-idle-timer 60 t 'local-auto-fold-all)
;--------------------

             reply	other threads:[~2006-04-24 12:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-24 12:15 Piotr Zielinski [this message]
2006-04-24 16:08 ` Autocollapse of outline nodes Xavier Maillard
2006-04-26  9:20 ` Carsten Dominik
2006-04-26 12:44   ` Piotr Zielinski
2006-05-12  1:26   ` Piotr Zielinski
2006-05-12  4:35     ` Carsten Dominik

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=3c12eb8d0604240515l3313b552o2ba25db2e7012f97@mail.gmail.com \
    --to=piotr.zielinski@gmail.com \
    --cc=emacs-orgmode@gnu.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).