Use better fix.
[planner-el.git] / planner-experimental.el
blobacd96cb6998fd3a30e757722c737274b385cdefe
1 ;;; planner-experimental.el --- Experimental functions for Emacs planner mode
3 ;; Copyright (C) 2004, 2008 Free Software Foundation, Inc.
5 ;; Author: Sacha Chua
7 ;; This file is part of Planner. It is not part of GNU Emacs.
9 ;; Planner is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
14 ;; Planner is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with Planner; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
24 ;;; Commentary:
26 (require 'planner)
28 ;;; Code:
30 ;;;_ + Searching
32 (defun planner-search-notes-next-match ()
33 "Jump to the next matching entry. Call after `planner-search-notes.'"
34 (interactive)
35 (if (buffer-live-p (get-buffer planner-search-notes-buffer))
36 (progn
37 (set-buffer planner-search-notes-buffer)
38 (forward-line -1)
39 (goto-char (planner-line-beginning-position))
40 (planner-follow-name-at-point))
41 (error "No current search.")))
43 (defun planner-search-notes-previous-match ()
44 "Jump to the previous matching entry. Call after `planner-search-notes.'"
45 (interactive)
46 (if (buffer-live-p (get-buffer planner-search-notes-buffer))
47 (progn
48 (set-buffer planner-search-notes-buffer)
49 (forward-line 1)
50 (goto-char (planner-line-beginning-position))
51 (planner-follow-name-at-point))
52 (error "No current search.")))
54 ;;;_* Tasks
56 (defun planner-remove-duplicates ()
57 "Remove duplicate tasks."
58 (interactive)
59 (goto-char (point-min))
60 (let ((today (planner-today))
61 (on-date (string-match planner-date-regexp (planner-page-name))))
62 (while (re-search-forward "^#[A-C][0-9]*\\s-+\\(.+\\)$" nil t)
63 (save-excursion
64 (let* ((task-info (planner-current-task-info))
65 (keep (planner-task-date task-info))
66 date
67 found
68 (start (match-beginning 0)))
69 (goto-char (planner-line-beginning-position))
70 (save-excursion
71 (unless on-date
72 (while (planner-find-task task-info (point))
73 ;; Determine the most recent one
74 (setq date (planner-task-date (planner-current-task-info)))
75 (when (or (and (string< keep today)
76 (string< keep date))
77 (string< date keep))
78 (setq keep date))
79 (forward-line 1))))
80 (while (planner-find-task task-info (point))
81 (if (string= keep
82 (planner-task-date (planner-current-task-info)))
83 (if found
84 (delete-region (planner-line-beginning-position)
85 (min (1+ (planner-line-end-position))
86 (point-max)))
87 (setq found t)
88 (forward-line 1))
89 (planner-delete-task))))))))
91 ;;;_* Local emacs vars.
92 ;;;Local variables:
93 ;;;allout-layout: (-1 0 : )
94 ;;;End:
96 (provide 'planner-experimental)
98 ;;; planner-experimental.el ends here