From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Piotr Zielinski" Subject: Autocollapse of outline nodes Date: Mon, 24 Apr 2006 13:15:03 +0100 Message-ID: <3c12eb8d0604240515l3313b552o2ba25db2e7012f97@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FXzy6-0000La-OI for emacs-orgmode@gnu.org; Mon, 24 Apr 2006 08:15:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FXzy5-0000L9-8j for emacs-orgmode@gnu.org; Mon, 24 Apr 2006 08:15:06 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FXzy5-0000L5-60 for emacs-orgmode@gnu.org; Mon, 24 Apr 2006 08:15:05 -0400 Received: from [64.233.162.199] (helo=nz-out-0102.google.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FY00J-0006Xn-EG for emacs-orgmode@gnu.org; Mon, 24 Apr 2006 08:17:23 -0400 Received: by nz-out-0102.google.com with SMTP id 14so994304nzn for ; Mon, 24 Apr 2006 05:15:03 -0700 (PDT) Content-Disposition: inline List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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 (<=3D (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) =09(outline-next-visible-heading 1)) (while (not (eobp)) =09(let ((end (save-excursion (outline-end-of-subtree) (point)))) =09 (if (or (< end point) (> (point) point)) =09 (local-fold-from-level (point) end (outline-level)) =09 (outline-next-visible-heading 1))))))) =09 (defun local-auto-fold-all () (save-excursion (dolist (buffer (buffer-list)) (set-buffer buffer) (when (eq major-mode 'org-mode) =09(local-auto-fold))))) =09=09 (run-with-idle-timer 60 t 'local-auto-fold-all) ;--------------------