emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Autocollapse of outline nodes
@ 2006-04-24 12:15 Piotr Zielinski
  2006-04-24 16:08 ` Xavier Maillard
  2006-04-26  9:20 ` Carsten Dominik
  0 siblings, 2 replies; 6+ messages in thread
From: Piotr Zielinski @ 2006-04-24 12:15 UTC (permalink / raw)
  To: emacs-orgmode

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)
;--------------------

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-12  4:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-24 12:15 Autocollapse of outline nodes Piotr Zielinski
2006-04-24 16:08 ` 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

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).