John Sullivan writes:
> Thanks, I've installed a modified version of this (used defcustom instead of
> defvar).
>
> What's the add-on you're working on?
The add-on add to the top of plan and day pages a menu with links to
the projects, of the form:
[[TaskPool][TaskPool(n)]]
where `n' is the number of unfinished tasks in these project. Or if
all tasks are done, of the form:
[[TaskPool]]
The menu is updated at moment when you add, delete or change the state
of a task. The module is splited in two parts, `planner-menu' and
`planner-menu-proj'. On the one hand, the first manage a list of
menus, which can be links written by user, on the other hand
`planner-menu-proj' maintain and update the menu with the projects.
It is my first program in emacs lisp and although it is not finished
yet, I would like you watch the code and check it.
I hope ideas, suggestions and reviews. Thanks ^^
;; planner-menu.el -- A menu for planner
;; Copyright (C) 2007 David Vazquez <[EMAIL PROTECTED]>
;; Version: 1.0
;; Keywords: hypermedia
;; Author: David Vazquez <[EMAIL PROTECTED]>
;; Maintainer: David Vazquez <[EMAIL PROTECTED]>
;; URL: http://
;; 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 2 of the License, 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 this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
;; Readme:
;; To install, add the path of planner-menu.el to load-path and put in
;; your .emacs this:
;; (require 'planner-menu)
;; (planner-menu-insinuate)
;; Code:
(require 'planner)
(require 'planner-lisp)
(defvar planner-menu-list nil
"List of menus to show")
;; Get the character at point in current buffer
(defmacro planner-menu-buffer-char ()
(buffer-substring-no-properties (point) (1+ (point))))
;; Make a link from target and caption strings
(defun planner-menu-make-link (target &optional caption)
(if caption
(concat "[[" target "][" caption "]]")
(concat "[[" target "]]")))
;; Generate the menu in form to string
(defun planner-menu-make ()
"Return the menus in form to string."
(interactive)
(let (planner-menu-string)
(dolist (menu planner-menu-list planner-menu-string)
(dolist (item (if (symbolp menu)
(symbol-value menu)
menu))
(let ((caption (car item))
(target (cdr item)))
(setq planner-menu-string
(concat planner-menu-string
"| " (planner-menu-make-link target caption) " "))))
(setq planner-menu-string (concat planner-menu-string "|\n")))))
;; Show menu in current plan page
(defun planner-menu-show ()
"Show the menus in current planner page."
(interactive)
(save-excursion
(save-restriction
(with-planner
(widen)
(goto-char (point-min))
;; If lines on top begin with `|', delete them.
(if (string-equal (planner-menu-buffer-char) "|")
(while (string-equal (planner-menu-buffer-char) "|")
(delete-region (line-beginning-position) (1+
(line-end-position))))
(save-excursion
(newline)))
(insert (planner-menu-make))))))
;; Insinuate planner-menu to planner
(defun planner-menu-insinuate ()
"Insinuate planner-menu to planner."
(add-hook 'planner-goto-hook 'planner-menu-show))
(provide 'planner-menu)
;; planner-menu.el ends here;; planner-menu-proj.el -- Add to planner-menu a entry by project.
;; Copyright (C) 2007 David Vazquez <[EMAIL PROTECTED]>
;; Version: 1.0
;; Keywords: hypermedia
;; Author: David Vazquez <[EMAIL PROTECTED]>
;; Maintainer: David Vazquez <[EMAIL PROTECTED]>
;; URL: http://
;; 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 2 of the License, 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 this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
;; Readme:
;; To install, add the path of planner-menu.el to load-path and put in
;; your .emacs this:
;; (require 'planner-menu-proj)
;; (planner-menu-proj-initialize)
;; Code:
(require 'planner)
(require 'planner-menu)
(defvar planner-menu-proj-tasks-undone nil)
(defvar planner-menu-proj-menu nil)
;; when a task is created
(defun planner-menu-proj-task-created ()
(let* ((projname (nth 7 (planner-current-task-info)))
(proj (assoc projname
planner-menu-proj-tasks-undone)))
(if (not proj)
(progn
(add-to-list 'planner-menu-proj-tasks-undone
(cons projname 0))
(planner-menu-proj-create-task))
(setcdr proj (1+ (cdr proj)))
(planner-menu-proj-update)
(planner-menu-show))))
;; when a task is deleted
(defun planner-menu-proj-task-deleted (info)
(when (string-match "[_oDP]" (nth 3 info))
(let ((proj (assoc
(nth 7 info)
planner-menu-proj-tasks-undone)))
(setcdr proj (1- (cdr proj))))
(planner-menu-proj-update)
(planner-menu-show)
t))
;; when a task change of state
(defun planner-menu-proj-task-change (old new)
"Doc String"
(let (of to)
(if (string-match "[_oDP]" old) (setq of t))
(if (string-match "[_oDP]" new) (setq to t))
(let ((proj (assoc
(nth 7 (planner-current-task-info))
planner-menu-proj-tasks-undone)))
(cond
;; Undone to done
((and of (not to))
(setcdr proj (1- (cdr proj))))
;; Done to undone
((and to (not of))
(setcdr proj (1+ (cdr proj)))))))
(planner-menu-proj-update)
(planner-menu-show)
t)
(defun planner-tasks-unfinished (planpage)
"Return the number of unfinished tasks in PLAN page."
(let ((planpage (list planpage))
(unfinished 0))
(dolist (task (planner-extract-tasks planpage) unfinished)
(if (string-match "[_oDP]" (planner-task-status task))
(setq unfinished (1+ unfinished))))))
(defun planner-menu-proj-update ()
"Add projects entry to `planner-menu-alist'"
(interactive)
(setq planner-menu-proj-menu nil)
(dolist (proj planner-menu-proj-tasks-undone)
(let ((plan (car proj))
(undone (cdr proj)))
(add-to-list 'planner-menu-proj-menu
(cons (if (zerop undone)
(format "%s" plan)
(format "%s(%d)" plan undone))
plan)))))
;; Create hooks and find all unfinished tasks and create a table in
;; order to following changes on this table will be on a task.
(defun planner-menu-proj-initialize ()
"Insinuate to planner-menu and build a list of ALL plan page
tasks unfinished."
(interactive)
(let ((files (muse-project-file-alist planner-project))
projects-alist)
;; Do for each file of planner pages direcoty and return
;; projects-alist
(dolist (element files projects-alist)
(unless (string-match planner-date-regexp (car element))
(let* ((plan (car element))
(undone (planner-tasks-unfinished plan)))
(add-to-list 'projects-alist (cons plan undone)))))
(add-to-list 'planner-menu-list 'planner-menu-proj-menu)
(add-hook 'planner-mark-task-hook 'planner-menu-proj-task-change)
(add-hook 'planner-create-task-hook 'planner-menu-proj-create-task)
(add-hook 'planner-delete-task-hook 'planner-menu-proj-delete-task)
(setq planner-menu-proj-tasks-undone projects-alist)
(planner-menu-proj-update)))
(provide 'planner-menu-proj)
;; planner-menu-proj.el ends here_______________________________________________
Planner-el-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/planner-el-discuss