From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/21196 Path: main.gmane.org!not-for-mail From: Kai.Grossjohann@CS.Uni-Dortmund.DE Newsgroups: gmane.emacs.gnus.general Subject: Manage todo items with Gnus Date: 14 Feb 1999 23:27:24 +0100 Sender: owner-ding@hpc.uh.edu Message-ID: <86aeygk4dv.fsf@slowfox.frob.org> NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1035159348 21782 80.91.224.250 (21 Oct 2002 00:15:48 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 00:15:48 +0000 (UTC) Return-Path: Original-Received: from spinoza.math.uh.edu (spinoza.math.uh.edu [129.7.128.18]) by sclp3.sclp.com (8.8.5/8.8.5) with ESMTP id RAA12639 for ; Sun, 14 Feb 1999 17:33:01 -0500 (EST) Original-Received: from sina.hpc.uh.edu (Sina.HPC.UH.EDU [129.7.3.5]) by spinoza.math.uh.edu (8.9.1/8.9.1) with ESMTP id QAB12665; Sun, 14 Feb 1999 16:31:37 -0600 (CST) Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Sun, 14 Feb 1999 16:32:35 -0600 (CST) Original-Received: from sclp3.sclp.com (root@sclp3.sclp.com [204.252.123.139]) by sina.hpc.uh.edu (8.7.3/8.7.3) with ESMTP id QAA15706 for ; Sun, 14 Feb 1999 16:32:18 -0600 (CST) Original-Received: from waldorf.cs.uni-dortmund.de (waldorf.cs.uni-dortmund.de [129.217.4.42]) by sclp3.sclp.com (8.8.5/8.8.5) with ESMTP id RAA12602 for ; Sun, 14 Feb 1999 17:32:07 -0500 (EST) Original-Received: from ramses.informatik.uni-dortmund.de (ramses.cs.uni-dortmund.de [129.217.20.180]) by waldorf.cs.uni-dortmund.de with SMTP id XAA07650 for ; Sun, 14 Feb 1999 23:31:45 +0100 (MET) Original-Received: (grossjoh@localhost) by ramses.informatik.uni-dortmund.de id XAA04647; Sun, 14 Feb 1999 23:31:44 +0100 Original-To: ding@gnus.org User-Agent: Gnus/5.070074 (Pterodactyl Gnus v0.74) Emacs/20.3 Original-Lines: 262 Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:21196 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:21196 This is a MIME multipart message. If you are reading this, you shouldn't. This is a MIME multipart message. If you are reading this, you shouldn't. --=-=-= Subject pretty much sez it all. This is pre-alpha code. Hacked it together in two hours. Would appreciate your input. kai `short sentence. good sentence.' -- I like _b_o_t_h kinds of music. --=-=-= Content-Type: application/emacs-lisp; name=todo-gnus.el Content-Disposition: attachment; filename=todo-gnus.el Content-Transfer-Encoding: 8bit ;;; todo-gnus.el --- Manage todo items with Gnus ;; Copyright (C) 1999 by Kai Grossjohann. ;; Author: Kai.Grossjohann@CS.Uni-Dortmund.DE ;; Keywords: news, mail, calendar, convenience ;; Version: $Id: todo-gnus.el,v 1.2 1999/02/14 22:21:03 kai Exp kai $ ;; This file 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, or (at your option) ;; any later version. ;; This file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Warning: this is alpha code! Use at your own risk! Don your ;; asbestos longjohns! Might eat your mail for lunch! ;; This file provides a new Gnus backend, nntodo, for storing todo ;; items. Each todo item is a message but has a special header ;; `X-Todo-Priority' for the priority of a todo item. It is possible ;; to sort todo items by creation date and by priority. Sorting by ;; due date hasn't been done yet. ;;; Kudos: ;; Dan Nicolaescu for providing me with a first ;; implementation to look at and steal from. ;;; Code: ;;; Backend definition: (require 'nnheader) (require 'nnmail) (require 'gnus-start) (require 'nnmbox) (require 'nnoo) (nnoo-declare nntodo nnmbox) ;; If this variable isn't named nntodo-mbox-file, strange things ;; happen. This seems to be a nnoo-ey problem. (defvoo nntodo-mbox-file (expand-file-name "~/.nntodo") "Name of the todo file in the user's home directory." nnmbox-mbox-file) ;; Similar. (defvoo nntodo-active-file (expand-file-name "~/.nntodo-active") "Name of the actile file for the todo file." nnmbox-active-file) ;; Can we protect better? (defvoo nntodo-get-new-mail nil "Whether nntodo should get new mail. MUST be nil!" nnmbox-get-new-mail) (defvoo nntodo-current-group "" nil nnmbox-current-group) (defconst nntodo-version "nntodo $Id: todo-gnus.el,v 1.2 1999/02/14 22:21:03 kai Exp kai $") (defvoo nntodo-status-string "" nil nnmbox-status-string) (nnoo-define-basics nntodo) ;; Too bad that nnmbox-create-mbox-file isn't nnoo'd. (deffoo nntodo-open-server (server &optional defs) (nnoo-change-server 'nntodo server defs) (nntodo-create-mbox-file) (cond ((not (file-exists-p nntodo-mbox-file)) (nntodo-close-server) (nnheader-report 'nntodo "No such file: %s" nntodo-mbox-file)) ((file-directory-p nntodo-mbox-file) (nntodo-close-server) (nnheader-report 'nntodo "Not a regular file: %s" nntodo-mbox-file)) (t (nnheader-report 'nntodo "Opened server %s using mbox %s" server nntodo-mbox-file) t))) ;; Copy of nnmbox-create-mbox-file, except for file name. (defun nntodo-create-mbox-file () (when (not (file-exists-p nntodo-mbox-file)) (nnmail-write-region 1 1 nntodo-mbox-file t 'nomesg))) ;; When creating a group, it gets some special settings (deffoo nntodo-request-create-group (group &optional server args) "Do whatever the nnmbox function does, then set a few group params." (nnoo-parent-function 'nntodo 'nnmbox-request-create-group (list group server args)) ;; Instead of setting these parameters for each group, isn't there a ;; way of somehow putting this into the server spec or into the ;; backend code? ;; Summary line looks different for todo items. (gnus-group-set-parameter (gnus-group-prefixed-name group (list "nntodo" server)) 'gnus-summary-line-format (list "%5N %7uT: %s\n")) ;; Why does the following not work? `gnus-post-method' is nil or ;; something like this in the message buffer after hitting `a' in an ;; nntodo group. (gnus-group-set-parameter (gnus-group-prefixed-name group (list "nntodo" server)) 'gnus-post-method '('current)) ;; Always display all articles. Maybe this is stupid? (gnus-group-set-parameter (gnus-group-prefixed-name group (list "nntodo" server)) 'display 'all) ;; Always display this group. (gnus-group-set-parameter (gnus-group-prefixed-name group (list "nntodo" server)) 'visible t) ;; Because the post method thing doesn't work, we need this. (gnus-group-set-parameter (gnus-group-prefixed-name group (list "nntodo" server)) 'gcc-self t) ;; Enter gnus-todo-mode in nntodo summaries. (gnus-group-set-parameter (gnus-group-prefixed-name group (list "nntodo" server)) 'dummy '( (gnus-todo-mode 1) ))) (nnoo-import nntodo (nnmbox)) (provide 'nntodo) ;;; Utility code: ;; Hook nntodo backend into Gnus (unless (assoc "nntodo" gnus-valid-select-methods) (gnus-declare-backend "nntodo" 'post 'respool 'address)) ;;; Creating todo items: (defvar todo-gnus-priority-alist '(("high" . 0) ("medium" . 1) ("low" . 2)) "Association between prio names and values.") (defun todo-gnus-get-priority () "Read a priority from the minibuffer." (interactive) (completing-read "Priority (medium): " todo-gnus-priority-alist nil ;predicate t ;require-match nil nil "medium")) ;; The following section is gross. Isn't there a better way to do ;; this? Maybe specify a special sending function for nntodo groups? ;; But how? (defun todo-gnus-message-send-hook () "Inserts required headers in todo item." (when (string-match "^nntodo\\>" (car gnus-message-group-art)) (message-remove-header "Newsgroups") (message-generate-headers '( ("X-Todo-Priority" . todo-gnus-get-priority) )))) (add-hook 'message-send-hook 'todo-gnus-message-send-hook) (add-to-list 'gnus-extra-headers 'X-Todo-Priority) (add-to-list 'nnmail-extra-headers 'X-Todo-Priority) ;;; Summary buffer: ;; This function is used in nntodo-request-create-group to set ;; `gnus-summary-line-format'. (defun gnus-user-format-function-T (head) (let* ((extra-headers (mail-header-extra head))) (cdr (assoc 'X-Todo-Priority extra-headers)))) ;; Sorting by priority. Code pretty much gleaned from gnus-sum.el ;; without any deeper understanding at all. (defun gnus-article-sort-by-priority (h1 h2) (let* ((e1 (mail-header-extra h1)) (e2 (mail-header-extra h2)) (p1 (cdr (assoc 'X-Todo-Priority e1))) (p2 (cdr (assoc 'X-Todo-Priority e2))) (n1 (cdr (assoc p1 todo-gnus-priority-alist))) (n2 (cdr (assoc p2 todo-gnus-priority-alist)))) (unless n1 (error "Unknown priority: %s" p1)) (unless n2 (error "Unknown priority: %s" p2)) (if (= n1 n2) (< (mail-header-number h1) (mail-header-number h2)) (< n1 n2)))) (defun gnus-thread-sort-by-priority (h1 h2) (gnus-article-sort-by-priority (gnus-thread-header h1) (gnus-thread-header h2))) (defun gnus-summary-sort-by-priority (&optional reverse) "Sort the summary buffer by priority. Argument REVERSE means reverse order." (interactive "P") (gnus-summary-sort 'priority reverse)) ;; Todo minor mode. ;; Gee, this seems to be simple with easy-mmode! (require 'easy-mmode) (defvar gnus-todo-mode-map (easy-mmode-define-keymap (list (cons (kbd "i n") (cons "Sort by number" 'gnus-summary-sort-by-number)) (cons (kbd "i p") (cons "Sort by priority" 'gnus-summary-sort-by-priority)) (cons (kbd "i i") (cons "Add new todo item" 'gnus-summary-post-news))) "Todo")) (easy-mmode-define-minor-mode gnus-todo-mode "Minor mode for nntodo summary buffers. Without ARG, toggle gnus-todo-mode. With ARG, turn on iff ARG is positive, else turn off." nil " Todo" gnus-todo-mode-map) ;;; Epilog: (provide 'todo-gnus) ;;; todo-gnus.el ends here --=-=-=--