Gnus development mailing list
 help / color / mirror / Atom feed
From: Mark Plaksin <happy@usg.edu>
Subject: CODE: Hide groups with few unread articles
Date: Wed, 13 Apr 2005 21:20:29 -0400	[thread overview]
Message-ID: <m3vf6qxig2.fsf@water.tss.usg.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 1455 bytes --]

Here's some code that lets you hide groups when they have just a few unread
articles.  You can set the threshold on a per-topic and/or per-group basis.

I use levels to separate my groups by priority but I am subscribed to a lot
of groups so each level contains a lot of groups.  I'm easily distracted so
I wanted a way to hide groups without many unread articles.  That way when
I check for new messages I don't end up reading two or three articles in
each of 25 groups.  Instead I generally end up reading one or two groups
with 25 articles each.

It requires a small patch to gnus-group.el which allows you to specify the
predicate to use in the funcall to gnus-group-prepare-function.  That's the
first attachment.  The second attachment does the rest of the work.

You get a new group parameter called gnus-distraction-threshold.  If a
group has fewer than gnus-distraction-threshold unread articles, it won't
be displayed.  gnus-distraction-threshold defaults to 1 so nothing should
change unless you set the threshold somewhere.  As with any group parameter
you can set it for a topic and have it apply to all groups in the topic.
By default groups with ticked articles are always displayed.

Two key bindings are turned on in the Group buffer:
- C-cd toggles distraction prevention on and off
- C-ct toggles the display of groups with ticked articles

I've only been playing with this for a few days so comments and suggestions
are very welcome!


[-- Attachment #2: gnus-group.el patch --]
[-- Type: text/plain, Size: 1232 bytes --]

--- gnus-group.el.orig	2005-04-13 20:43:59.300374438 -0400
+++ gnus-group.el	2005-04-13 20:54:52.185167853 -0400
@@ -255,6 +255,10 @@
   :group 'gnus-group-listing
   :type 'function)
 
+(defvar gnus-group-prepare-function-predicate '(lambda (info) (gnus-distraction-prevention-check info))
+  "Predicate to use in call to gnus-group-prepare-function.
+Defaults to '(lambda (info) (gnus-distraction-prevention-check info))")
+
 (defcustom gnus-group-prepare-hook nil
   "Hook called after the group buffer has been generated.
 If you want to modify the group buffer, you can use this hook."
@@ -1156,9 +1160,12 @@
 	(props (text-properties-at (point-at-bol)))
 	(empty (= (point-min) (point-max)))
 	(group (gnus-group-group-name))
+        (unread-or-predicate (if (functionp gnus-group-prepare-function-predicate)
+                                 gnus-group-prepare-function-predicate
+                               unread))
 	number)
     (set-buffer gnus-group-buffer)
-    (setq number (funcall gnus-group-prepare-function level unread lowest))
+    (setq number (funcall gnus-group-prepare-function level unread-or-predicate lowest))
     (when (or (and (numberp number)
 		   (zerop number))
 	      (zerop (buffer-size)))

[-- Attachment #3: distraction-prevention.el --]
[-- Type: text/plain, Size: 2402 bytes --]

(defvar gnus-prevent-distraction-prevention nil
  "If t, do not prevent distraction.")
(defvar gnus-distraction-prevention-include-ticked t
  "If t, groups with ticked articles will always be displayed.")
(setq gnus-distraction-threshold 1)

(defun gnus-distraction-prevention-check (info)
  "Return t if group has more than gnus-distraction-threshold unread articles.
If gnus-distraction-prevention-include-ticked is t, groups with ticked articles will always be displayed."
  ;(debug)
  (let* ((group (car info))
         (threshold (or 
                     (if gnus-prevent-distraction-prevention
                         1
                       nil)
                     (gnus-group-find-parameter group
                                                'gnus-distraction-threshold)
                     gnus-distraction-threshold))
         (unread (or (gnus-group-unread group)
                     0))
         (ticked (assoc 'tick (gnus-info-marks info))))
    ;; if unread is t, the group is not opened
    (if (eq unread t)
        (setq unread 0))
    ;;(message (concat "threshold for " group " is "
    ;;                 (number-to-string threshold)))
    (or (and gnus-distraction-prevention-include-ticked
             ticked)
        (>= unread threshold))))

(defun gnus-distraction-prevention-toggle ()
  "Toggle between distraction prevention and no distraction prevention."
  (interactive)
  (let ((message))
    (if gnus-prevent-distraction-prevention
        (progn
          (setq gnus-prevent-distraction-prevention nil
                message "on"))
      (setq gnus-prevent-distraction-prevention t
            message "off"))
    (gnus-group-list-groups)
    (message (concat "Distraction prevention is " message "."))))

(defun gnus-distraction-tick-toggle ()
  "Toggle between displaying groups with ticked articles or not."
  (interactive)
  (let ((message))
    (if gnus-distraction-prevention-include-ticked
        (progn
          (setq gnus-distraction-prevention-include-ticked nil
                message "on"))
      (setq gnus-distraction-prevention-include-ticked t
            message "off"))
    (gnus-group-list-groups)
    (message (concat "Ticked distraction prevention is " message "."))))

(define-key gnus-group-mode-map (kbd "C-c d")
  'gnus-distraction-prevention-toggle)
(define-key gnus-group-mode-map (kbd "C-c t")
  'gnus-distraction-tick-toggle)

             reply	other threads:[~2005-04-14  1:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-14  1:20 Mark Plaksin [this message]
2006-04-14 15:17 ` Lars Magne Ingebrigtsen
2006-04-16 20:27   ` Mark Plaksin
2006-04-17  8:59     ` Lars Magne Ingebrigtsen
2006-04-26 16:32       ` Reiner Steib
2006-04-14 18:13 ` Leon
2006-04-16 20:28   ` Mark Plaksin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3vf6qxig2.fsf@water.tss.usg.edu \
    --to=happy@usg.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).