org2rem.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;;; org2rem.el --- Convert org appointments into reminders
  2. ;; Copyright 2006 Bastien Guerry
  3. ;;
  4. ;; Author: bzg AT altern DOT fr
  5. ;; Version: $Id: org2rem.el,v 0.1 2006/12/04 09:21:03 guerry Exp guerry $
  6. ;; Keywords: org-mode remind reminder appointment diary calendar
  7. ;; X-URL: http://www.cognition.ens.fr/~guerry/u/org2rem.el
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 2, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with this program; if not, write to the Free Software
  20. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. ;;; Commentary:
  22. ;; Not so much to say here. Just try org2rem in your org-mode buffer.
  23. ;; Put this file into your load-path and the following into your ~/.emacs:
  24. ;; (require 'org2rem)
  25. ;;; Code:
  26. (provide 'org2rem)
  27. (eval-when-compile
  28. (require 'cl))
  29. (defvar org2rem-scheduled-reminders nil)
  30. (defvar org2rem-deadline-reminders nil)
  31. (defvar org2rem-scheduled-remind-file
  32. "~/.reminders.org.scheduled")
  33. (defvar org2rem-deadline-remind-file
  34. "~/.reminders.org.deadline")
  35. (defun org2rem-list-reminders (regexp)
  36. "Make a list of appointments.
  37. REGEXP is either SCHEDULED: or DEADLINE:."
  38. (save-excursion
  39. (goto-char (point-min))
  40. (while (re-search-forward
  41. (concat "^[ \t]*" regexp
  42. "[ \t]*" org-ts-regexp2) nil t)
  43. (let* ((system-time-locale "C") ;; make sure we use english dates
  44. (year (string-to-number (match-string-no-properties 2)))
  45. (month (string-to-number (match-string-no-properties 3)))
  46. (day (string-to-number (match-string-no-properties 4)))
  47. (encoded-time (encode-time 0 0 0 day month year))
  48. (rem-time (format-time-string " %d %b %Y " encoded-time))
  49. task rem-task)
  50. (save-excursion
  51. (re-search-backward org-todo-line-regexp nil t)
  52. (setq task
  53. (replace-regexp-in-string
  54. org-bracket-link-regexp
  55. "\\3" (match-string-no-properties 3)))
  56. (setq rem-task (concat "REM" rem-time "MSG " task "%"))
  57. (if (equal regexp org-scheduled-string)
  58. (push rem-task org2rem-scheduled-reminders)
  59. (push rem-task org2rem-deadline-reminders)))))))
  60. (defun org2rem-write-file (file reminders)
  61. "Write reminders list to files."
  62. (with-temp-buffer
  63. (find-file file)
  64. (erase-buffer)
  65. (dolist (rem reminders)
  66. (insert rem "\n"))
  67. (write-file file)
  68. (kill-buffer (file-name-nondirectory file))))
  69. (defun org2rem ()
  70. "Convert apptointment from local org-mode buffer to reminders.
  71. Store scheduled appointments in `org2rem-scheduled-remind-file'
  72. and `org2rem-deadline-remind-file'."
  73. (interactive)
  74. (setq org2rem-scheduled-reminders nil)
  75. (setq org2rem-deadline-reminders nil)
  76. (save-window-excursion
  77. (org2rem-list-reminders org-scheduled-string)
  78. (org2rem-list-reminders org-deadline-string)
  79. (org2rem-write-file "~/.reminders.org.scheduled"
  80. org2rem-scheduled-reminders)
  81. (org2rem-write-file "~/.reminders.org.deadline"
  82. org2rem-deadline-reminders)))
  83. ;;;;##########################################################################
  84. ;;;; User Options, Variables
  85. ;;;;##########################################################################
  86. ;;; org2rem.el ends here