Don Marti’s e-mail productivity hack

| productivity

See http://www.linuxworld.com/community/?q=node/387 for inspiration.

;;;_+ Inbox anti-addiction hack
;;
;; The following code implements the inbox productivity hack described
;; by Don Marti in http://www.linuxworld.com/community/?q=node/387 .
;; People are not allowed to check mail for more messages unless the
;; number of ticked items has decreased since the last time checked
;; or `sacha/gnus-inbox-time-threshold' seconds have passed.
;;
;; Use ! (tick article) to mark articles as needing action.
;; Modify the logic if you move messages from your inbox into some kind
;; of archive (which is probably a better idea).

(defvar sacha/gnus-inbox-time-threshold (seconds-to-time (* 60 60 2))
  "*Number of seconds before you can check again if you haven't done any work.
Nil means don't use time.")
(defvar sacha/gnus-inbox-group "mail.misc"
  "*Group to consider as inbox.")

(defvar sacha/gnus-inbox-last-count nil "Number of ticked items in inbox.")
(defvar sacha/gnus-inbox-last-check nil "Timestamp of last check.")

(defun sacha/gnus-inbox-decreased-p ()
  "Return non-nil if you are allowed to check mail.
Based on http://www.linuxworld.com/community/?q=node/387"
  (or (not (numberp sacha/gnus-inbox-last-count)) ;; First time called
      (and sacha/gnus-inbox-last-check
           sacha/gnus-inbox-time-threshold
           (not (time-less-p (time-since sacha/gnus-inbox-last-check)
                             sacha/gnus-inbox-time-threshold)))
      (or (= (sacha/gnus-inbox-count) 0)
          (< (sacha/gnus-inbox-count)
             sacha/gnus-inbox-last-count))))

(defadvice gnus-group-get-new-news (around sacha/gnus-inbox-check-mail activate)
  "Allow only if the inbox count has decreased."
  (if (sacha/gnus-inbox-decreased-p)
      ad-do-it
    (error "Get your mail count below %d first." sacha/gnus-inbox-last-count))
  (setq sacha/gnus-inbox-last-count (sacha/gnus-inbox-count)
        sacha/gnus-inbox-last-check (current-time)))

(defun sacha/gnus-inbox-count ()
  "Return number of ticked items in `sacha/gnus-inbox-group'."
  (save-window-excursion
    (gnus-summary-read-group-1 sacha/gnus-inbox-group nil t nil t)
    (length gnus-newsgroup-marked)))

Random Emacs symbol: set-process-filter-multibyte - Function: Set multibyteness of the strings given to PROCESS's filter.

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.