;;; planner-multi-plan.el --- Tasks and notes with more than one plan page ;;; Commentary: ;; Tasks and notes can have links of the form ;; (WikiLinkOne,WikiLinkTwo,WikiLinkThree). (defun planner-format-task (task-info &optional category priority status description link-text link) "Return a string containing TASK-INFO ready to be inserted into a page. Non-nil values of CATEGORY, PRIORITY, STATUS, DESCRIPTION, LINK-TEXT, and LINK override TASK-INFO." (format planner-task-format (or category (planner-task-category task-info)) (or priority (planner-task-priority task-info) "") (or status (planner-task-status task-info)) (or description (planner-task-description task-info)) (let ((text (or link-text (and link (planner-make-link link)) (planner-task-link-text task-info)))) (if (and text (not (equal text ""))) (concat " (" text ")") "")))) (defun planner-update-task-on-page (page info &optional no-create) "On PAGE, update or create a task based on INFO. If NO-CREATE is non-nil, do not create it if the task is not yet there." (setq page (emacs-wiki-wiki-link-target page)) (unless (and no-create (not (assoc page (planner-file-alist)))) (planner-find-file page) (if (planner-find-task info) (unless (planner-tasks-equal-p info (planner-current-task-info)) (delete-region (line-beginning-position) (min (point-max) (1+ (line-end-position)))) (insert (planner-format-task info nil nil nil nil (planner-task-link-text info)) "\n")) (unless no-create (planner-seek-task-creation-point) (insert (planner-format-task info nil nil nil nil (planner-task-link-text info)) "\n"))))) ;; We put this in a separate function so that we can change it ;; easily (defsubst planner-multi-plan-split-string (link) "Return a list of links in LINK. LINK should be a string of the form link1,link2,link3 where links can be extended links or simple wiki links." (and link (split-string link ","))) (defsubst planner-multi-plan-create-string (list) "Return LIST as a link-text string." (mapconcat 'identity list ",")) (defun planner-multi-plan-delete-matching (regexp list) "Remove all elements that match REGEXP from LIST." (delq nil (mapcar (lambda (item) (unless (string-match regexp (emacs-wiki-wiki-link-target item)) item)) list))) (defun planner-multi-plan-schedule (list new-date) "Change or set the date for LIST to NEW-DATE." (setq list (planner-multi-plan-delete-matching planner-date-regexp list)) (if new-date (cons new-date list) list)) ;; Go to the next page in a sequence (defun planner-multi-plan-next-page (page list) "Return the page following PAGE in LIST, or nil if not found." (let ((tail (member page list))) (when tail (if (= (length tail) 1) ; Last (car list) ; Return the first item (cadr tail))))) ;; Update a task on all the pages (defun planner-multi-plan-update-task-at-point () "Update the current task on all the pages linked to it." (interactive) (let* ((info (planner-current-task-info)) (links (planner-multi-plan-split-string (planner-task-link info)))) (mapcar (lambda (page) (planner-update-task-on-page page info)) links))) (defun planner-multi-plan-copy-or-move-task (&optional date) "Copy or move the current task to DATE. Tasks are moved if they are rescheduled from a date page to another date page." (let ((info (planner-current-task-info)) ) new-links) (setq new-links (planner-multi-plan-schedule (planner-multi-plan-split-string (planner-task-link info)))) (mapcar (lambda (page) (if (string-match planner-date-regexp page) (progn ;; Delete it from the page ) ;; Update the task )) (unless info (error "No task on line")) ;; Delete it from any date pages ;; Update the linked plan pages ;; Create a new item ) (provide 'planner-multi-plan) ;;; planner-multi-plan.el ends here