emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-orgmode] Autocollapse of outline nodes


From: Piotr Zielinski
Subject: [Emacs-orgmode] Autocollapse of outline nodes
Date: Mon, 24 Apr 2006 13:15:03 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]