[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
easy-todo.el --- Manage your todos in an extremely easy way!
From: |
William Xu |
Subject: |
easy-todo.el --- Manage your todos in an extremely easy way! |
Date: |
Thu, 11 Oct 2007 11:47:26 +0900 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (darwin) |
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 <address@hidden>
;; 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
大道泛兮,其可左右。万物恃之以生而不辞,功成而不有。
衣养万物而不为主,可名于小;万物归焉而不为主,可名为大。
以其终不自为大,故能成其大。
---- 老子第三十四章
- easy-todo.el --- Manage your todos in an extremely easy way!,
William Xu <=