unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* easy-todo.el --- Manage your todos in an extremely easy way!
@ 2007-10-11  2:47 William Xu
  2007-10-11 14:05 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: William Xu @ 2007-10-11  2:47 UTC (permalink / raw)
  To: emacs-devel

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 <william.xwl@gmail.com>
;; 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)

\f
;;; 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

  大道泛兮,其可左右。万物恃之以生而不辞,功成而不有。
衣养万物而不为主,可名于小;万物归焉而不为主,可名为大。
以其终不自为大,故能成其大。
            ---- 老子第三十四章

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: easy-todo.el --- Manage your todos in an extremely easy way!
  2007-10-11  2:47 easy-todo.el --- Manage your todos in an extremely easy way! William Xu
@ 2007-10-11 14:05 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2007-10-11 14:05 UTC (permalink / raw)
  To: William Xu; +Cc: emacs-devel

William Xu <william.xwl@gmail.com> writes:

> It's a very simple extension, just do what it intends to.

Good. 

> What do you think of this?

It does what it intends to :)  

Did you try Org? It's an organizer, it officially comes with latest GNU
Emacs.  You can use it for doing complex planning, but you can also use
it to do very simple planning.

HTH,

-- 
Bastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-11 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-11  2:47 easy-todo.el --- Manage your todos in an extremely easy way! William Xu
2007-10-11 14:05 ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).