mhc 1.1.1 → 1.2.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 (48) hide show
  1. checksums.yaml +5 -5
  2. data/bin/mhc +66 -3
  3. data/emacs/Cask +1 -1
  4. data/emacs/mhc-date.el +1 -1
  5. data/emacs/mhc-day.el +1 -1
  6. data/emacs/mhc-db.el +57 -38
  7. data/emacs/mhc-draft.el +36 -22
  8. data/emacs/mhc-face.el +1 -1
  9. data/emacs/mhc-header.el +20 -1
  10. data/emacs/mhc-minibuf.el +12 -7
  11. data/emacs/mhc-parse.el +1 -1
  12. data/emacs/mhc-process.el +26 -9
  13. data/emacs/mhc-ps.el +1 -1
  14. data/emacs/mhc-schedule.el +5 -2
  15. data/emacs/mhc-summary.el +31 -12
  16. data/emacs/mhc-vars.el +15 -2
  17. data/emacs/mhc.el +50 -24
  18. data/lib/mhc.rb +3 -1
  19. data/lib/mhc/builder.rb +5 -1
  20. data/lib/mhc/calendar.rb +5 -1
  21. data/lib/mhc/command/cache.rb +5 -4
  22. data/lib/mhc/converter.rb +3 -2
  23. data/lib/mhc/datastore.rb +52 -13
  24. data/lib/mhc/date_enumerator.rb +2 -2
  25. data/lib/mhc/event.rb +42 -21
  26. data/lib/mhc/formatter.rb +17 -312
  27. data/lib/mhc/formatter/base.rb +125 -0
  28. data/lib/mhc/formatter/emacs.rb +47 -0
  29. data/lib/mhc/formatter/howm.rb +35 -0
  30. data/lib/mhc/formatter/icalendar.rb +17 -0
  31. data/lib/mhc/formatter/json.rb +27 -0
  32. data/lib/mhc/formatter/mail.rb +20 -0
  33. data/lib/mhc/formatter/org_table.rb +24 -0
  34. data/lib/mhc/formatter/symbolic_expression.rb +42 -0
  35. data/lib/mhc/formatter/text.rb +29 -0
  36. data/lib/mhc/occurrence.rb +27 -5
  37. data/lib/mhc/occurrence_enumerator.rb +1 -1
  38. data/lib/mhc/property_value.rb +6 -0
  39. data/lib/mhc/property_value/date.rb +23 -14
  40. data/lib/mhc/property_value/date_time.rb +19 -0
  41. data/lib/mhc/property_value/integer.rb +5 -1
  42. data/lib/mhc/property_value/list.rb +7 -6
  43. data/lib/mhc/property_value/period.rb +3 -1
  44. data/lib/mhc/property_value/range.rb +1 -1
  45. data/lib/mhc/property_value/time.rb +8 -1
  46. data/lib/mhc/version.rb +1 -1
  47. data/spec/mhc_spec.rb +83 -0
  48. metadata +13 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7c9ab546227bfcd6c56b48af0bd308d2219214c3
4
- data.tar.gz: 0ec52f413f4e033d96032450fcc07c75d7fa2d60
2
+ SHA256:
3
+ metadata.gz: 537f2bfe5826a0763c8c41fa53f6a035de6a796c7f515990b5cda8017b01e4ab
4
+ data.tar.gz: c264417ac39a7b1cdbf037378e2d67540861a48caeab5945a58adad350a24b00
5
5
  SHA512:
6
- metadata.gz: 70dbddc76e2f44969dc11cd233d402bc4de639ff1e5870c7044c6c8cad813149d342706f5040cce6ec642666828fdbe104d8dc50e76fb30f9bab57a00790ab5a
7
- data.tar.gz: ce91e6cbca1ca392399d259a21c5bab7247846fbe22611c1242fe5ee85f61439c5dcca8940bcfbf3651f34021146bdba669bfd0a700e606e3aac53bae3a53ed5
6
+ metadata.gz: 172010da102859b39e05ad9ba54f28c4faf8327e4a0c8cc30bed00599f1e8ba37bc36a7f752e24e959395066e3b32413f1b044f67cf00b4209dde455f79f783d
7
+ data.tar.gz: 0e6be200e4cd65828aba8a5e0216f3e641b3b351f430fe02de21cdd194248b66406fd859d97b82e0c590256687c7bf678091e49ec4b6da61e6b5f5f1ba981846
data/bin/mhc CHANGED
@@ -110,9 +110,32 @@ class MhcCLI < Thor
110
110
  named_option :repository
111
111
 
112
112
  def cache
113
- Mhc::Command::Cache.new(calendar)
113
+ Mhc::Command::Cache.new(builder.datastore)
114
114
  end
115
115
 
116
+ # Command: todo
117
+ desc "todo", "List Todo entries in MHC calendar"
118
+
119
+ named_option :repository
120
+ method_option :show_all, :desc => "Include all finished tasks."
121
+
122
+ def todo
123
+ calendar.tasks.each do |task|
124
+ if task.recurring?
125
+ # Yearly: today - 90days .. today + 365d - 90days ?
126
+ # Weekly: today - 7days .. today + 7days
127
+ search_range = Mhc::PropertyValue::Date.parse_range("today+365d")
128
+ # search_range = nil
129
+ else
130
+ search_range = nil
131
+ end
132
+ 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)
136
+ end
137
+ end # todo
138
+
116
139
  ################################################################
117
140
  # Command: completions
118
141
  ################################################################
@@ -185,7 +208,7 @@ class MhcCLI < Thor
185
208
  def scan(range)
186
209
  begin
187
210
  Mhc::Command::Scan.new(calendar, range, **symbolize_keys(options))
188
- rescue Mhc::PropertyValue::ParseError, Mhc::FormatterNameError, Mhc::Query::ParseError => e
211
+ rescue Mhc::PropertyValue::ParseError, Mhc::Formatter::NameError, Mhc::Query::ParseError => e
189
212
  STDERR.print "Error: " + e.message + "\n"
190
213
  end
191
214
  return self
@@ -236,6 +259,40 @@ class MhcCLI < Thor
236
259
  return self
237
260
  end
238
261
 
262
+ ################################################################
263
+ # Command: validate
264
+ ################################################################
265
+ desc "validate FILE", "Validate event FILE"
266
+
267
+ named_option :format
268
+
269
+ def validate(file)
270
+ full_path = File.expand_path(file)
271
+
272
+ unless File.exist?(full_path)
273
+ puts Mhc::Converter::Emacs.new.to_emacs("No such file #{file}.")
274
+ return 1
275
+ end
276
+
277
+ errors = Mhc::Event.validate(File.open(full_path) {|f| f.read})
278
+
279
+ string = ""
280
+ exit_on_error do
281
+ errors.each do |err, key|
282
+ string += "#{err.to_s.capitalize}"
283
+ string += " in X-SC-#{key.capitalize}" if key
284
+ string += ".\n"
285
+ end
286
+ end
287
+ if errors.empty?
288
+ puts Mhc::Converter::Emacs.new.to_emacs("OK")
289
+ return 0
290
+ end
291
+
292
+ puts Mhc::Converter::Emacs.new.to_emacs(string)
293
+ return 1
294
+ end
295
+
239
296
  ################################################################
240
297
  # add some hooks to Thor
241
298
 
@@ -312,4 +369,10 @@ class MhcCLI < Thor
312
369
  end
313
370
  end
314
371
 
315
- command = MhcCLI.start(ARGV)
372
+ result = MhcCLI.start(ARGV)
373
+
374
+ if result.is_a?(Numeric)
375
+ exit result
376
+ else
377
+ exit 0
378
+ end
data/emacs/Cask CHANGED
@@ -5,7 +5,7 @@
5
5
  (source org)
6
6
  (source melpa)
7
7
 
8
- (package "mhc" "1.1.1" "Message Harmonized Calendaring system") ;; MHC_VERSION
8
+ (package "mhc" "1.2.0" "Message Harmonized Calendaring system") ;; MHC_VERSION
9
9
 
10
10
  (files "mhc.el" "mhc-*.el")
11
11
 
@@ -646,4 +646,4 @@ If WKST is not specified, 0 (Sunday) is used."
646
646
  ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
647
647
  ;; OF THE POSSIBILITY OF SUCH DAMAGE.
648
648
 
649
- ;;; mhc-date.el ends here.
649
+ ;;; mhc-date.el ends here
@@ -146,4 +146,4 @@ This special form converts DAY, as the number of days since
146
146
  ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
147
147
  ;; OF THE POSSIBILITY OF SUCH DAMAGE.
148
148
 
149
- ;;; mhc-day.el ends here.
149
+ ;;; mhc-day.el ends here
@@ -1,4 +1,4 @@
1
- ;;; -*- mode: Emacs-Lisp; coding: utf-8 -*-
1
+ ;;; mhc-db.el --- Database Interface to MHC.
2
2
 
3
3
  ;; Author: Yoshinari Nomura <nom@quickhack.net>,
4
4
  ;; TSUCHIYA Masatoshi <tsuchiya@namazu.org>
@@ -18,18 +18,38 @@
18
18
  (require 'mhc-process)
19
19
  (require 'mhc-schedule)
20
20
 
21
- (defun mhc-db-scan (b e &optional nosort category search)
21
+ (defun mhc-db-scan (begin-date end-date &optional nosort category search)
22
+ "Scan MHC database from BEGIN-DATE to END-DATE.
23
+ If optional NOSORT is non-nil, returned value is not sort.
24
+ If optional CATEGORY is non-nil, returned value is clipped by category.
25
+ If optional SEARCH is non-nil returned value is clipped by search string."
22
26
  (mhc-process-send-command
23
27
  (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)
28
+ (mhc-date-yy begin-date)
29
+ (mhc-date-mm begin-date)
30
+ (mhc-date-dd begin-date)
31
+ (mhc-date-yy end-date)
32
+ (mhc-date-mm end-date)
33
+ (mhc-date-dd end-date)
30
34
  (if category (format " --category=%s" category) "")
31
35
  (if search (format " --search='%s'" search) ""))))
32
36
 
37
+ (defun mhc-db-scan-flat (begin-date end-date &optional nosort category search)
38
+ "Scan MHC database from BEGIN-DATE to END-DATE.
39
+ Unlike `mhc-db-scan`, returned value is not grouped by date.
40
+ For example:
41
+ ((date . mhc-schedule) (date . mhc-schedule) ...)
42
+ If optional NOSORT is non-nil, returned value is not sort.
43
+ If optional CATEGORY is non-nil, returned value is clipped by category.
44
+ 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))))
52
+
33
53
  (defun mhc-db-search (&rest query)
34
54
  (let ((b (mhc-date-new 1970 1 1))
35
55
  (e (mhc-date-yy+ (mhc-date-now) 10)))
@@ -60,32 +80,33 @@
60
80
  nosort
61
81
  category)))
62
82
 
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)))
83
+ (defun mhc-db-record-path-from-buffer (buffer)
84
+ "Return file path in MHC spool bound to BUFFER.
85
+ File path is taken from X-SC-Record-Id field."
86
+ (with-current-buffer buffer
87
+ (let ((spool-directory (file-name-as-directory
88
+ (expand-file-name
89
+ "spool" (mhc-config-base-directory))))
90
+ (record-id (mhc-draft-record-id)))
91
+ (expand-file-name (concat record-id ".mhc") spool-directory))))
92
+
93
+ (defun mhc-db-add-record-from-buffer (buffer &optional allow-overwrite)
94
+ "Add current mhc-draft BUFFER to MHC db.
95
+ If optional ALLOW-OVERWRITE is non-nil, do not ask overwrite."
96
+ (let* ((path (mhc-db-record-path-from-buffer buffer))
97
+ (directory (file-name-directory path))
98
+ (overwriting (file-exists-p path)))
99
+ (if (or (not overwriting)
100
+ allow-overwrite
101
+ (y-or-n-p (format "Overwrite existing %s? " path)))
102
+ (with-current-buffer buffer
103
+ (mhc-draft-increment-sequence)
104
+ (mhc-draft-translate)
105
+ (mhc-file-make-directory directory)
106
+ (mhc-write-region-as-coding-system
107
+ mhc-default-coding-system
108
+ (point-min) (point-max) path nil 'nomsg)
109
+ (set-buffer-modified-p nil)
89
110
  (mhc-misc-touch-directory directory)
90
111
  t))))
91
112
 
@@ -118,9 +139,7 @@
118
139
  (mhc-schedule-condition schedule))))
119
140
  " "))))
120
141
  (mhc-record-set-name record (mhc-record-name original-record))
121
- (mhc-db-add-record-from-buffer record (current-buffer))))))
122
-
123
-
142
+ (mhc-db-add-record-from-buffer (current-buffer) t)))))
124
143
 
125
144
  (provide 'mhc-db)
126
145
 
@@ -155,4 +174,4 @@
155
174
  ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
156
175
  ;; OF THE POSSIBILITY OF SUCH DAMAGE.
157
176
 
158
- ;;; mhc-db.el ends here.
177
+ ;;; mhc-db.el ends here
@@ -17,14 +17,10 @@
17
17
 
18
18
  (defconst mhc-draft-buffer-name "*mhc draft*")
19
19
 
20
- (defcustom mhc-draft-unuse-hdr-list
21
- '(">From " "From " "Delivered-To:" "Delivery-date:" "Envelope-to:"
22
- "Errors-To:" "Gnus-Warning:" "Lines:" "Posted:" "Precedence:" "Received:"
23
- "Replied:" "Return-Path:" "Sender:" "User-Agent:" "X-Bogosity:"
24
- "X-Dispatcher:" "X-Filter:" "X-Gnus-Mail-Source:" "X-Mailer:" "X-Received:"
25
- "X-Sender:" "X-Seqno:" "X-Spam-Flag:" "X-Spam-Probability:" "X-UIDL:"
26
- "Xref:")
27
- "*These headers are removed when article is imported."
20
+ (defcustom mhc-draft-import-header-list
21
+ '("Subject:" "From:" "To:" "Cc:" "Date:" "Message-Id:"
22
+ "X-GM-THRID:" "X-GM-MSGID:" "X-GM-LABELS:")
23
+ "*These headers are used when article is imported."
28
24
  :group 'mhc
29
25
  :type '(repeat string))
30
26
 
@@ -199,7 +195,7 @@ If optional argument NO-CONFIRM is non-nil, kill without confirmation."
199
195
  (defun mhc-draft-delete-garbage-headers ()
200
196
  (mhc-header-narrowing
201
197
  (mhc-header-delete-header
202
- (concat "^\\(" (mhc-regexp-opt mhc-draft-unuse-hdr-list) "\\)")
198
+ (concat "^\\(" (mhc-regexp-opt mhc-draft-import-header-list) "\\)")
203
199
  'regexp)))
204
200
 
205
201
  (defun mhc-draft-setup-headers (&optional headers-values)
@@ -217,22 +213,40 @@ HEADERS-VALUES is a list of cons-cell like: ((header-name . value) ...)."
217
213
  (mhc-header-put-value xsc ""))))
218
214
  xsc-headers))))
219
215
 
216
+ (defun mhc-draft-record-id ()
217
+ "Get X-SC-Record-Id header value in draft buffer."
218
+ (mhc-header-narrowing
219
+ (mhc-header-get-value "x-sc-record-id")))
220
+
221
+ (defun mhc-draft-validate-buffer (&optional buffer)
222
+ "Validate mhc draft BUFFER.
223
+ If BUFFER is omitted, current buffer will be validated."
224
+ (interactive)
225
+ (let ((validation (mhc-process-send-command-with-buffer
226
+ "validate --format=emacs"
227
+ (or buffer (current-buffer)))))
228
+ (if (and (stringp validation)
229
+ (string-match "^OK" validation))
230
+ (message "Validation passed.")
231
+ ;; \\' means end of string (not end of each line)
232
+ (error "ERROR: %s" (replace-regexp-in-string "[.\r\n]+\\'" "" validation)))))
233
+
220
234
  (defun mhc-draft-finish ()
221
235
  "Add current draft as a schedule."
222
236
  (interactive)
223
- (let ((record
224
- (mhc-parse-buffer (mhc-record-new mhc-draft-buffer-file-name)
225
- 'strict)))
226
- (mhc-calendar-input-exit)
227
- (if (mhc-db-add-record-from-buffer record (current-buffer)
228
- (not (called-interactively-p 'interactive)))
229
- (progn
230
- (kill-buffer (current-buffer))
231
- (mhc-window-pop)
232
- (or (and (mhc-summary-buffer-p)
233
- (mhc-rescan-month mhc-default-hide-private-schedules))
234
- (and (mhc-calendar-p) (mhc-calendar-rescan)))
235
- (run-hooks 'mhc-draft-finish-hook)))))
237
+ (mhc-draft-validate-buffer)
238
+ (mhc-calendar-input-exit)
239
+ (if (mhc-db-add-record-from-buffer
240
+ (current-buffer)
241
+ (not (called-interactively-p 'interactive)))
242
+ (progn
243
+ (kill-buffer (current-buffer))
244
+ (mhc-window-pop)
245
+ (or (and (mhc-summary-buffer-p)
246
+ (mhc-rescan-month mhc-default-hide-private-schedules))
247
+ (and (mhc-calendar-p) (mhc-calendar-rescan)))
248
+ (run-hooks 'mhc-draft-finish-hook)
249
+ (message "Successfully registered."))))
236
250
 
237
251
  (provide 'mhc-draft)
238
252
 
@@ -68,7 +68,7 @@ refer to mhc-calendar-hnf-face-alist-internal.")
68
68
  (1 font-lock-type-face)
69
69
  (2 font-lock-comment-face)
70
70
  (3 font-lock-builtin-face))
71
- ("\\(X-SC-\\(Subject\\|Location\\|Day\\|Time\\|Category\\|Priority\\|Recurrence-Tag\\|Mission-Tag:\\|Cond\\|Duration\\|Alarm\\|Record-Id\\|Sequence\\):\\)"
71
+ ("\\(X-SC-\\(Subject\\|Location\\|Day\\|Time\\|Category\\|Priority\\|Recurrence-Tag\\|Mission-Tag\\|Cond\\|Duration\\|Alarm\\|Record-Id\\|Sequence\\):\\)"
72
72
  (1 font-lock-keyword-face))
73
73
  ("\\(\\[End of message\\]\\)"
74
74
  (1 mhc-message-face-eof-marker))
@@ -63,6 +63,25 @@
63
63
  (memq (following-char) '(? ?\t)))))
64
64
 
65
65
 
66
+ (defun mhc-header-distill-header (header &optional regexp)
67
+ "Remove all headers except X-SC-* and HEADER.
68
+ If REGEXP is non-nil, HEADER is a regular expression."
69
+ (save-excursion
70
+ (let ((case-fold-search t)
71
+ (header-top)
72
+ (header-name)
73
+ (all-regexp "^[^:]+:")
74
+ (use-regexp (if regexp header (concat "^" (regexp-quote header) ":")))
75
+ (xsc-regexp (concat "^\\(" (mhc-regexp-opt (mhc-header-list)) "\\)")))
76
+ (goto-char (point-min))
77
+ (while (re-search-forward all-regexp nil t)
78
+ (setq header-top (match-beginning 0)
79
+ header-name (match-string 0))
80
+ (mhc-header-goto-end)
81
+ (unless (or (string-match use-regexp header-name)
82
+ (string-match xsc-regexp header-name))
83
+ (delete-region header-top (point)))))))
84
+
66
85
  (defun mhc-header-delete-header (header &optional regexp) "\
67
86
  Remove HEADER in the narrowed buffer.
68
87
  If REGEXP, HEADER is a regular expression."
@@ -177,4 +196,4 @@ If REGEXP, HEADER is a regular expression."
177
196
  ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
178
197
  ;; OF THE POSSIBILITY OF SUCH DAMAGE.
179
198
 
180
- ;;; mhc-header.el ends here.
199
+ ;;; mhc-header.el ends here
@@ -189,7 +189,7 @@
189
189
  (if (not (pos-visible-in-window-p b))
190
190
  (recenter))
191
191
  (if (not non-minibuf)
192
- (pop-to-buffer (window-buffer (minibuffer-window))))
192
+ (select-window (minibuffer-window)))
193
193
  ;; in minibuffer
194
194
  (if non-minibuf
195
195
  ()
@@ -254,12 +254,17 @@
254
254
  (mhc-date-format default
255
255
  "%04d/%02d/%02d" yy mm dd))
256
256
  ((listp default)
257
- (mapconcat
258
- (lambda (date)
259
- (mhc-date-format date
260
- "%04d/%02d/%02d" yy mm dd))
261
- default
262
- " "))
257
+ (let ((sep " ") (datelist default))
258
+ (if (null (cdr (last default)))
259
+ ()
260
+ (setq sep "-")
261
+ (setq datelist (list (car default) (cdr default))))
262
+ (mapconcat
263
+ (lambda (date)
264
+ (mhc-date-format date
265
+ "%04d/%02d/%02d" yy mm dd))
266
+ datelist
267
+ sep)))
263
268
  (t
264
269
  nil)))
265
270
  (current-buffer)
@@ -291,4 +291,4 @@
291
291
  ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
292
292
  ;; OF THE POSSIBILITY OF SUCH DAMAGE.
293
293
 
294
- ;;; mhc-parse.el ends here.
294
+ ;;; mhc-parse.el ends here
@@ -1,34 +1,51 @@
1
- (defvar mhc-process nil)
1
+ (require 'mhc-vars)
2
2
 
3
- (add-to-list 'process-coding-system-alist '("^mhc$" . utf-8))
3
+ (defvar mhc-process nil)
4
4
 
5
5
  (defun mhc-process-send-command (command)
6
6
  (unless (and (processp mhc-process)
7
7
  (eq (process-status mhc-process) 'run))
8
8
  (mhc-start-process))
9
- (message "COMMAND: %s" command)
10
9
  (with-current-buffer (process-buffer mhc-process)
11
10
  (delete-region (point-min) (point-max))
12
11
  (process-send-string mhc-process (concat command "\n"))
13
12
  (let ((i 1))
14
13
  (while (not (and (> (point-max) 1)
15
14
  (eq (char-after (1- (point-max))) ?\n)))
16
- (message (format "Waiting mhc process...%d" i))
15
+ (if (< 2 i) (message (format "Waiting mhc process...%d" i)))
17
16
  (setq i (1+ i))
18
17
  (accept-process-output mhc-process 0.5)))
19
18
  (read (buffer-substring (point-min) (1- (point-max))))))
20
19
 
20
+ (defun mhc-process-send-command-with-buffer (command buffer)
21
+ "Send COMMAND to mhc process with BUFFER via temporal file."
22
+ (let ((temp-file (make-temp-file "mhc")))
23
+ (unwind-protect
24
+ (with-current-buffer buffer
25
+ (mhc-write-region-as-coding-system
26
+ mhc-default-coding-system
27
+ (point-min)
28
+ (point-max)
29
+ temp-file
30
+ nil 'nomsg)
31
+ (mhc-process-send-command
32
+ (format "%s %s" command temp-file)))
33
+ (delete-file temp-file))))
34
+
21
35
  (defun mhc-start-process ()
22
36
  (interactive)
23
37
  (let ((process-connection-type nil)) ;; use PIPE not tty
24
38
  (if (and (processp mhc-process)
25
39
  (eq (process-status mhc-process) 'run))
26
40
  (kill-process mhc-process))
27
- (setq mhc-process (start-process
28
- "mhc"
29
- (get-buffer-create " *mhc-scan-process*")
30
- "mhc"
31
- "server"))
41
+ (setq mhc-process
42
+ (apply 'start-process
43
+ (delq nil `("mhc"
44
+ ,(get-buffer-create " *mhc-scan-process*")
45
+ ,mhc-ruby-program-name
46
+ ,mhc-program-name
47
+ "server"))))
48
+ (set-process-coding-system mhc-process 'utf-8 'utf-8)
32
49
  (set-process-query-on-exit-flag mhc-process nil)
33
50
  mhc-process))
34
51