From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: William Xu Newsgroups: gmane.emacs.devel Subject: easy-todo.el --- Manage your todos in an extremely easy way! Date: Thu, 11 Oct 2007 11:47:26 +0900 Organization: the Church of Emacs Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1192070880 11976 80.91.229.12 (11 Oct 2007 02:48:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 11 Oct 2007 02:48:00 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 11 04:47:58 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ifo5d-0007Ij-Hh for ged-emacs-devel@m.gmane.org; Thu, 11 Oct 2007 04:47:58 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ifo5X-0005VR-Kb for ged-emacs-devel@m.gmane.org; Wed, 10 Oct 2007 22:47:51 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ifo5T-0005T6-Sa for emacs-devel@gnu.org; Wed, 10 Oct 2007 22:47:47 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ifo5T-0005SS-AW for emacs-devel@gnu.org; Wed, 10 Oct 2007 22:47:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ifo5T-0005SF-4Q for emacs-devel@gnu.org; Wed, 10 Oct 2007 22:47:47 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ifo5S-0001hH-E6 for emacs-devel@gnu.org; Wed, 10 Oct 2007 22:47:46 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Ifo5M-0003Gm-4o for emacs-devel@gnu.org; Thu, 11 Oct 2007 02:47:40 +0000 Original-Received: from gw.community-engine.co.jp ([210.255.51.230]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 11 Oct 2007 02:47:40 +0000 Original-Received: from william.xwl by gw.community-engine.co.jp with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 11 Oct 2007 02:47:40 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 217 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: gw.community-engine.co.jp User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (darwin) Cancel-Lock: sha1:8btUPQAziWcU4Z1WsREff3mifJY= X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:80573 Archived-At: It's a very simple extension, just do what it intends to. What do you think of this? ;;; easy-todo.el --- Manage your todos in an extremely easy way! ;; Copyright (C) 2007 William Xu ;; Author: William Xu ;; Version: 0.2 ;; Url: http://williamxu.net9.org/ref/easy-todo.el ;; Last updated: 2007/10/11 ;; 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 3, 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 EMMS; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; `easy-todo-mode' is a very easy todo manager. It simply adds some ;; hilighting keywords, some special prefix flags(for indicating ;; different types of todo items) upon `text-mode'. ;; It supports three different prefix flags, namely "^> "(ongoing), ;; "^- "(todo), "^x "(unfinished). Here's a screenshot: ;; ;; ,---- ;; | > (work) Check compress() function ;; | > Finish easy-todo-mode ;; | - Make a nicer buddy interface for erc ;; | * display buddy images ;; | * learn from adium's look and feel ;; | x (emmms) share music with iTunes user? ;; `---- ;; Put this file into your load-path and the following into your ;; ~/.emacs: ;; (autoload 'easy-todo-mode "easy-todo") ;;; Code: ;;; Customizations (defgroup easy-todo nil "Manage todos in an easy way!" :prefix "easy-todo-" :group 'convenience) (defcustom easy-todo-ongoing-regexp "^> " "Prefix for ongoing items." :type 'string :group 'easy-todo) (defcustom easy-todo-todo-regexp "^- " "Prefix for todo items." :type 'string :group 'easy-todo) (defcustom easy-todo-unfinished-regexp "^x " "Prefix for unfinished items." :type 'string :group 'easy-todo) ;;; Implementations ;;;###autoload (define-derived-mode easy-todo-mode text-mode "Easy-Todo" "Major mode for managing todos. \\{easy-todo-mode-map}" (setq font-lock-defaults '(easy-todo-font-lock-keywords)) (run-hooks 'easy-todo-mode-hook)) (define-key easy-todo-mode-map (kbd "C-c C-o") 'easy-todo-item-ongoing) (define-key easy-todo-mode-map (kbd "C-c C-t") 'easy-todo-item-todo) (define-key easy-todo-mode-map (kbd "C-c C-u") 'easy-todo-item-unfinished) (define-key easy-todo-mode-map (kbd "C-c C-b") 'easy-todo-sort-buffer) (define-key easy-todo-mode-map (kbd "C-c C-r") 'easy-todo-sort-region) (define-key easy-todo-mode-map (kbd "C-c C-k") 'easy-todo-kill-item) (defvar easy-todo-regexps (mapconcat (lambda (i) i) (list easy-todo-ongoing-regexp easy-todo-todo-regexp easy-todo-unfinished-regexp) "\\|")) (defvar easy-todo-font-lock-keywords `((,(concat easy-todo-ongoing-regexp ".*") (0 font-lock-keyword-face t t)) (,(concat easy-todo-todo-regexp ".*") (0 font-lock-variable-name-face t t)) (,(concat easy-todo-unfinished-regexp ".*") (0 font-lock-string-face t t)))) (defun easy-todo-item-ongoing () "Switch current item into ongoing status and sort todos automatically." (interactive) (easy-todo-item-switch easy-todo-ongoing-regexp)) (defun easy-todo-item-todo () "Switch current item into todo status and sort todos automatically." (interactive) (easy-todo-item-switch easy-todo-todo-regexp)) (defun easy-todo-item-unfinished () "Switch current item into unfinished status and sort todos automatically." (interactive) (easy-todo-item-switch easy-todo-unfinished-regexp)) (defun easy-todo-item-switch (regexp) "Switch current item into status matched by REGEX and sort todos automatically. REGEX could be like `easy-todo-ongoing-regexp'." (let ((inhibit-read-only t)) (save-excursion (move-beginning-of-line 1) (or (re-search-forward easy-todo-regexps (progn (move-end-of-line 1) (point)) t 1) (re-search-backward easy-todo-regexps (point-min) t 1)) (replace-match (replace-regexp-in-string "^\\^" "" regexp))) (easy-todo-sort-buffer))) (defun easy-todo-sort-buffer () "Sort all todo items in buffer." (interactive) (easy-todo-sort-region (point-min) (point-max))) (defun easy-todo-sort-region (beg end) "Sort todo items by `easy-todo-regexps' between BEG and END. BEG and END are points." (interactive "r") (let ((inhibit-read-only t) (remaining-flags (list easy-todo-ongoing-regexp easy-todo-todo-regexp easy-todo-unfinished-regexp)) (pos beg) ; position for inserting new items item-beg item-end flag) (save-excursion (goto-char beg) (while (and remaining-flags (cdr remaining-flags)) (setq flag (car remaining-flags)) (while (setq item-beg (re-search-forward flag end t 1)) (setq item-beg (- item-beg 2)) (setq item-end (re-search-forward (mapconcat (lambda (j) j) (cdr remaining-flags) "\\|") end t 1)) (if item-end (setq item-end (- (point) 2)) (setq item-end end)) (goto-char pos) (insert (delete-and-extract-region item-beg item-end)) (setq pos (point))) (setq remaining-flags (cdr remaining-flags)))))) (defun easy-todo-kill-item () "Kill most recent item." (interactive) (let ((inhibit-read-only t)) (save-excursion (let (beg end) (move-beginning-of-line 1) (setq beg (or (re-search-forward easy-todo-regexps (save-excursion (move-end-of-line 1) (point)) t 1) (re-search-backward easy-todo-regexps (point-min) t 1))) (if beg (progn (setq beg (- beg 2)) (setq end (re-search-forward easy-todo-regexps (point-max) t 1)) (if end (setq end (- end 2)) (setq end (point-max))) (kill-region beg end)) (message "easy-todo item not found here")))))) (provide 'easy-todo) ;;; easy-todo.el ends here -- William http://williamxu.net9.org 大道泛兮,其可左右。万物恃之以生而不辞,功成而不有。 衣养万物而不为主,可名于小;万物归焉而不为主,可名为大。 以其终不自为大,故能成其大。 ---- 老子第三十四章