mhc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/COPYRIGHT +28 -0
  6. data/Gemfile +8 -0
  7. data/README.org +209 -0
  8. data/Rakefile +13 -0
  9. data/bin/mhc +312 -0
  10. data/emacs/Cask +25 -0
  11. data/emacs/Makefile +58 -0
  12. data/emacs/mhc-calendar.el +1723 -0
  13. data/emacs/mhc-calfw.el +135 -0
  14. data/emacs/mhc-compat.el +90 -0
  15. data/emacs/mhc-date.el +642 -0
  16. data/emacs/mhc-day.el +149 -0
  17. data/emacs/mhc-db.el +158 -0
  18. data/emacs/mhc-draft.el +211 -0
  19. data/emacs/mhc-e21.el +167 -0
  20. data/emacs/mhc-face.el +236 -0
  21. data/emacs/mhc-file.el +224 -0
  22. data/emacs/mhc-guess.el +648 -0
  23. data/emacs/mhc-header.el +176 -0
  24. data/emacs/mhc-logic.el +563 -0
  25. data/emacs/mhc-message.el +130 -0
  26. data/emacs/mhc-minibuf.el +466 -0
  27. data/emacs/mhc-misc.el +248 -0
  28. data/emacs/mhc-mua.el +260 -0
  29. data/emacs/mhc-parse.el +286 -0
  30. data/emacs/mhc-process.el +35 -0
  31. data/emacs/mhc-ps.el +1174 -0
  32. data/emacs/mhc-record.el +201 -0
  33. data/emacs/mhc-schedule.el +202 -0
  34. data/emacs/mhc-summary.el +763 -0
  35. data/emacs/mhc-sync.el +158 -0
  36. data/emacs/mhc-vars.el +149 -0
  37. data/emacs/mhc.el +1114 -0
  38. data/icons/Anniversary.xbm +6 -0
  39. data/icons/Anniversary.xpm +27 -0
  40. data/icons/Birthday.xbm +6 -0
  41. data/icons/Birthday.xpm +25 -0
  42. data/icons/Business.xbm +6 -0
  43. data/icons/Business.xpm +24 -0
  44. data/icons/CheckBox.xbm +6 -0
  45. data/icons/CheckBox.xpm +24 -0
  46. data/icons/CheckedBox.xbm +6 -0
  47. data/icons/CheckedBox.xpm +25 -0
  48. data/icons/Conflict.xbm +6 -0
  49. data/icons/Conflict.xpm +22 -0
  50. data/icons/Date.xbm +6 -0
  51. data/icons/Date.xpm +29 -0
  52. data/icons/Holiday.xbm +6 -0
  53. data/icons/Holiday.xpm +25 -0
  54. data/icons/Link.xbm +6 -0
  55. data/icons/Link.xpm +25 -0
  56. data/icons/Other.xbm +6 -0
  57. data/icons/Other.xpm +28 -0
  58. data/icons/Party.xbm +6 -0
  59. data/icons/Party.xpm +23 -0
  60. data/icons/Private.xbm +6 -0
  61. data/icons/Private.xpm +26 -0
  62. data/icons/Recurrence.xbm +6 -0
  63. data/icons/Recurrence.xpm +98 -0
  64. data/icons/Vacation.xbm +6 -0
  65. data/icons/Vacation.xpm +26 -0
  66. data/lib/mhc.rb +45 -0
  67. data/lib/mhc/builder.rb +64 -0
  68. data/lib/mhc/caldav.rb +304 -0
  69. data/lib/mhc/calendar.rb +106 -0
  70. data/lib/mhc/command.rb +13 -0
  71. data/lib/mhc/command/cache.rb +14 -0
  72. data/lib/mhc/command/completions.rb +108 -0
  73. data/lib/mhc/command/init.rb +133 -0
  74. data/lib/mhc/command/scan.rb +33 -0
  75. data/lib/mhc/command/sync.rb +22 -0
  76. data/lib/mhc/config.rb +229 -0
  77. data/lib/mhc/converter.rb +330 -0
  78. data/lib/mhc/datastore.rb +164 -0
  79. data/lib/mhc/date_enumerator.rb +274 -0
  80. data/lib/mhc/date_frame.rb +124 -0
  81. data/lib/mhc/date_helper.rb +49 -0
  82. data/lib/mhc/etag.rb +68 -0
  83. data/lib/mhc/event.rb +396 -0
  84. data/lib/mhc/formatter.rb +312 -0
  85. data/lib/mhc/logger.rb +94 -0
  86. data/lib/mhc/modifier.rb +149 -0
  87. data/lib/mhc/occurrence.rb +94 -0
  88. data/lib/mhc/occurrence_enumerator.rb +113 -0
  89. data/lib/mhc/property_value.rb +33 -0
  90. data/lib/mhc/property_value/date.rb +190 -0
  91. data/lib/mhc/property_value/integer.rb +15 -0
  92. data/lib/mhc/property_value/list.rb +41 -0
  93. data/lib/mhc/property_value/period.rb +49 -0
  94. data/lib/mhc/property_value/range.rb +100 -0
  95. data/lib/mhc/property_value/recurrence_condition.rb +272 -0
  96. data/lib/mhc/property_value/text.rb +11 -0
  97. data/lib/mhc/property_value/time.rb +45 -0
  98. data/lib/mhc/query.rb +210 -0
  99. data/lib/mhc/sync.rb +46 -0
  100. data/lib/mhc/sync/driver.rb +108 -0
  101. data/lib/mhc/sync/status.rb +70 -0
  102. data/lib/mhc/sync/status_manager.rb +142 -0
  103. data/lib/mhc/sync/strategy.rb +233 -0
  104. data/lib/mhc/sync/syncinfo.rb +98 -0
  105. data/lib/mhc/templates/config.yml.erb +142 -0
  106. data/lib/mhc/version.rb +4 -0
  107. data/lib/mhc/webdav.rb +319 -0
  108. data/mhc.gemspec +24 -0
  109. data/samples/DOT.mhc-config.yml +116 -0
  110. data/samples/japanese-holidays.mhcc +153 -0
  111. data/samples/mhc-completions.zsh +11 -0
  112. data/spec/mhc_spec.rb +682 -0
  113. data/spec/spec_helper.rb +9 -0
  114. data/xpm/close.xpm +18 -0
  115. data/xpm/delete.xpm +19 -0
  116. data/xpm/exit.xpm +18 -0
  117. data/xpm/month.xpm +18 -0
  118. data/xpm/next.xpm +18 -0
  119. data/xpm/next2.xpm +18 -0
  120. data/xpm/next_year.xpm +18 -0
  121. data/xpm/open.xpm +19 -0
  122. data/xpm/prev.xpm +18 -0
  123. data/xpm/prev2.xpm +18 -0
  124. data/xpm/prev_year.xpm +18 -0
  125. data/xpm/save.xpm +19 -0
  126. data/xpm/today.xpm +18 -0
  127. metadata +214 -0
data/emacs/mhc-day.el ADDED
@@ -0,0 +1,149 @@
1
+ ;;; -*- mode: Emacs-Lisp; coding: utf-8 -*-
2
+
3
+ ;; Author: Yoshinari Nomura <nom@quickhack.net>,
4
+ ;; TSUCHIYA Masatoshi <tsuchiya@namazu.org>
5
+ ;; Created: 2000/05/04
6
+ ;; Reviesd: $Date$
7
+
8
+
9
+ ;;; Commentary:
10
+
11
+ ;; This file is a part of MHC, and includes functions to manipulate
12
+ ;; MHC-DAY structure.
13
+
14
+
15
+ ;;; About MHC-DAY structure:
16
+
17
+ ;; Each MHC-DAY structure is a cons cell has a construction as
18
+ ;; follows:
19
+ ;;
20
+ ;; MHC-DAY ::= ( KEY . VALUE )
21
+ ;; KEY ::= DATE
22
+ ;; VALUE ::= [ YEAR MONTH DAY-OF-MONTH DAY-OF-WEEK HOLIDAY SCHEDULES ]
23
+ ;; YEAR ::= integer, larger than 1900.
24
+ ;; MONTH ::= integer, between 1 and 12.
25
+ ;; DAY-OF-MONTH ::= integer, between 1 and 31.
26
+ ;; DAY-OF-WEEK ::= integer, between 0 and 6.
27
+ ;; HOLIDAY ::= nil or t. t stands for holiday.
28
+ ;; SCHEDULES ::= MHC-SCHEDULE*
29
+
30
+
31
+ ;;; Code:
32
+
33
+ ;; Function and macros to manipulate MHC-DAY structure:
34
+
35
+ (defun mhc-day-new (date &optional year month day-of-month day-of-week holiday schedules)
36
+ "Constructor of MHC-DAY structure."
37
+ (cons date
38
+ (vector (or year (mhc-date-yy date))
39
+ (or month (mhc-date-mm date))
40
+ (or day-of-month (mhc-date-dd date))
41
+ (or day-of-week (mhc-date-ww date))
42
+ holiday
43
+ schedules)))
44
+
45
+ (defmacro mhc-day/key (dayinfo)
46
+ `(car ,dayinfo))
47
+ (defmacro mhc-day/value (dayinfo)
48
+ `(cdr ,dayinfo))
49
+
50
+ (defmacro mhc-day-date (dayinfo)
51
+ `(mhc-day/key ,dayinfo))
52
+ (defmacro mhc-day-year (dayinfo)
53
+ `(aref (mhc-day/value ,dayinfo) 0))
54
+ (defmacro mhc-day-month (dayinfo)
55
+ `(aref (mhc-day/value ,dayinfo) 1))
56
+ (defmacro mhc-day-day-of-month (dayinfo)
57
+ `(aref (mhc-day/value ,dayinfo) 2))
58
+ (defmacro mhc-day-day-of-week (dayinfo)
59
+ `(aref (mhc-day/value ,dayinfo) 3))
60
+ (defmacro mhc-day-holiday (dayinfo)
61
+ `(aref (mhc-day/value ,dayinfo) 4))
62
+ (defmacro mhc-day-schedules (dayinfo)
63
+ `(aref (mhc-day/value ,dayinfo) 5))
64
+
65
+ (defmacro mhc-day-set-holiday (dayinfo holiday)
66
+ `(aset (mhc-day/value ,dayinfo) 4 ,holiday))
67
+ (defmacro mhc-day-set-schedules (dayinfo schedules)
68
+ `(aset (mhc-day/value ,dayinfo) 5 ,schedules))
69
+
70
+ (defun mhc-day-day-of-week-as-string (dayinfo)
71
+ "Return three letter code of the day of week."
72
+ (aref ["Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"]
73
+ (mhc-day-day-of-week dayinfo)))
74
+
75
+ (defun mhc-day-busy-p (dayinfo)
76
+ (let ((schedules (mhc-day-schedules dayinfo)))
77
+ (catch 'busy
78
+ (while schedules
79
+ (or (mhc-schedule-in-category-p (car schedules) "holiday")
80
+ (throw 'busy t))
81
+ (setq schedules (cdr schedules))))))
82
+
83
+
84
+
85
+ ;; Utility functions:
86
+
87
+ (defmacro mhc-day-let (day &rest form) "\
88
+ This special form converts DAY, as the number of days since
89
+ 1970/01/01, to following local variables, and evaluates FORM.
90
+
91
+ year
92
+ The year, an integer typically greater than 1900.
93
+
94
+ month
95
+ The month of the year, as an integer between 1 and 12.
96
+
97
+ day-of-month
98
+ The day of the month, as an integer between 1 and 31.
99
+
100
+ day-of-week
101
+ The day of week, as an integer between 0 and 6, where 0
102
+ stands for Sunday.
103
+ "
104
+ (let ((tempvar (make-symbol "decode-time")))
105
+ `(let* ((,tempvar (mhc-date-to-list , day))
106
+ (day-of-month (nth 2 ,tempvar))
107
+ (month (nth 1 ,tempvar))
108
+ (year (nth 0 ,tempvar))
109
+ (day-of-week (nth 3 ,tempvar)))
110
+ ,@form)))
111
+ (put 'mhc-day-let 'lisp-indent-function 1)
112
+ (put 'mhc-day-let 'edebug-form-spec '(form body))
113
+
114
+
115
+
116
+ (provide 'mhc-day)
117
+
118
+ ;;; Copyright Notice:
119
+
120
+ ;; Copyright (C) 1999, 2000 Yoshinari Nomura. All rights reserved.
121
+ ;; Copyright (C) 2000 MHC developing team. All rights reserved.
122
+
123
+ ;; Redistribution and use in source and binary forms, with or without
124
+ ;; modification, are permitted provided that the following conditions
125
+ ;; are met:
126
+ ;;
127
+ ;; 1. Redistributions of source code must retain the above copyright
128
+ ;; notice, this list of conditions and the following disclaimer.
129
+ ;; 2. Redistributions in binary form must reproduce the above copyright
130
+ ;; notice, this list of conditions and the following disclaimer in the
131
+ ;; documentation and/or other materials provided with the distribution.
132
+ ;; 3. Neither the name of the team nor the names of its contributors
133
+ ;; may be used to endorse or promote products derived from this software
134
+ ;; without specific prior written permission.
135
+ ;;
136
+ ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS''
137
+ ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
138
+ ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
139
+ ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
140
+ ;; THE TEAM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
141
+ ;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
142
+ ;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
143
+ ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
144
+ ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
145
+ ;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
146
+ ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
147
+ ;; OF THE POSSIBILITY OF SUCH DAMAGE.
148
+
149
+ ;;; mhc-day.el ends here.
data/emacs/mhc-db.el ADDED
@@ -0,0 +1,158 @@
1
+ ;;; -*- mode: Emacs-Lisp; coding: utf-8 -*-
2
+
3
+ ;; Author: Yoshinari Nomura <nom@quickhack.net>,
4
+ ;; TSUCHIYA Masatoshi <tsuchiya@namazu.org>
5
+ ;; Created: 2000/05/01
6
+ ;; Revised: $Date$
7
+
8
+
9
+ ;;; Commentary:
10
+
11
+ ;; This file is a part of MHC, and includes functions to manipulate
12
+ ;; database of schedules.
13
+
14
+
15
+ ;;; Code:
16
+
17
+ (require 'mhc-day)
18
+ (require 'mhc-process)
19
+ (require 'mhc-schedule)
20
+
21
+ (defun mhc-db-scan (b e &optional nosort category search)
22
+ (mhc-process-send-command
23
+ (format "scan --format=emacs %04d%02d%02d-%04d%02d%02d%s%s"
24
+ (mhc-date-yy b)
25
+ (mhc-date-mm b)
26
+ (mhc-date-dd b)
27
+ (mhc-date-yy e)
28
+ (mhc-date-mm e)
29
+ (mhc-date-dd e)
30
+ (if category (format " --category=%s" category) "")
31
+ (if search (format " --search='%s'" search) ""))))
32
+
33
+ (defun mhc-db-search (&rest query)
34
+ (let ((b (mhc-date-new 1970 1 1))
35
+ (e (mhc-date-yy++ (mhc-date-now))))
36
+ (mhc-db-scan b e nil nil (mhc-db/query-to-search-string query))))
37
+
38
+ (defun mhc-db/quote-string (string)
39
+ (format "\"%s\"" string))
40
+
41
+ (defun mhc-db/keyword-to-string (keyword)
42
+ (format "%s" keyword))
43
+
44
+ (defun mhc-db/query-to-search-string (query)
45
+ (let ((keywords '(:subject :body :category)) string)
46
+ (mapconcat 'identity
47
+ (delq nil
48
+ (mapcar
49
+ (lambda (keyword)
50
+ (if (setq string (plist-get query keyword))
51
+ (format "%s:%s" (substring (symbol-name keyword) 1)
52
+ (mhc-db/quote-string string))))
53
+ keywords))
54
+ " | ")))
55
+
56
+ (defun mhc-db-scan-month (year month &optional nosort category)
57
+ (let ((first-date (mhc-date-new year month 1)))
58
+ (mhc-db-scan first-date
59
+ (mhc-date-mm-last first-date)
60
+ nosort
61
+ category)))
62
+
63
+ (defun mhc-db-add-record-from-buffer (record buffer &optional force-refile)
64
+ (let* ((slot (mhc-logic-record-to-slot record))
65
+ (directory (and slot
66
+ (file-name-as-directory
67
+ (expand-file-name
68
+ "spool" (mhc-config-base-directory)))))
69
+ (old-record))
70
+ (unless slot (error "Cannot get schedule slot"))
71
+ (if (mhc-record-name record)
72
+ ;; Modifying existing record
73
+ (setq old-record record)
74
+ ;; Creating new record
75
+ (mhc-record-set-name record (mhc-misc-get-new-path directory record)))
76
+ (if (or force-refile
77
+ (y-or-n-p (format
78
+ "Refile %s to %s "
79
+ (or (mhc-record-name old-record) "it")
80
+ (mhc-record-name record))))
81
+ (progn
82
+ (mhc-record-write-buffer record buffer old-record)
83
+ (if (and old-record
84
+ (not (eq record old-record)))
85
+ (let* ((dir (file-name-directory
86
+ (directory-file-name
87
+ (mhc-record-name old-record)))))
88
+ (mhc-misc-touch-directory dir)))
89
+ (mhc-misc-touch-directory directory)
90
+ t))))
91
+
92
+
93
+ (defun mhc-db-delete-file (record)
94
+ (let* ((dir (file-name-directory (directory-file-name (mhc-record-name record)))))
95
+ (mhc-record-delete record)
96
+ (mhc-misc-touch-directory dir)))
97
+
98
+ ;; FIXME: X-SC-Schedule ヘッダによって指定された子スケジュールに対する
99
+ ;; 例外規則の追加が動作しない。
100
+ (defun mhc-db-add-exception-rule (original-record except-day)
101
+ (let ((date-string (mhc-day-let except-day
102
+ (format "%04d%02d%02d" year month day-of-month))))
103
+ (with-temp-buffer
104
+ (mhc-draft-reedit-file (mhc-record-name original-record))
105
+ (let (record dayinfo schedule)
106
+ (while (setq record (mhc-parse-buffer)
107
+ dayinfo (mhc-logic-eval-for-date (list (mhc-record-sexp record)) except-day)
108
+ schedule (car (mhc-day-schedules dayinfo)))
109
+ (save-restriction
110
+ (narrow-to-region (mhc-schedule-region-start schedule)
111
+ (mhc-schedule-region-end schedule))
112
+ (mhc-header-put-value
113
+ "x-sc-day"
114
+ (mapconcat 'identity
115
+ (cons (format "!%s" date-string)
116
+ (delete date-string
117
+ (mhc-logic-day-as-string-list
118
+ (mhc-schedule-condition schedule))))
119
+ " "))))
120
+ (mhc-record-set-name record (mhc-record-name original-record))
121
+ (mhc-db-add-record-from-buffer record (current-buffer))))))
122
+
123
+
124
+
125
+ (provide 'mhc-db)
126
+
127
+ ;;; Copyright Notice:
128
+
129
+ ;; Copyright (C) 1999, 2000 Yoshinari Nomura. All rights reserved.
130
+ ;; Copyright (C) 2000 MHC developing team. All rights reserved.
131
+
132
+ ;; Redistribution and use in source and binary forms, with or without
133
+ ;; modification, are permitted provided that the following conditions
134
+ ;; are met:
135
+ ;;
136
+ ;; 1. Redistributions of source code must retain the above copyright
137
+ ;; notice, this list of conditions and the following disclaimer.
138
+ ;; 2. Redistributions in binary form must reproduce the above copyright
139
+ ;; notice, this list of conditions and the following disclaimer in the
140
+ ;; documentation and/or other materials provided with the distribution.
141
+ ;; 3. Neither the name of the team nor the names of its contributors
142
+ ;; may be used to endorse or promote products derived from this software
143
+ ;; without specific prior written permission.
144
+ ;;
145
+ ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS''
146
+ ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
147
+ ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
148
+ ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
149
+ ;; THE TEAM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
150
+ ;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
151
+ ;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
152
+ ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
153
+ ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
154
+ ;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
155
+ ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
156
+ ;; OF THE POSSIBILITY OF SUCH DAMAGE.
157
+
158
+ ;;; mhc-db.el ends here.
@@ -0,0 +1,211 @@
1
+ ;;; mhc-draft.el --- Draft modules for MHC.
2
+
3
+ ;; Author: Yoshinari Nomura <nom@quickhack.net>,
4
+ ;; Yuuichi Teranishi <teranisi@quickhack.net>
5
+ ;; Created: 2000/07/25
6
+ ;; Revised: $Date: 2008/07/04 06:01:20 $
7
+
8
+ ;;; Commentary:
9
+
10
+ ;; This file is a part of MHC, includes functions for draft.
11
+
12
+ ;;; About MUA Backend:
13
+
14
+ ;; In order to define new MUA backend, it is required to define these
15
+ ;; methods.
16
+ ;;
17
+ ;; (mhc-foo-draft-setup-new)
18
+ ;; Setup new draft (Insert header separator).
19
+ ;;
20
+ ;; (mhc-foo-draft-reedit-buffer BUFFER ORIGINAL)
21
+ ;; Restore content of BUFFER as draft in the current buffer.
22
+ ;; If ORIGINAL is non-nil, use BUFFER as raw buffer.
23
+ ;;
24
+ ;; (mhc-foo-draft-reedit-file FILENAME)
25
+ ;; Restore contents of file FILENAME as draft in the current buffer.
26
+ ;;
27
+ ;; (mhc-foo-draft-translate)
28
+ ;; Translate current buffer to raw buffer.
29
+ ;;
30
+ ;; Define these methods appropriately, and put definitions as follows:
31
+ ;;
32
+ ;; (put 'mhc-foo 'draft-setup-new 'mhc-foo-draft-setup-new)
33
+ ;; (put 'mhc-foo 'draft-reedit-buffer 'mhc-foo-draft-reedit-buffer)
34
+ ;; (put 'mhc-foo 'draft-reedit-file 'mhc-foo-draft-reedit-file)
35
+ ;; (put 'mhc-foo 'draft-translate 'mhc-foo-draft-translate)
36
+
37
+ ;;; Code:
38
+
39
+ (require 'mhc-summary)
40
+
41
+ ;; Global Variable:
42
+
43
+ (defconst mhc-draft-buffer-name "*mhc draft*")
44
+
45
+ (defcustom mhc-draft-unuse-hdr-list
46
+ '(">From " "From " "Delivered-To:" "Delivery-date:" "Envelope-to:"
47
+ "Errors-To:" "Gnus-Warning:" "Lines:" "Posted:" "Precedence:" "Received:"
48
+ "Replied:" "Return-Path:" "Sender:" "User-Agent:" "X-Bogosity:"
49
+ "X-Dispatcher:" "X-Filter:" "X-Gnus-Mail-Source:" "X-Mailer:" "X-Received:"
50
+ "X-Sender:" "X-Seqno:" "X-Spam-Flag:" "X-Spam-Probability:" "X-UIDL:"
51
+ "Xref:")
52
+ "*These headers are removed when article is imported."
53
+ :group 'mhc
54
+ :type '(repeat string))
55
+
56
+ (defcustom mhc-draft-mode-hook nil
57
+ "*Hook run in mhc draft mode buffers."
58
+ :group 'mhc
59
+ :type 'hook)
60
+
61
+ ;; Avoid warning of byte-compiler.
62
+ (defvar mhc-draft-buffer-file-name nil)
63
+
64
+ (defvar mhc-draft-mode-map)
65
+
66
+ (defsubst mhc-draft-setup-new ()
67
+ "Setup new draft (Insert header separator, etc)."
68
+ (funcall (mhc-get-function 'draft-setup-new)))
69
+
70
+
71
+ (defsubst mhc-draft-reedit-buffer (buffer &optional original)
72
+ "Restore contents of BUFFER as draft in the current buffer.
73
+ If optional argument ORIGINAL is non-nil, BUFFER is raw buffer."
74
+ (funcall (mhc-get-function 'draft-reedit-buffer) buffer original))
75
+
76
+
77
+ (defsubst mhc-draft-reedit-file (filename)
78
+ "Restore contents of file FILENAME as draft in the current buffer."
79
+ (funcall (mhc-get-function 'draft-reedit-file) filename))
80
+
81
+
82
+ (defsubst mhc-draft-translate ()
83
+ "Translate current buffer to raw buffer."
84
+ (funcall (mhc-get-function 'draft-translate)))
85
+
86
+
87
+ (define-derived-mode mhc-draft-mode
88
+ text-mode
89
+ "MHC-Draft"
90
+ "Major mode for editing schdule files of MHC.
91
+ Like Text Mode but with these additional commands:
92
+ C-c C-c mhc-draft-finish
93
+ C-c C-k mhc-draft-kill
94
+ C-c C-q mhc-draft-kill
95
+ C-c ? mhc-draft-insert-calendar
96
+ .
97
+ "
98
+ (define-key mhc-draft-mode-map "\C-c\C-c" 'mhc-draft-finish)
99
+ (define-key mhc-draft-mode-map "\C-c\C-q" 'mhc-draft-kill)
100
+ (define-key mhc-draft-mode-map "\C-c\C-k" 'mhc-draft-kill)
101
+ (define-key mhc-draft-mode-map "\C-c?" 'mhc-draft-insert-calendar)
102
+ (make-local-variable 'adaptive-fill-regexp)
103
+ (setq adaptive-fill-regexp
104
+ (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
105
+ adaptive-fill-regexp))
106
+ (unless (boundp 'adaptive-fill-first-line-regexp)
107
+ (setq adaptive-fill-first-line-regexp nil))
108
+ (make-local-variable 'adaptive-fill-first-line-regexp)
109
+ (setq adaptive-fill-first-line-regexp
110
+ (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
111
+ adaptive-fill-first-line-regexp))
112
+ (mhc-highlight-message t)
113
+ (set (make-local-variable 'indent-tabs-mode) nil))
114
+
115
+ (defun mhc-draft-kill (&optional no-confirm)
116
+ "Kill current draft.
117
+ If optional argument NO-CONFIRM is non-nil, kill without confirmation."
118
+ (interactive "P")
119
+ (if (or no-confirm (y-or-n-p "Kill draft buffer? "))
120
+ (progn
121
+ (message "")
122
+ (mhc-calendar-input-exit)
123
+ (kill-buffer (current-buffer))
124
+ (mhc-window-pop))))
125
+
126
+ (defvar mhc-draft-finish-hook nil
127
+ "Hook run after `mhc-draft-finish'.")
128
+
129
+ (defun mhc-draft-append-category (category)
130
+ "Append CATEGORY if it is not contained yet."
131
+ (mhc-header-narrowing
132
+ (let ((categories (mhc-header-get-value "x-sc-category")))
133
+ (unless (string-match category categories)
134
+ (mhc-header-put-value "x-sc-category"
135
+ (concat categories " " category))))))
136
+
137
+ (defun mhc-draft-in-category-p (category)
138
+ (mhc-header-narrowing
139
+ (string-match (concat "[ \t]*" category)
140
+ (mhc-header-get-value "x-sc-category"))))
141
+
142
+ (defun mhc-draft-delete-category (category)
143
+ "Delete CATEGORY if it is contained."
144
+ (mhc-header-narrowing
145
+ (let ((categories (mhc-header-get-value "x-sc-category")))
146
+ (when (string-match (concat "[ \t]*" category) categories)
147
+ (setq categories (concat
148
+ (substring categories 0 (match-beginning 0))
149
+ (substring categories (match-end 0))))
150
+ (when (string-match "[ \t]+$" categories)
151
+ (setq categories (substring categories 0 (match-beginning 0))))
152
+ (mhc-header-put-value "X-SC-Category" categories)))))
153
+
154
+ (defun mhc-draft-increment-sequence ()
155
+ "Increment X-SC-Sequence in mhc-draft buffer."
156
+ (mhc-header-narrowing
157
+ (let ((sequence (or (mhc-header-get-value "x-sc-sequence") "0")))
158
+ (mhc-header-put-value "x-sc-sequence"
159
+ (1+ (string-to-number sequence))))))
160
+
161
+ (defun mhc-draft-finish ()
162
+ "Add current draft as a schedule."
163
+ (interactive)
164
+ (let ((record
165
+ (mhc-parse-buffer (mhc-record-new mhc-draft-buffer-file-name)
166
+ 'strict)))
167
+ (mhc-calendar-input-exit)
168
+ (if (mhc-db-add-record-from-buffer record (current-buffer)
169
+ (not (called-interactively-p 'interactive)))
170
+ (progn
171
+ (kill-buffer (current-buffer))
172
+ (mhc-window-pop)
173
+ (or (and (mhc-summary-buffer-p)
174
+ (mhc-rescan-month mhc-default-hide-private-schedules))
175
+ (and (mhc-calendar-p) (mhc-calendar-rescan)))
176
+ (run-hooks 'mhc-draft-finish-hook)))))
177
+
178
+ (provide 'mhc-draft)
179
+
180
+ ;;; Copyright Notice:
181
+
182
+ ;; Copyright (C) 1999, 2000 Yoshinari Nomura. All rights reserved.
183
+ ;; Copyright (C) 2000 MHC developing team. All rights reserved.
184
+
185
+ ;; Redistribution and use in source and binary forms, with or without
186
+ ;; modification, are permitted provided that the following conditions
187
+ ;; are met:
188
+ ;;
189
+ ;; 1. Redistributions of source code must retain the above copyright
190
+ ;; notice, this list of conditions and the following disclaimer.
191
+ ;; 2. Redistributions in binary form must reproduce the above copyright
192
+ ;; notice, this list of conditions and the following disclaimer in the
193
+ ;; documentation and/or other materials provided with the distribution.
194
+ ;; 3. Neither the name of the team nor the names of its contributors
195
+ ;; may be used to endorse or promote products derived from this software
196
+ ;; without specific prior written permission.
197
+ ;;
198
+ ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS''
199
+ ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
200
+ ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
201
+ ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
202
+ ;; THE TEAM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
203
+ ;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
204
+ ;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
205
+ ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
206
+ ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
207
+ ;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
208
+ ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
209
+ ;; OF THE POSSIBILITY OF SUCH DAMAGE.
210
+
211
+ ;;; mhc-draft.el ends here