* 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
* Re: Autocollapse of outline nodes
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
1 sibling, 0 replies; 6+ messages in thread
From: Xavier Maillard @ 2006-04-24 16:08 UTC (permalink / raw)
To: emacs-orgmode
On Monday 24 April 2006 14:15, Piotr Zielinski wrote:
> 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.
That's great !! Thank you.
Xavier
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Autocollapse of outline nodes
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
1 sibling, 2 replies; 6+ messages in thread
From: Carsten Dominik @ 2006-04-26 9:20 UTC (permalink / raw)
To: Piotr Zielinski; +Cc: emacs-orgmode
On Apr 24, 2006, at 14:15, Piotr Zielinski wrote:
> 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.
very interesting idea / piece of code.
One potential problem that I see is that (point) is a property of a
window. Only if a buffer is shown in one or zero windows, then (point)
is unique after a set-buffer operation for this buffer and you can use
it to select which part not to hide.
So what might happen is that you can have two or more windows on a
buffer (in the same frame, or even on different frames), each looking
at a different section of the outline tree. I often do this when
restructuring a file, while moving stuff from one place in a file to
another. Your code would keep closing some of the visible outlines,
because it only considers (point) in a single window (I don't even know
which one if would actually use in this case, an interesting problem).
To solve this, you would need to check if a buffer is displayed in
several places, make a list of (point) in all these places, and then
check is any of the listed values of point fall in the outline subtree
you are about to close.
Finally, you are running it on an idle timer with 60 seconds of idle
time required. I would be interesting how this works in pratice, and
if this is the best way to activate this code. For now, I have not
tried it extensively and I don't know.
- Carsten
--
Carsten Dominik
Sterrenkundig Instituut "Anton Pannekoek"
Universiteit van Amsterdam
Kruislaan 403
NL-1098SJ Amsterdam
phone: +31 20 525 7477
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Autocollapse of outline nodes
2006-04-26 9:20 ` Carsten Dominik
@ 2006-04-26 12:44 ` Piotr Zielinski
2006-05-12 1:26 ` Piotr Zielinski
1 sibling, 0 replies; 6+ messages in thread
From: Piotr Zielinski @ 2006-04-26 12:44 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
Carsten, thanks for your comments. I'll incorporate your suggestions
into the code as soon as I can.
Piotr
On 26/04/06, Carsten Dominik <carsten.dominik@gmail.com> wrote:
>
> On Apr 24, 2006, at 14:15, Piotr Zielinski wrote:
>
> > 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.
>
> very interesting idea / piece of code.
>
> One potential problem that I see is that (point) is a property of a
> window. Only if a buffer is shown in one or zero windows, then (point)
> is unique after a set-buffer operation for this buffer and you can use
> it to select which part not to hide.
>
> So what might happen is that you can have two or more windows on a
> buffer (in the same frame, or even on different frames), each looking
> at a different section of the outline tree. I often do this when
> restructuring a file, while moving stuff from one place in a file to
> another. Your code would keep closing some of the visible outlines,
> because it only considers (point) in a single window (I don't even know
> which one if would actually use in this case, an interesting problem).
> To solve this, you would need to check if a buffer is displayed in
> several places, make a list of (point) in all these places, and then
> check is any of the listed values of point fall in the outline subtree
> you are about to close.
>
> Finally, you are running it on an idle timer with 60 seconds of idle
> time required. I would be interesting how this works in pratice, and
> if this is the best way to activate this code. For now, I have not
> tried it extensively and I don't know.
>
> - Carsten
>
>
>
> --
> Carsten Dominik
> Sterrenkundig Instituut "Anton Pannekoek"
> Universiteit van Amsterdam
> Kruislaan 403
> NL-1098SJ Amsterdam
> phone: +31 20 525 7477
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Autocollapse of outline nodes
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
1 sibling, 1 reply; 6+ messages in thread
From: Piotr Zielinski @ 2006-05-12 1:26 UTC (permalink / raw)
To: Carsten Dominik; +Cc: emacs-orgmode
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)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Autocollapse of outline nodes
2006-05-12 1:26 ` Piotr Zielinski
@ 2006-05-12 4:35 ` Carsten Dominik
0 siblings, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2006-05-12 4:35 UTC (permalink / raw)
To: Piotr Zielinski; +Cc: emacs-orgmode
Great.
I did no know about get-buffer-window-list, this makes it a lot easier.
- Carsten
On May 12, 2006, at 3:26, Piotr Zielinski wrote:
> 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)
>
>
--
Carsten Dominik
Sterrenkundig Instituut "Anton Pannekoek"
Universiteit van Amsterdam
Kruislaan 403
NL-1098SJ Amsterdam
phone: +31 20 525 7477
^ 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).