mhc 1.2.3 → 1.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 650db4a5196f97fe4edc81028a8eaa77be9914fbe3d3ea1c5d27b3b0fe790cbe
4
- data.tar.gz: a164d3c77a6aa6dbce5aa702158a70c9a558b6c11023dd282a14a535234ee7d7
3
+ metadata.gz: b0b65ae5e1dd5f504de2eeb59f280eff7ef0422133520006e9814ab52510e9ac
4
+ data.tar.gz: '0168de3d55867bf8356a02cf9be81d3ecd199b01f64d5c2cdc5f6835a0605fdd'
5
5
  SHA512:
6
- metadata.gz: 61edc1a0f6c05b05af51a84c9dcb40425eab9ff217f37017f8c1d9e2000c12e0c086f63fbc5a5da87e7367ceb28b5fa40657311a1d08dc0e09298f743f9629d7
7
- data.tar.gz: 7221e67e855a6658922a81482875cd92ddb6250aa89f07a671e04175a0d158a2918a68b820c04a76326aa8760fc08808515590658d4439f21c95859bc668bafe
6
+ metadata.gz: d4533cef977bafd8491f1f3bbb709049dfa17b7ca70f0286381aaba60ffb51a096d34b28d6cb7239e1a5f932729237dce1d931332c1830983357ec99196f75e5
7
+ data.tar.gz: 40dbdfcdcacf2ac4f274db2897bfa91f25a58ebb0d80c4b705d9134efef3e2fafa7e1ec51a743817e075e7a0f015b53262a6c3c1f915400ce5e0dd5dad31727d
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  .bundle
6
6
  .config
7
7
  .yardoc
8
- Gemfile.lock
8
+ Gemfile.lock*
9
9
  InstalledFiles
10
10
  _yardoc
11
11
  attic/
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Style/RedundantReturn:
2
+ Enabled: false
3
+ Style/CommentedKeyword:
4
+ Enabled: false
5
+ Style/Documentation:
6
+ Enabled: false
7
+ Style/RedundantSelf:
8
+ Enabled: false
9
+ Style/StringLiterals:
10
+ Enabled: false
11
+ Metrics/MethodLength:
12
+ Enabled: false
13
+ Metrics/ClassLength:
14
+ Enabled: false
data/README.org CHANGED
@@ -127,6 +127,7 @@
127
127
  | =M= | Open pointed article to edit |
128
128
  | =D= | Delete pointed article |
129
129
  | =C= | Copy article temporally as a reusable template |
130
+ | =R= | Copy article like =C= using completing-read |
130
131
  | =Y= | Same as =E= but use the template stored by =C= |
131
132
 
132
133
  3) Draft Buffer
@@ -149,6 +150,7 @@
149
150
  X-SC-Time: 18:00-21:00
150
151
  X-SC-Category: Private Party
151
152
  X-SC-Cond:
153
+ X-SC-Recurrence-Tag: HomeParty
152
154
  X-SC-Duration:
153
155
  X-SC-Record-Id: C34D89F5-27FA-4243-AC6C-168D8D243D9A
154
156
  X-SC-Sequence: 0
@@ -241,6 +243,40 @@
241
243
  of 2015-07-15 (Wed) and inclusion of 2015-08-01 (Sat).
242
244
  #+END_EXAMPLE
243
245
 
246
+ ** Headers for Grouping
247
+ *** X-SC-Category
248
+ =X-SC-Category:= is a space separated list of category
249
+ It is useful for selective display both in CLI:
250
+ : mhc scan today --category=Private
251
+ and Emacs UI:
252
+ : M-x mhc-set-default-category
253
+ : Default Category: Private && !Party
254
+
255
+ Also useful sync with Google Calendar. See [[https://github.com/yoshinari-nomura/mhc/blob/master/samples/DOT.mhc-config.yml][mhc-config.yml]] for
256
+ details.
257
+
258
+ *** X-SC-Recurrence-Tag
259
+ =X-SC-Recurrence-Tag:= is a tag for bundling multiple event articles as one recurring group.
260
+
261
+ MHC allows flexible description of repeating events using
262
+ =X-SC-Cond:=, =X-SC-Duration:=, or =X-SC-Day:=. However, we know
263
+ this is not sufficient.
264
+
265
+ For example, in my experience, some monthly meetings do not have
266
+ distinct recurring patterns such like "Third Wednesday of each
267
+ month." Instead, the next date is fixed by coordination during the meeting.
268
+
269
+ In such cases, it is difficult to mark these events as a series of related events.
270
+ That's why we need =X-SC-Recurrence-Tag:=
271
+
272
+ Using =X-SC-Recurrence-Tag:=, MHC suggests what event should be arranged.
273
+ : mhc stuck_recurrences
274
+ will tell you to make the next appointment.
275
+
276
+ For example, if you have "X-SC-Recurrence-Tag: Dentist" in your
277
+ articles of past dentist events, mhc will point out that you
278
+ forgot to make your next dentist appointment.
279
+
244
280
  * INFORMATION FOR DEVELOPERS
245
281
  ** INSTALL for developers:
246
282
  1) Install rbenv + ruby-build
@@ -326,6 +362,7 @@
326
362
  (setq load-path
327
363
  (cons "~/src/mhc/emacs" load-path))
328
364
  (autoload 'mhc "mhc" "Message Harmonized Calendar system." t)
365
+ (autoload 'mhc-import "mhc" "Import a schedule." t)
329
366
 
330
367
  ;; M-x mhc
331
368
  #+END_SRC
data/bin/mhc CHANGED
@@ -72,9 +72,10 @@ class MhcCLI < Thor
72
72
  register_option :repository, :desc => "Set MHC top directory", :banner => "DIRECTORY"
73
73
  register_option :calendar, :desc => "Set source CALENDAR"
74
74
  register_option :category, :desc => "Pick items only in CATEGORY"
75
- register_option :format, :desc => "Set printing format", :enum => %w(text mail orgtable emacs icalendar calfw howm json)
75
+ register_option :format, :desc => "Set printing format", :enum => %w(text mail orgtable emacs icalendar calfw howm json html)
76
76
  register_option :search, :desc => "Search items by complex expression"
77
77
  register_option :dry_run, :desc => "Perform a trial run with no changes made", :type => :boolean
78
+ register_option :verbose, :desc => "Show verbose message", :type => :boolean
78
79
 
79
80
  ################################################################
80
81
  # command name mappings
@@ -113,13 +114,16 @@ class MhcCLI < Thor
113
114
  Mhc::Command::Cache.new(builder.datastore)
114
115
  end
115
116
 
117
+ ################################################################
116
118
  # Command: todo
119
+ ################################################################
117
120
  desc "todo", "List Todo entries in MHC calendar"
118
121
 
119
122
  named_option :repository
120
123
  method_option :show_all, :desc => "Include all finished tasks."
121
124
 
122
125
  def todo
126
+ todos = []
123
127
  calendar.tasks.each do |task|
124
128
  if task.recurring?
125
129
  # Yearly: today - 90days .. today + 365d - 90days ?
@@ -130,9 +134,25 @@ class MhcCLI < Thor
130
134
  search_range = nil
131
135
  end
132
136
  next if task.in_category?("done") && !options[:show_all]
133
- occurrence = task.occurrences(range: search_range).first
134
- deadline = occurrence.dtstart
135
- puts format("%s %s", deadline.strftime("%Y/%m/%d %a"), task.subject)
137
+ task_first = task.occurrences(range: search_range).first
138
+ todos << task_first if task_first
139
+ end
140
+ todos.each.sort{|a, b| a.dtstart <=> b.dtstart}.each do |t|
141
+ deadline = t.dtstart
142
+ deadline_string = ""
143
+ remaining = (deadline - Mhc::PropertyValue::Date.today).to_i
144
+ if remaining == 0
145
+ deadline_string = " (due this date)"
146
+ elsif remaining > 0
147
+ deadline_string = format(" (%d days to go)", remaining)
148
+ else
149
+ deadline_string = format(" (%d days overdue)", -remaining)
150
+ end
151
+ location_string = " [#{t.location}]" if !t.location.empty?
152
+ puts format("%s %-11s %s%s%s",
153
+ deadline.strftime("%Y/%m/%d %a"),
154
+ t.time_range.to_mhc_string,
155
+ t.subject, location_string, deadline_string)
136
156
  end
137
157
  end # todo
138
158
 
@@ -152,6 +172,38 @@ class MhcCLI < Thor
152
172
  Mhc::Command::Completions.new(help, global_options, command, config)
153
173
  end
154
174
 
175
+ ################################################################
176
+ # Command: compose
177
+ ################################################################
178
+ desc "compose", "Create new draft and open it in your editor"
179
+
180
+ long_desc <<-LONGDESC
181
+ Create a new draft and open it in your editor.
182
+ To select your favorite editor,
183
+ set environment variable MHC_EDITOR or EDITOR.
184
+ LONGDESC
185
+
186
+ def compose
187
+ require 'securerandom'
188
+ ev = Mhc::Event.new
189
+ ev.record_id = SecureRandom.uuid.upcase
190
+ path = builder.datastore.create(ev, true)
191
+ puts "Create draft #{path}"
192
+ editor = ENV["MHC_EDITOR"] || ENV["EDITOR"] || "vi"
193
+ system(editor, path)
194
+
195
+ while add(path) != 0
196
+ if ask("Retry?") =~ /^[Yy]/
197
+ system(editor, path)
198
+ else
199
+ puts "Abort..."
200
+ exit(1)
201
+ end
202
+ end
203
+ puts "Successfully registered."
204
+ exit(0)
205
+ end
206
+
155
207
  ################################################################
156
208
  # Command: config
157
209
  ################################################################
@@ -163,6 +215,40 @@ class MhcCLI < Thor
163
215
  puts Mhc::Converter::Emacs.new.to_emacs(config.get_value(name))
164
216
  end
165
217
 
218
+ ################################################################
219
+ # Command: add
220
+ ################################################################
221
+ desc "add FILE", "Add event FILE to repository"
222
+
223
+ named_option :repository
224
+
225
+ def add(file)
226
+ full_path = File.expand_path(file)
227
+
228
+ unless File.exist?(full_path)
229
+ puts Mhc::Converter::Emacs.new.to_emacs("No such file #{file}.")
230
+ return 1
231
+ end
232
+
233
+ event_string = File.open(full_path).read
234
+ errors = Mhc::Event.validate(event_string)
235
+
236
+ if errors.empty?
237
+ ev = Mhc::Event.parse(event_string)
238
+ calendar.add(ev)
239
+ return 0
240
+ else
241
+ string = ""
242
+ errors.each do |err, key|
243
+ string += "#{err.to_s.capitalize}"
244
+ string += " in X-SC-#{key.capitalize}" if key
245
+ string += ".\n"
246
+ end
247
+ puts string
248
+ return 1
249
+ end
250
+ end
251
+
166
252
  ################################################################
167
253
  # Command: init
168
254
  ################################################################
@@ -172,6 +258,55 @@ class MhcCLI < Thor
172
258
  Mhc::Command::Init.new(top_dir, options[:config] || DEFAULT_CONFIG_PATH, ENV["MHC_TZID"])
173
259
  end
174
260
 
261
+ ################################################################
262
+ # Command: stuck_recurrences
263
+ ################################################################
264
+ desc "stuck_recurrences", "List stuck recurrences in MHC calendar"
265
+
266
+ named_option :repository
267
+ named_option :verbose
268
+ named_option :format
269
+
270
+ # * stuck_recurrences
271
+ #
272
+ # For all "living recurrences", if no next event has been set in
273
+ # the "future", show the information on the last time.
274
+ #
275
+ # + "living recurrences" ::
276
+ # + There is a last-time evnet within a year and a half.
277
+ # + "future" :: ten years from now.
278
+ #
279
+ def stuck_recurrences(format = options[:format])
280
+ today = Mhc::PropertyValue::Date.today
281
+
282
+ # Seek -1.5y to +10y
283
+ search_range = (today - ((365 * 5).to_i)) ..
284
+ (today + ((365 * 10).to_i))
285
+
286
+ recurrences = {}
287
+
288
+ # Get all recurrences in search_range
289
+ calendar.occurrences(search_range).each do |oc|
290
+ rtag = oc.recurrence_tag.to_s
291
+ next if rtag.empty?
292
+ recurrences[rtag] ||= []
293
+ recurrences[rtag] << oc
294
+ end
295
+
296
+ formatter = Mhc::Formatter.build(formatter: format || :text, date_range: search_range)
297
+
298
+ recurrences.each do |rtag, recurrence|
299
+ if options[:verbose]
300
+ rec_put_debug(recurrence)
301
+ else
302
+ formatter << recurrence.last if rec_stuck?(recurrence)
303
+ end
304
+ end
305
+ str = formatter.to_s
306
+ return str if format == :json || options[:verbose]
307
+ puts str
308
+ end # stuck_recurrences
309
+
175
310
  ################################################################
176
311
  # Command: scan
177
312
  ################################################################
@@ -206,6 +341,9 @@ class MhcCLI < Thor
206
341
  named_option :calendar, :category, :format, :repository, :search
207
342
 
208
343
  def scan(range)
344
+ if options[:format].to_s == 'html'
345
+ $stuck_recurrences_json = stuck_recurrences(:json)
346
+ end
209
347
  begin
210
348
  Mhc::Command::Scan.new(calendar, range, **symbolize_keys(options))
211
349
  rescue Mhc::PropertyValue::ParseError, Mhc::Formatter::NameError, Mhc::Query::ParseError => e
@@ -310,6 +448,80 @@ class MhcCLI < Thor
310
448
 
311
449
  private
312
450
 
451
+ def rec_put_debug(recurrence)
452
+ ol = recurrence.last
453
+
454
+ today = Mhc::PropertyValue::Date.today
455
+ last_occurrence = recurrence.last
456
+ last_occurrence_date = last_occurrence.dtstart.to_date
457
+ # Ignore living recurrences
458
+ return false if last_occurrence_date > today
459
+
460
+ status = if rec_stuck?(recurrence) then " TODO" else "" end
461
+ print "*#{status} #{ol.recurrence_tag}#{status} "
462
+
463
+ print format("%s %s",
464
+ ol.dtstart.strftime("%Y-%m-%d %a"),
465
+ ol.subject)
466
+
467
+ print format(" (length: %d, max: %d, min: %d, avr: %d)\n",
468
+ recurrence.length,
469
+ *rec_stat(recurrence))
470
+
471
+ pr = recurrence.first
472
+ recurrence.each do |oc|
473
+ puts format(" %s %s (%d)",
474
+ oc.dtstart.strftime("%Y-%m-%d %a"),
475
+ oc.subject,
476
+ (oc.dtstart.to_date - pr.dtstart.to_date).to_i
477
+ )
478
+ pr = oc
479
+ end
480
+ end
481
+
482
+ # Judge if a recurrence is stuck or not. recurrence is a set of occurrences.
483
+ def rec_stuck?(recurrence, today = Mhc::PropertyValue::Date.today)
484
+ last_occurrence = recurrence.last
485
+ last_occurrence_date = last_occurrence.dtstart.to_date
486
+ max_interval, _min_interval, avr_interval = rec_stat(recurrence)
487
+
488
+ # Not stuck if scheduled in the future dates
489
+ return false if last_occurrence_date > today
490
+
491
+ # Stuck if last event occurred within 90 days, but average
492
+ # interval is less than 60 days.
493
+ if (today - last_occurrence_date).to_i < 90 && avr_interval < 60
494
+ return true
495
+ end
496
+
497
+ # Not stuck if the number of days between the last event and today
498
+ # does not reach 80% of the maximum interval.
499
+ return false if (today - last_occurrence_date).to_i < max_interval * 4 / 5
500
+
501
+ # Not stuck if the number of days between the last event and today
502
+ # is more than 30 days or 1.5 years beyond the maximum interval.
503
+ # It would be no more recurring.
504
+ return false if (today - last_occurrence_date).to_i > [max_interval + 30, 365*1.5].min
505
+
506
+ # Otherwise, stuck
507
+ return true
508
+ end
509
+
510
+ # Return statistics on recurrences: max/min/average interval.
511
+ def rec_stat(recurrence)
512
+ # Calcurate all intervals of the recurrence
513
+ intervals = recurrence.each_cons(2).map{|ocs|
514
+ (ocs[1].dtstart.to_date - ocs[0].dtstart.to_date).to_i
515
+ }.reject{|interval| interval < 1}
516
+
517
+ # Assume annual event if the recurrence is one-shot.
518
+ intervals = [365] if intervals.empty?
519
+
520
+ return [intervals.max,
521
+ intervals.min,
522
+ intervals.reduce(0, :+) / intervals.length]
523
+ end
524
+
313
525
  def exit_on_error(&block)
314
526
  begin
315
527
  yield if block_given?
data/emacs/Cask CHANGED
@@ -5,7 +5,7 @@
5
5
  (source org)
6
6
  (source melpa)
7
7
 
8
- (package "mhc" "1.2.3" "Message Harmonized Calendaring system") ;; MHC_VERSION
8
+ (package "mhc" "1.2.5" "Message Harmonized Calendaring system") ;; MHC_VERSION
9
9
 
10
10
  (files "mhc.el" "mhc-*.el")
11
11
 
data/emacs/mhc-date.el CHANGED
@@ -411,17 +411,10 @@
411
411
  `(/ (1- (mhc-date-dd ,date)) 7))
412
412
 
413
413
  (defsubst mhc-date-cw (date)
414
- (mhc-date-let date
415
- (let* ((yday (mhc-date/day-number yy mm dd))
416
- (days (mhc-date/iso-week-days yday ww))
417
- (d))
418
- (if (< days 0)
419
- (setq days (mhc-date/iso-week-days
420
- (+ yday 365 (if (mhc-date/leap-year-p (1- yy)) 1 0)) ww))
421
- (setq d (mhc-date/iso-week-days
422
- (- yday 365 (if (mhc-date/leap-year-p yy) 1 0)) ww))
423
- (if (<= 0 d) (setq days d)))
424
- (1+ (/ days 7)))))
414
+ (string-to-number
415
+ (format-time-string
416
+ (if (= mhc-start-day-of-week 1) "%V" "%U")
417
+ (mhc-date-to-second date))))
425
418
 
426
419
  ;;
427
420
  ;; compare.
data/emacs/mhc-db.el CHANGED
@@ -34,6 +34,12 @@ If optional SEARCH is non-nil returned value is clipped by search string."
34
34
  (if category (format " --category=%s" category) "")
35
35
  (if search (format " --search='%s'" search) ""))))
36
36
 
37
+ (defun mhc-db-stuck-recurrences ()
38
+ "List stuck recurrences in MHC calendar."
39
+ (mhc-db-flatten
40
+ (mhc-process-send-command
41
+ (format "stuck_recurrences --format=emacs"))))
42
+
37
43
  (defun mhc-db-scan-flat (begin-date end-date &optional nosort category search)
38
44
  "Scan MHC database from BEGIN-DATE to END-DATE.
39
45
  Unlike `mhc-db-scan`, returned value is not grouped by date.
@@ -42,19 +48,48 @@ For example:
42
48
  If optional NOSORT is non-nil, returned value is not sort.
43
49
  If optional CATEGORY is non-nil, returned value is clipped by category.
44
50
  If optional SEARCH is non-nil returned value is clipped by search string."
45
- (let ((dayinfo-list (mhc-db-scan begin-date end-date nosort category search)))
46
- (apply 'append
47
- (mapcar (lambda (dayinfo)
48
- (let ((date (mhc-day-date dayinfo))
49
- (schedules (mhc-day-schedules dayinfo)))
50
- (mapcar (lambda (sch) (cons date sch)) schedules)))
51
- dayinfo-list))))
51
+ (mhc-db-flatten (mhc-db-scan begin-date end-date nosort category search)))
52
+
53
+ (defun mhc-db-flatten (dayinfo-list)
54
+ "Flatten DAYINFO-LIST scanned from `mhc-db-scan`.
55
+ Unlike `mhc-db-scan`, returned value is not grouped by date."
56
+ (apply 'append
57
+ (mapcar (lambda (dayinfo)
58
+ (let ((date (mhc-day-date dayinfo))
59
+ (schedules (mhc-day-schedules dayinfo)))
60
+ (mapcar (lambda (sch) (cons date sch)) schedules)))
61
+ dayinfo-list)))
52
62
 
53
63
  (defun mhc-db-search (&rest query)
54
64
  (let ((b (mhc-date-new 1970 1 1))
55
65
  (e (mhc-date-yy+ (mhc-date-now) 10)))
56
66
  (mhc-db-scan b e nil nil (mhc-db/query-to-search-string query))))
57
67
 
68
+ (defun mhc-db-past-occurrences (&optional days)
69
+ (let ((now (mhc-date-now)))
70
+ (nreverse
71
+ (mhc-db-scan-flat (mhc-date- now (or days 732)) now))))
72
+
73
+ (defun mhc-db-make-completion-list (occurrences)
74
+ (delq nil
75
+ (mapcar
76
+ (lambda (occurrence)
77
+ (let ((sch (cdr occurrence)))
78
+ (if (not (string= (mhc-record-name (mhc-schedule-record sch)) ""))
79
+ (cons (mhc-db-real-to-display occurrence) occurrence))))
80
+ occurrences)))
81
+
82
+ (defun mhc-db-real-to-display (occurrence)
83
+ (let* ((date (car occurrence))
84
+ (sch (cdr occurrence))
85
+ (location (mhc-schedule-location sch)))
86
+ (concat
87
+ (mhc-date-format date "%04d/%02d/%02d" yy mm dd)
88
+ (format " %11s " (mhc-schedule-time-as-string sch))
89
+ (mhc-schedule-subject sch)
90
+ (if (and location (not (string= location "")))
91
+ (format " [%s]" location)))))
92
+
58
93
  (defun mhc-db/quote-string (string)
59
94
  (format "\"%s\"" string))
60
95
 
data/emacs/mhc-record.el CHANGED
@@ -54,7 +54,7 @@
54
54
 
55
55
  (defun mhc-record-create-id ()
56
56
  "Return unique ID string."
57
- (org-id-new))
57
+ (upcase (org-id-new)))
58
58
 
59
59
  (defun mhc-record-new (name &optional id schedules sexp)
60
60
  "Constructer of MHC-RECORD structure."
data/emacs/mhc-summary.el CHANGED
@@ -294,9 +294,10 @@ If optional argument FOR-DRAFT is non-nil, Hilight message as draft message."
294
294
  (set-visited-file-name nil)
295
295
  ;; (rename-buffer (file-name-nondirectory file) 'unique)
296
296
  ;; (run-hooks 'mhc-calendar-view-file-hook)
297
+ (let ((buffer-read-only nil))
298
+ (mhc-message-mode))
297
299
  (set-buffer-modified-p nil)
298
300
  (setq buffer-read-only t)
299
- (mhc-message-mode)
300
301
  (mhc-message-set-file-name file)
301
302
  )))
302
303
 
@@ -356,7 +357,8 @@ message and cdr keeps a visible message."
356
357
  (or (null (setq dayinfo
357
358
  (get-text-property (point) 'mhc-dayinfo)))
358
359
  (not (eq (mhc-day-date dayinfo) date))))
359
- (goto-char (next-single-property-change (point) 'mhc-dayinfo)))))
360
+ (goto-char (or (next-single-property-change (point) 'mhc-dayinfo)
361
+ (point-min))))))
360
362
 
361
363
  (defun mhc-summary-record (&optional mailer)
362
364
  "Return record on current line."
@@ -632,6 +634,7 @@ If BANNER is set, it is printed on the horizontal line."
632
634
  (define-key mhc-summary-mode-map "E" 'mhc-edit)
633
635
  (define-key mhc-summary-mode-map "M" 'mhc-modify)
634
636
  (define-key mhc-summary-mode-map "C" 'mhc-reuse-copy)
637
+ (define-key mhc-summary-mode-map "R" 'mhc-reuse-past-event)
635
638
  (define-key mhc-summary-mode-map "Y" 'mhc-reuse-create)
636
639
 
637
640
  (define-key mhc-summary-mode-map "n" 'mhc-summary-display-next)
data/emacs/mhc-vars.el CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
  ;;; Constants:
21
- (defconst mhc-version "mhc 1.2.3") ;; MHC_VERSION
21
+ (defconst mhc-version "mhc 1.2.5") ;; MHC_VERSION
22
22
 
23
23
 
24
24
  ;;; Configration Variables:
data/emacs/mhc.el CHANGED
@@ -3,7 +3,7 @@
3
3
  ;; Description: Message Harmonized Calendaring system.
4
4
  ;; Author: Yoshinari Nomura <nom@quickhack.net>
5
5
  ;; Created: 1994-07-04
6
- ;; Version: 1.2.3
6
+ ;; Version: 1.2.5
7
7
  ;; Keywords: calendar
8
8
  ;; URL: http://www.quickhack.net/mhc
9
9
  ;; Package-Requires: ((calfw "20150703"))
@@ -19,13 +19,14 @@
19
19
  ;;
20
20
  ;; (setq load-path
21
21
  ;; (cons "~/src/mhc/emacs" load-path))
22
- ;; (autoload 'mhc "mhc")
22
+ ;; (autoload 'mhc "mhc" nil t)
23
+ ;; (autoload 'mhc-import "mhc" nil t)
23
24
  ;;
24
25
  ;; and M-x mhc
25
26
 
26
27
  ;;; Code:
27
28
 
28
- (eval-when-compile (require 'cl))
29
+ (eval-when-compile (require 'cl-lib))
29
30
 
30
31
  ;; For Mule 2.3
31
32
  (eval-and-compile
@@ -325,10 +326,11 @@
325
326
  ret))))
326
327
 
327
328
  (defun mhc-expr-compile (string)
328
- (byte-compile
329
- `(lambda (schedule)
330
- ,(mhc-expr-parse string)
331
- )))
329
+ (let ((lexical-binding nil))
330
+ (byte-compile
331
+ `(lambda (schedule)
332
+ ,(mhc-expr-parse string)
333
+ ))))
332
334
 
333
335
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334
336
  ;;
@@ -796,6 +798,7 @@ Returns t if the importation was succeeded."
796
798
  :group 'mhc
797
799
  :type 'boolean)
798
800
 
801
+ ;;;###autoload
799
802
  (defun mhc-import (&optional get-original)
800
803
  "Import a schedule from the current article.
801
804
  The default action of this command is to import a schedule from the
@@ -912,6 +915,27 @@ the default action of this command is changed to the latter."
912
915
  (message "%s is copied." (mhc-record-subject-as-string record)))
913
916
  (message "No file here."))))
914
917
 
918
+ (defun mhc-reuse-past-event ()
919
+ "Select past schedule and copy to template."
920
+ (interactive)
921
+ (let* ((completion-ignore-case t)
922
+ (read-file-name-completion-ignore-case t)
923
+ (read-buffer-completion-ignore-case t)
924
+ (case-fold-search t)
925
+ (collection
926
+ (mhc-db-make-completion-list
927
+ (mhc-db-past-occurrences)))
928
+ (completion-table
929
+ (lambda (string pred action)
930
+ (if (eq action 'metadata)
931
+ '(metadata (display-sort-function . identity)
932
+ (cycle-sort-function . identity))
933
+ (complete-with-action action collection string pred))))
934
+ (key (completing-read "Select occurrence: " completion-table nil t))
935
+ (sch (cdr (cdr (assoc key collection)))))
936
+ (mhc-reuse-copy
937
+ (mhc-record-name (mhc-schedule-record sch)))))
938
+
915
939
  (defun mhc-modify ()
916
940
  "Modify the current schedule."
917
941
  (interactive)
data/lib/mhc/caldav.rb CHANGED
@@ -26,7 +26,7 @@ module Mhc
26
26
  D:propstat/D:prop/caldav:calendar-data
27
27
  ).map{|e| xmldoc.elements[e].text rescue nil}
28
28
 
29
- info.href = URI.unescape(href)
29
+ info.href = URI.decode_www_form_component(href)
30
30
  info.uid = File.basename(info.href, ".ics")
31
31
  info.status = status
32
32
  info.content_type = content_type
data/lib/mhc/calendar.rb CHANGED
@@ -23,6 +23,22 @@ module Mhc
23
23
  @datastore.entries(category: "todo")
24
24
  end
25
25
 
26
+ def recurrences(rec, &scope_block)
27
+ @datastore.entries(recurrence: rec)
28
+ end
29
+
30
+ def recurrence_tags
31
+ hash = {}
32
+ @datastore.entries.each do |ev|
33
+ tag = ev.recurrence_tag.to_s
34
+ next if tag == ""
35
+ next if hash[tag]
36
+
37
+ yield tag
38
+ hash[tag] = ev
39
+ end
40
+ end
41
+
26
42
  def occurrences(date_range, &scope_block)
27
43
  ocs = []
28
44
  @datastore.entries(range: date_range).each do |event|
@@ -34,6 +50,10 @@ module Mhc
34
50
  return ocs.sort
35
51
  end
36
52
 
53
+ def add(event)
54
+ @datastore.update(event)
55
+ end
56
+
37
57
  ################################################################
38
58
  ## for sync manager
39
59
 
@@ -95,7 +95,7 @@ module Mhc
95
95
  when "COMMAND"
96
96
  possible_commands
97
97
  when "RANGE"
98
- "(today tomorrow thismonth nextmonth)"
98
+ "(all today tomorrow thismonth nextmonth)"
99
99
  when /^NUM/
100
100
  "_guard '[0-9]#' 'Number'"
101
101
  else
data/lib/mhc/config.rb CHANGED
@@ -52,7 +52,11 @@ module Mhc
52
52
  end
53
53
 
54
54
  def self.create_from_yaml_string(yaml_string, filename = nil)
55
- hash = YAML.load(yaml_string, filename) || {}
55
+ hash = if YAML.respond_to?(:unsafe_load)
56
+ YAML.unsafe_load(yaml_string, filename: filename)
57
+ else
58
+ YAML.load(yaml_string, filename)
59
+ end || {}
56
60
  return new(hash)
57
61
  end
58
62