Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

implemented thread folding in summary buffer

1 view
Skip to first unread message

Eric Schulte

unread,
Dec 19, 2007, 10:57:12 PM12/19/07
to

Hi,

I just finished a couple of simple functions which alter the VM
Summary view to fold/unfold threads of conversations. The benefit
being that it is possible to view a much larger swath of mail in a
smaller amount of space.

I figure I would post them here both in case anyone else may find them
useful, and also to solicit code feedback/suggestions. I'm new to
elisp.

Following this I would like to add some more options to the
vm-summary-format variable. Namely an option which would display the
number of "thread-children" an article has. The vm-thread code looked
somewhat intimidating so that might have to wait for a while.

Thanks,
Eric

not sure how to attach in gnus, so I'll just paste the file here
-------------------------vm-hide-threads.el-------------------------
;; vm-hide-threads.el -- Functions for hiding threads in VM Summary buffer
;;
;; Provides two functions for compact viewing of threads in VM
;; Summmary buffers. These functions are...
;;
;; collapse-all-threads: which collapses all threads
;;
;; toggle-current-thread: which toggles the visibility of the messages
;; in the current thread
;;
;; to use these functions include something similar to the following
;; in your vm load file
;;
;; ;; collapsable threads in VM summary buffers
;; (load "~/path/to/vm-hide-threads.el")
;; (add-hook 'vm-mode-hook
;; (lambda ()
;; (local-set-key (kbd "<tab>") 'toggle-current-thread)
;; (local-set-key "\M-t" 'collapse-all-threads)))
;;
;;
;; Copyright (c) 2007 Eric Schulte
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along
;; with this program; if not, write to the Free Software Foundation, Inc.,
;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
;;

;; show ellipses when hiding text
;; (info "(elisp)ellipsis")
(add-to-invisibility-spec '(hidden-thread . t))

(defun reveal-overlay (overlay)
;; needed to show text during isearch
;; (info "(elisp)isearch-open-invisible")
(overlay-put overlay 'invisible nil))

(defun toggle-current-thread ()
"toggle the current thread's visibility"
(interactive)
(unless (show-current-thread)
(collapse-current-thread))
(move-beginning-of-line 1))

(defun show-current-thread ()
"show the thread on the current line"
(interactive)
(move-end-of-line 1)
(backward-char)
(let ((all (overlays-at (point)))
(shown nil))
(mapcar
(lambda (ol)
;; this is able to reveal invisible overlays in the *scrath*
;; buffer, but it doesn't seem to work in the VM buffer. It
;; looks like the overlay is found, but it doesn't return true
;; for (overlay-get ol 'invisible) even though it is...
(if (overlay-get ol 'invisible)
(progn
(overlay-put ol 'invisible nil)
(setq shown t))))
all)
shown))

(defun collapse-current-thread ()
"collapse the thread on the current line"
(interactive)
(move-end-of-line 1)
(if (re-search-backward "[0-9] \"" nil t)
(progn
(move-end-of-line 1)
(setq start (point))
;; search for the end of the thread
(if (re-search-forward "[0-9] \"" nil t)
(progn
(previous-line)
(move-end-of-line 1)
(setq end (point)))
;; buffer ends on a thread
(progn
(end-of-buffer)
(setq end (point))))
(if (> (count-lines start end) 0)
(collapse-thread start end)))
nil))

(defun collapse-thread (start end)
"collapse a thread"
(interactive)
(add-to-invisibility-spec '(hidden-thread . t))
(let ((range (make-overlay start end)))
(overlay-put range 'invisible 'hidden-thread)
(overlay-put range 'isearch-open-invisible 'reveal-overlay)))

(defun next-thread-bounds ()
"moving forward from start in the VM summary buffer this will
find the next thread, and return the point at the end of the
first line of the thread, and the point at the end of the last
line of the thread. This will leave the point at the end of the
last noticed thread. Note that this relies on the thread
indentation to recognize threads."
(interactive)
(let ((start (point))
(end (point))
(more t))
;; stay in while till find a thread
(while (and more (not (> (count-lines start end) 0)))
;; search for the beginning of the thread
(if (re-search-forward "[0-9] \"" nil t)
(progn
(move-end-of-line 1)
(setq start (point))
;; search for the end of the thread
(if (re-search-forward "[0-9] \"" nil t)
(progn
(previous-line)
(move-end-of-line 1)
(setq end (point)))
;; buffer ends on a thread
(progn
(end-of-buffer)
(setq end (point)))))
(setq more nil)))
(if more
(list start end)
nil)))

(defun collapse-all-threads ()
(interactive)
(beginning-of-buffer)
(while (setq thread-bounds (next-thread-bounds))
(collapse-thread (car thread-bounds) (car (cdr thread-bounds)))))

-------------------------vm-hide-threads.el-------------------------

0 new messages