emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Emacs-orgmode] Autocollapse of outline nodes


From: Piotr Zielinski
Subject: Re: [Emacs-orgmode] Autocollapse of outline nodes
Date: Fri, 12 May 2006 03:26:48 +0200

Below is a version of autocollapse that works correctly even if
several windows show the same buffer.  It periodically collapses
outline nodes that are far from the current point position [1].

Piotr

[1] http://zerotau.blogspot.com/2006/04/autocollapse-mode-for-emacs.html

(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-contains-point (beg end pointlist)
 (let ((result))
   (dolist (point pointlist result)
     (setq result (or result (and (>= point beg) (<= point end)))))))

(defun local-auto-fold ()
 (save-excursion
   (let ((pointlist (mapcar 'window-point
                             (get-buffer-window-list (current-buffer) nil t))))
     (message "fold: %S: %S" (current-buffer) pointlist)
     (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 (local-contains-point (point) end pointlist)
              (outline-next-visible-heading 1)
            (local-fold-from-level (point) end (outline-level))))))))
        
(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]