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.
- checksums.yaml +7 -0
- data/.gitignore +27 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/COPYRIGHT +28 -0
- data/Gemfile +8 -0
- data/README.org +209 -0
- data/Rakefile +13 -0
- data/bin/mhc +312 -0
- data/emacs/Cask +25 -0
- data/emacs/Makefile +58 -0
- data/emacs/mhc-calendar.el +1723 -0
- data/emacs/mhc-calfw.el +135 -0
- data/emacs/mhc-compat.el +90 -0
- data/emacs/mhc-date.el +642 -0
- data/emacs/mhc-day.el +149 -0
- data/emacs/mhc-db.el +158 -0
- data/emacs/mhc-draft.el +211 -0
- data/emacs/mhc-e21.el +167 -0
- data/emacs/mhc-face.el +236 -0
- data/emacs/mhc-file.el +224 -0
- data/emacs/mhc-guess.el +648 -0
- data/emacs/mhc-header.el +176 -0
- data/emacs/mhc-logic.el +563 -0
- data/emacs/mhc-message.el +130 -0
- data/emacs/mhc-minibuf.el +466 -0
- data/emacs/mhc-misc.el +248 -0
- data/emacs/mhc-mua.el +260 -0
- data/emacs/mhc-parse.el +286 -0
- data/emacs/mhc-process.el +35 -0
- data/emacs/mhc-ps.el +1174 -0
- data/emacs/mhc-record.el +201 -0
- data/emacs/mhc-schedule.el +202 -0
- data/emacs/mhc-summary.el +763 -0
- data/emacs/mhc-sync.el +158 -0
- data/emacs/mhc-vars.el +149 -0
- data/emacs/mhc.el +1114 -0
- data/icons/Anniversary.xbm +6 -0
- data/icons/Anniversary.xpm +27 -0
- data/icons/Birthday.xbm +6 -0
- data/icons/Birthday.xpm +25 -0
- data/icons/Business.xbm +6 -0
- data/icons/Business.xpm +24 -0
- data/icons/CheckBox.xbm +6 -0
- data/icons/CheckBox.xpm +24 -0
- data/icons/CheckedBox.xbm +6 -0
- data/icons/CheckedBox.xpm +25 -0
- data/icons/Conflict.xbm +6 -0
- data/icons/Conflict.xpm +22 -0
- data/icons/Date.xbm +6 -0
- data/icons/Date.xpm +29 -0
- data/icons/Holiday.xbm +6 -0
- data/icons/Holiday.xpm +25 -0
- data/icons/Link.xbm +6 -0
- data/icons/Link.xpm +25 -0
- data/icons/Other.xbm +6 -0
- data/icons/Other.xpm +28 -0
- data/icons/Party.xbm +6 -0
- data/icons/Party.xpm +23 -0
- data/icons/Private.xbm +6 -0
- data/icons/Private.xpm +26 -0
- data/icons/Recurrence.xbm +6 -0
- data/icons/Recurrence.xpm +98 -0
- data/icons/Vacation.xbm +6 -0
- data/icons/Vacation.xpm +26 -0
- data/lib/mhc.rb +45 -0
- data/lib/mhc/builder.rb +64 -0
- data/lib/mhc/caldav.rb +304 -0
- data/lib/mhc/calendar.rb +106 -0
- data/lib/mhc/command.rb +13 -0
- data/lib/mhc/command/cache.rb +14 -0
- data/lib/mhc/command/completions.rb +108 -0
- data/lib/mhc/command/init.rb +133 -0
- data/lib/mhc/command/scan.rb +33 -0
- data/lib/mhc/command/sync.rb +22 -0
- data/lib/mhc/config.rb +229 -0
- data/lib/mhc/converter.rb +330 -0
- data/lib/mhc/datastore.rb +164 -0
- data/lib/mhc/date_enumerator.rb +274 -0
- data/lib/mhc/date_frame.rb +124 -0
- data/lib/mhc/date_helper.rb +49 -0
- data/lib/mhc/etag.rb +68 -0
- data/lib/mhc/event.rb +396 -0
- data/lib/mhc/formatter.rb +312 -0
- data/lib/mhc/logger.rb +94 -0
- data/lib/mhc/modifier.rb +149 -0
- data/lib/mhc/occurrence.rb +94 -0
- data/lib/mhc/occurrence_enumerator.rb +113 -0
- data/lib/mhc/property_value.rb +33 -0
- data/lib/mhc/property_value/date.rb +190 -0
- data/lib/mhc/property_value/integer.rb +15 -0
- data/lib/mhc/property_value/list.rb +41 -0
- data/lib/mhc/property_value/period.rb +49 -0
- data/lib/mhc/property_value/range.rb +100 -0
- data/lib/mhc/property_value/recurrence_condition.rb +272 -0
- data/lib/mhc/property_value/text.rb +11 -0
- data/lib/mhc/property_value/time.rb +45 -0
- data/lib/mhc/query.rb +210 -0
- data/lib/mhc/sync.rb +46 -0
- data/lib/mhc/sync/driver.rb +108 -0
- data/lib/mhc/sync/status.rb +70 -0
- data/lib/mhc/sync/status_manager.rb +142 -0
- data/lib/mhc/sync/strategy.rb +233 -0
- data/lib/mhc/sync/syncinfo.rb +98 -0
- data/lib/mhc/templates/config.yml.erb +142 -0
- data/lib/mhc/version.rb +4 -0
- data/lib/mhc/webdav.rb +319 -0
- data/mhc.gemspec +24 -0
- data/samples/DOT.mhc-config.yml +116 -0
- data/samples/japanese-holidays.mhcc +153 -0
- data/samples/mhc-completions.zsh +11 -0
- data/spec/mhc_spec.rb +682 -0
- data/spec/spec_helper.rb +9 -0
- data/xpm/close.xpm +18 -0
- data/xpm/delete.xpm +19 -0
- data/xpm/exit.xpm +18 -0
- data/xpm/month.xpm +18 -0
- data/xpm/next.xpm +18 -0
- data/xpm/next2.xpm +18 -0
- data/xpm/next_year.xpm +18 -0
- data/xpm/open.xpm +19 -0
- data/xpm/prev.xpm +18 -0
- data/xpm/prev2.xpm +18 -0
- data/xpm/prev_year.xpm +18 -0
- data/xpm/save.xpm +19 -0
- data/xpm/today.xpm +18 -0
- metadata +214 -0
data/emacs/Cask
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
;; -*- coding:utf-8 mode:lisp-interaction -*-
|
2
|
+
|
3
|
+
;; see: http://cask.readthedocs.org/en/latest/
|
4
|
+
|
5
|
+
(source org)
|
6
|
+
(source melpa)
|
7
|
+
|
8
|
+
(package "mhc"
|
9
|
+
"1.0.0" "Message Harmonized Calendaring system")
|
10
|
+
|
11
|
+
(files "mhc.el" "mhc-*.el")
|
12
|
+
|
13
|
+
(depends-on "org-plus-contrib")
|
14
|
+
(depends-on "htmlize")
|
15
|
+
(depends-on "calfw")
|
16
|
+
|
17
|
+
(development
|
18
|
+
(depends-on "f")
|
19
|
+
(depends-on "ecukes")
|
20
|
+
(depends-on "ert-runner")
|
21
|
+
(depends-on "el-mock"))
|
22
|
+
|
23
|
+
;; Local Variables:
|
24
|
+
;; flycheck-mode: nil
|
25
|
+
;; End:
|
data/emacs/Makefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- Makefile -*-
|
2
|
+
|
3
|
+
################################################################
|
4
|
+
## Use Emacs.app if available and anothr EMACS is not specified by user
|
5
|
+
|
6
|
+
COCOA_EMACS := /Applications/Emacs.app/Contents/MacOS/Emacs
|
7
|
+
|
8
|
+
ifneq ("$(wildcard $(COCOA_EMACS))", "")
|
9
|
+
EMACS ?= $(COCOA_EMACS)
|
10
|
+
else
|
11
|
+
EMACS ?= emacs
|
12
|
+
endif
|
13
|
+
|
14
|
+
################################################################
|
15
|
+
## Use cask if available and another CASK is not specified by user
|
16
|
+
|
17
|
+
CASK_VERSION := $(shell EMACS="$(EMACS)" cask --version 2>/dev/null)
|
18
|
+
|
19
|
+
ifdef CASK_VERSION
|
20
|
+
CASK ?= cask
|
21
|
+
endif
|
22
|
+
|
23
|
+
ifdef CASK
|
24
|
+
CASK_EXEC ?= exec
|
25
|
+
CASK_INSTALL ?= install
|
26
|
+
endif
|
27
|
+
|
28
|
+
################################################################
|
29
|
+
## cask, emacs and flags
|
30
|
+
|
31
|
+
COMPILER := $(CASK) $(CASK_EXEC) $(EMACS)
|
32
|
+
#FLAGS := -Q -batch -L . -L .cask/24.3.1/elpa/org-plus-contrib-20140922 -L .cask/24.3.1/elpa/calfw-20140407.2212 -l mhc
|
33
|
+
FLAGS := -Q -batch -L . -l mhc
|
34
|
+
ELFILES := $(wildcard *.el)
|
35
|
+
ELCFILES := $(ELFILES:el=elc)
|
36
|
+
|
37
|
+
################################################################
|
38
|
+
## Suffix rules
|
39
|
+
|
40
|
+
.SUFFIXES: .elc .el
|
41
|
+
|
42
|
+
.el.elc:
|
43
|
+
-rm -f $@
|
44
|
+
$(COMPILER) $(FLAGS) -f batch-byte-compile $<
|
45
|
+
|
46
|
+
################################################################
|
47
|
+
### Targets
|
48
|
+
|
49
|
+
all: setup build
|
50
|
+
|
51
|
+
build: $(ELCFILES)
|
52
|
+
# $(COMPILER) $(FLAGS) -f batch-byte-compile *.el
|
53
|
+
|
54
|
+
clean:
|
55
|
+
-rm -f *.elc auto-autoloads.el custom-load.el *~
|
56
|
+
|
57
|
+
setup:
|
58
|
+
$(CASK) $(CASK_INSTALL)
|
@@ -0,0 +1,1723 @@
|
|
1
|
+
;;; -*- emacs-lisp -*-
|
2
|
+
;; mhc-calendar.el -- MHC Mini calendar
|
3
|
+
;;
|
4
|
+
;; Author: Hideyuki SHIRAI <shirai@quickhack.net>
|
5
|
+
;; MIYOSHI Masanori <miyoshi@quickhack.net>
|
6
|
+
;;
|
7
|
+
;; Created: 05/12/2000
|
8
|
+
;; Reviesd: $Date: 2008/03/06 09:40:12 $
|
9
|
+
|
10
|
+
;;; Code:
|
11
|
+
|
12
|
+
;;; Configration Variables:
|
13
|
+
|
14
|
+
(require 'mhc-vars)
|
15
|
+
(require 'mhc-face)
|
16
|
+
(require 'mhc-e21)
|
17
|
+
|
18
|
+
(defcustom mhc-calendar-language 'english
|
19
|
+
"*Language of the calendar."
|
20
|
+
:group 'mhc
|
21
|
+
:type '(choice (const :tag "English" english)
|
22
|
+
(const :tag "Japanese" japanese)))
|
23
|
+
|
24
|
+
(defcustom mhc-calendar-separator ?|
|
25
|
+
"*Character of the separator between Summary and Vertical calendar."
|
26
|
+
:group 'mhc
|
27
|
+
:type 'character)
|
28
|
+
|
29
|
+
(defcustom mhc-calendar-use-cw nil
|
30
|
+
"*Displayed style of `Calendar week number'."
|
31
|
+
:group 'mhc
|
32
|
+
:type '(choice (const :tag "No" nil)
|
33
|
+
(const :tag "Month" month)
|
34
|
+
(const :tag "Week" week)))
|
35
|
+
|
36
|
+
(defcustom mhc-calendar-cw-indicator
|
37
|
+
(if (eq mhc-calendar-language 'japanese) "週" "Cw")
|
38
|
+
"*Indicator of Calendar week."
|
39
|
+
:group 'mhc
|
40
|
+
:type 'string)
|
41
|
+
|
42
|
+
(defcustom mhc-calendar-day-strings
|
43
|
+
(if (eq mhc-calendar-language 'japanese)
|
44
|
+
'["日" "月" "火" "水" "木" "金" "土"]
|
45
|
+
'["Su" "Mo" "Tu" "We" "Th" "Fr" "Sa"])
|
46
|
+
"*Vector of \"day of week\" for 3-month calendar header."
|
47
|
+
:group 'mhc
|
48
|
+
:type '(list string string string string string string string))
|
49
|
+
|
50
|
+
(defcustom mhc-calendar-header-function
|
51
|
+
(if (eq mhc-calendar-language 'japanese)
|
52
|
+
'mhc-calendar-make-header-ja
|
53
|
+
'mhc-calendar-make-header)
|
54
|
+
"*Function of \"make calendar header\" for 3-month calendar.
|
55
|
+
Assigned function must have one option \"date\"
|
56
|
+
and must return string like \" December 2000\"."
|
57
|
+
:group 'mhc
|
58
|
+
:type '(radio
|
59
|
+
(function-item :tag "English" mhc-calendar-make-header)
|
60
|
+
(function-item :tag "Japanese" mhc-calendar-make-header-ja)
|
61
|
+
(function :tag "Other")))
|
62
|
+
|
63
|
+
(defvar mhc-calendar-inserter-date-list
|
64
|
+
'(((yy mm02 dd02) . "-")
|
65
|
+
((yy "/" mm02 "/" dd02) . "-")
|
66
|
+
((mm02 "/" dd02 "/" yy "(" ww-string ")") . "-")
|
67
|
+
((yy "." mm02 "." dd02 "(" ww-string ")") . " - ")
|
68
|
+
((yy "-" mm02 "-" dd02 "(" ww-string ")") . " - ")
|
69
|
+
((dd02 "-" mm-string "-" yy "(" ww-string ")") . " - ")
|
70
|
+
((ww-string ", " dd02 " " mm-string " " yy) . " - ")
|
71
|
+
((yy "年" mm2 "月" dd2 "日(" ww-japanese ")") . ("〜" " - "))
|
72
|
+
((mm "月" dd2 "日(" ww-japanese ")") . ("〜" " - "))
|
73
|
+
((nengo mm2 "月" dd2 "日(" ww-japanese ")") . ("〜" " - ")))
|
74
|
+
"*List of date inserters.
|
75
|
+
Each cell has a cons cell, car slot has a format of 'date modifier funcitons'
|
76
|
+
and cdr slot has a which 'concatenate string' or its list for the duration.
|
77
|
+
E.g., if date equal \"Mon, 01 May 2000\", symbol return a string described below,
|
78
|
+
|
79
|
+
yy => \"2000\"
|
80
|
+
nengo => \"平成12年\"
|
81
|
+
mm => \"7\"
|
82
|
+
mm2 => \" 7\"
|
83
|
+
mm02 => \"07\"
|
84
|
+
mm-string => \"Jul\"
|
85
|
+
mm-string-long => \"July\"
|
86
|
+
dd => \"1\"
|
87
|
+
dd2 => \" 1\"
|
88
|
+
dd02 => \"01\"
|
89
|
+
ww => \"6\"
|
90
|
+
ww-string => \"Sat\"
|
91
|
+
ww-string-long => \"Saturday\"
|
92
|
+
ww-japanese => \"土\"
|
93
|
+
ww-japanese-long => \"土曜日\"
|
94
|
+
")
|
95
|
+
|
96
|
+
(defcustom mhc-calendar-mode-hook nil
|
97
|
+
"*Hook called in mhc-calendar-mode."
|
98
|
+
:group 'mhc
|
99
|
+
:type 'hook)
|
100
|
+
|
101
|
+
(defcustom mhc-calendar-create-buffer-hook nil
|
102
|
+
"*Hook called in mhc-calendar-create-buffer."
|
103
|
+
:group 'mhc
|
104
|
+
:type 'hook)
|
105
|
+
|
106
|
+
(defcustom mhc-calendar-start-column 2
|
107
|
+
"*Size of left margin."
|
108
|
+
:group 'mhc
|
109
|
+
:type 'integer)
|
110
|
+
|
111
|
+
(defcustom mhc-calendar-height
|
112
|
+
(cond
|
113
|
+
((and (featurep 'xemacs) window-system) 12)
|
114
|
+
((and (not (featurep 'xemacs)) (>= emacs-major-version 21)) 10)
|
115
|
+
(t 9))
|
116
|
+
"*Height of next month start column (greater or equal 9)."
|
117
|
+
:group 'mhc
|
118
|
+
:type 'integer)
|
119
|
+
|
120
|
+
(defcustom mhc-calendar-height-offset
|
121
|
+
(cond
|
122
|
+
((and (featurep 'xemacs) window-system) 4)
|
123
|
+
((and (not (featurep 'xemacs)) (>= emacs-major-version 21)) 3)
|
124
|
+
(t 1))
|
125
|
+
"*Offset of window height."
|
126
|
+
:group 'mhc
|
127
|
+
:type 'integer)
|
128
|
+
|
129
|
+
(defcustom mhc-calendar-view-summary nil
|
130
|
+
"*View day's summary if *non-nil*."
|
131
|
+
:group 'mhc
|
132
|
+
:type 'boolean)
|
133
|
+
|
134
|
+
(defcustom mhc-calendar-link-hnf nil
|
135
|
+
"*Support HNF(Hyper Nikki File) mode if *non-nil*."
|
136
|
+
:group 'mhc
|
137
|
+
:type 'boolean)
|
138
|
+
|
139
|
+
(defcustom mhc-calendar-use-mouse-highlight t
|
140
|
+
"*Highlight mouse pointer."
|
141
|
+
:group 'mhc
|
142
|
+
:type 'boolean)
|
143
|
+
|
144
|
+
(defcustom mhc-calendar-use-help-echo t
|
145
|
+
"*Display schedule within help-echo."
|
146
|
+
:group 'mhc
|
147
|
+
:type 'boolean)
|
148
|
+
|
149
|
+
(defcustom mhc-calendar-use-duration-show (if window-system 'mixed 'modeline)
|
150
|
+
"*Show 'duration' mode."
|
151
|
+
:group 'mhc
|
152
|
+
:type '(choice
|
153
|
+
(const :tag "none" nil)
|
154
|
+
(const :tag "modeline" modeline)
|
155
|
+
(const :tag "face" face)
|
156
|
+
(const :tag "mixed" mixed)))
|
157
|
+
|
158
|
+
(defcustom mhc-calendar-view-file-hook nil
|
159
|
+
"*Hook called in mhc-calendar-view-file."
|
160
|
+
:group 'mhc
|
161
|
+
:type 'hook)
|
162
|
+
|
163
|
+
;; internal variables. Don't modify.
|
164
|
+
(defvar mhc-calendar/buffer "*mhc-calendar*")
|
165
|
+
(defvar mhc-calendar-date nil)
|
166
|
+
(defvar mhc-calendar-view-date nil)
|
167
|
+
(defvar mhc-calendar-mode-map nil)
|
168
|
+
(defvar mhc-calendar-mode-menu-spec nil)
|
169
|
+
(defvar mhc-calendar/week-header nil)
|
170
|
+
(defvar mhc-calendar/separator-str nil)
|
171
|
+
|
172
|
+
(defvar mhc-calendar/inserter-call-buffer nil)
|
173
|
+
(defvar mhc-calendar/inserter-type nil)
|
174
|
+
(defvar mhc-calendar/inserter-for-minibuffer '(((yy "/" mm02 "/" dd02) . "-")))
|
175
|
+
(defvar mhc-calendar/inserter-for-draft '(((yy mm02 dd02) . "-")))
|
176
|
+
(defvar mhc-calendar/mark-date nil)
|
177
|
+
|
178
|
+
;; mhc-calendar functions
|
179
|
+
;; macros
|
180
|
+
(defmacro mhc-calendar-p ()
|
181
|
+
`(eq major-mode 'mhc-calendar-mode))
|
182
|
+
|
183
|
+
(defmacro mhc-calendar/in-date-p () ;; return 'date from 01/01/1970'
|
184
|
+
`(get-text-property (point) 'mhc-calendar/date-prop))
|
185
|
+
|
186
|
+
(defmacro mhc-calendar/in-summary-p () ;; return 'schedule filename'
|
187
|
+
`(or (get-text-property (point) 'mhc-calendar/summary-prop)
|
188
|
+
(save-excursion
|
189
|
+
(beginning-of-line)
|
190
|
+
(get-text-property (point) 'mhc-calendar/summary-prop))))
|
191
|
+
|
192
|
+
(defmacro mhc-calendar/in-summary-hnf-p () ;; return 'title count'
|
193
|
+
`(or (get-text-property (point) 'mhc-calendar/summary-hnf-prop)
|
194
|
+
(save-excursion
|
195
|
+
(beginning-of-line)
|
196
|
+
(get-text-property (point) 'mhc-calendar/summary-hnf-prop))))
|
197
|
+
|
198
|
+
(defmacro mhc-calendar/cw-week ()
|
199
|
+
`(and (or (eq mhc-calendar-use-cw 'week)
|
200
|
+
(eq mhc-calendar-use-cw t))
|
201
|
+
(eq mhc-start-day-of-week 1)))
|
202
|
+
|
203
|
+
(defcustom mhc-calendar-next-offset (if (mhc-calendar/cw-week) 27 23)
|
204
|
+
"*Offset of next month start column (greater or equal 23)."
|
205
|
+
:group 'mhc
|
206
|
+
:type 'integer)
|
207
|
+
|
208
|
+
(defvar mhc-calendar-width (if (mhc-calendar/cw-week) 28 24))
|
209
|
+
|
210
|
+
(defmacro mhc-calendar/cw-string (cw)
|
211
|
+
`(let (ret)
|
212
|
+
(if (stringp ,cw)
|
213
|
+
(setq ret ,cw)
|
214
|
+
(setq ret (format "%2d." ,cw)))
|
215
|
+
(mhc-face-put ret 'mhc-calendar-face-cw)
|
216
|
+
ret))
|
217
|
+
|
218
|
+
(defmacro mhc-calendar/get-date-colnum (col)
|
219
|
+
`(cond
|
220
|
+
((< ,col (+ mhc-calendar-next-offset mhc-calendar-start-column)) -1)
|
221
|
+
((< ,col (+ (* mhc-calendar-next-offset 2) mhc-calendar-start-column)) 0)
|
222
|
+
(t 1)))
|
223
|
+
|
224
|
+
(defmacro mhc-calendar/buffer-substring-to-num (pos)
|
225
|
+
`(string-to-number
|
226
|
+
(buffer-substring (match-beginning ,pos) (match-end ,pos))))
|
227
|
+
|
228
|
+
;; Avoid warning of byte-compiler.
|
229
|
+
(eval-when-compile
|
230
|
+
(defvar mhc-yy)
|
231
|
+
(defvar mhc-mm)
|
232
|
+
(defvar mhc-dd)
|
233
|
+
(defvar mhc-ww)
|
234
|
+
(defvar hnf-diary-dir)
|
235
|
+
(defvar hnf-diary-year-directory-flag)
|
236
|
+
(defvar view-exit-action)
|
237
|
+
(defvar mhc-calendar-mode-menu))
|
238
|
+
|
239
|
+
(eval-and-compile
|
240
|
+
(autoload 'easy-menu-add "easymenu")
|
241
|
+
(autoload 'hnf-mode "hnf-mode"))
|
242
|
+
|
243
|
+
;; Compatibilities between emacsen
|
244
|
+
(eval-and-compile
|
245
|
+
(if (fboundp 'text-property-any)
|
246
|
+
(defsubst mhc-calendar/tp-any (beg end prop value)
|
247
|
+
(text-property-any beg end prop value))
|
248
|
+
(defsubst mhc-calendar/tp-any (beg end prop value)
|
249
|
+
(while (and beg (< beg end)
|
250
|
+
(not (eq value (get-text-property beg prop))))
|
251
|
+
(setq beg (next-single-property-change beg prop nil end)))
|
252
|
+
(if (eq beg end) nil beg))))
|
253
|
+
|
254
|
+
(if (fboundp 'event-buffer)
|
255
|
+
(defalias 'mhc-calendar/event-buffer 'event-buffer)
|
256
|
+
(defun mhc-calendar/event-buffer (event)
|
257
|
+
(window-buffer (posn-window (event-start event)))))
|
258
|
+
|
259
|
+
(if (fboundp 'event-point)
|
260
|
+
(defalias 'mhc-calendar/event-point 'event-point)
|
261
|
+
(defun mhc-calendar/event-point (event)
|
262
|
+
(posn-point (event-start event))))
|
263
|
+
|
264
|
+
;; map/menu
|
265
|
+
(unless mhc-calendar-mode-map
|
266
|
+
(setq mhc-calendar-mode-map (make-sparse-keymap))
|
267
|
+
(define-key mhc-calendar-mode-map "." 'mhc-calendar-goto-today)
|
268
|
+
(define-key mhc-calendar-mode-map "g" 'mhc-calendar-goto-month)
|
269
|
+
(define-key mhc-calendar-mode-map "r" 'mhc-calendar-rescan)
|
270
|
+
(define-key mhc-calendar-mode-map "R" 'mhc-reset)
|
271
|
+
(define-key mhc-calendar-mode-map "=" 'mhc-calendar-get-day)
|
272
|
+
(define-key mhc-calendar-mode-map " " 'mhc-calendar-get-day-insert)
|
273
|
+
(define-key mhc-calendar-mode-map "\C-m" 'mhc-calendar-get-day-insert-quit)
|
274
|
+
(define-key mhc-calendar-mode-map "-" 'mhc-calendar-count-days-region)
|
275
|
+
(define-key mhc-calendar-mode-map "s" 'mhc-calendar-scan)
|
276
|
+
(define-key mhc-calendar-mode-map "E" 'mhc-calendar-edit)
|
277
|
+
(define-key mhc-calendar-mode-map "M" 'mhc-calendar-modify)
|
278
|
+
(define-key mhc-calendar-mode-map "D" 'mhc-calendar-delete)
|
279
|
+
(define-key mhc-calendar-mode-map "H" 'mhc-calendar-hnf-edit)
|
280
|
+
(define-key mhc-calendar-mode-map "v" 'mhc-calendar-goto-view)
|
281
|
+
(define-key mhc-calendar-mode-map "h" 'mhc-calendar-goto-home)
|
282
|
+
(define-key mhc-calendar-mode-map "f" 'mhc-calendar-next-day)
|
283
|
+
(define-key mhc-calendar-mode-map "b" 'mhc-calendar-prev-day)
|
284
|
+
(define-key mhc-calendar-mode-map "n" 'mhc-calendar-next-week)
|
285
|
+
(define-key mhc-calendar-mode-map "p" 'mhc-calendar-prev-week)
|
286
|
+
(define-key mhc-calendar-mode-map "N" 'mhc-calendar-next-month)
|
287
|
+
(define-key mhc-calendar-mode-map "P" 'mhc-calendar-prev-month)
|
288
|
+
(define-key mhc-calendar-mode-map ">" 'mhc-calendar-inc-month)
|
289
|
+
(define-key mhc-calendar-mode-map "<" 'mhc-calendar-dec-month)
|
290
|
+
(define-key mhc-calendar-mode-map "\M-\C-n" 'mhc-calendar-next-year)
|
291
|
+
(define-key mhc-calendar-mode-map "\M-\C-p" 'mhc-calendar-prev-year)
|
292
|
+
(define-key mhc-calendar-mode-map "\C-@" 'mhc-calendar-set-mark-command)
|
293
|
+
(cond
|
294
|
+
((featurep 'xemacs)
|
295
|
+
(define-key mhc-calendar-mode-map "\C- " 'mhc-calendar-set-mark-command)
|
296
|
+
(define-key mhc-calendar-mode-map [(button1)] 'mhc-calendar-day-at-mouse)
|
297
|
+
(define-key mhc-calendar-mode-map [(button2)] 'mhc-calendar-day-at-mouse))
|
298
|
+
(t
|
299
|
+
(define-key mhc-calendar-mode-map [?\C- ] 'mhc-calendar-set-mark-command)
|
300
|
+
(define-key mhc-calendar-mode-map [mouse-1] 'mhc-calendar-day-at-mouse)
|
301
|
+
(define-key mhc-calendar-mode-map [mouse-2] 'mhc-calendar-day-at-mouse)))
|
302
|
+
(define-key mhc-calendar-mode-map "\C-x\C-x" 'mhc-calendar-exchange-point-and-mark)
|
303
|
+
(define-key mhc-calendar-mode-map "q" 'mhc-calendar-quit)
|
304
|
+
(define-key mhc-calendar-mode-map "Q" 'mhc-calendar-exit)
|
305
|
+
(define-key mhc-calendar-mode-map "?" 'describe-mode))
|
306
|
+
|
307
|
+
(unless mhc-calendar-mode-menu-spec
|
308
|
+
(setq mhc-calendar-mode-menu-spec
|
309
|
+
'("Mhc-Calendar"
|
310
|
+
["Toggle view area" mhc-calendar-goto-home t]
|
311
|
+
["Goto today" mhc-calendar-goto-today t]
|
312
|
+
["Goto next month" mhc-calendar-inc-month t]
|
313
|
+
["Goto prev month" mhc-calendar-dec-month t]
|
314
|
+
["Goto month" mhc-calendar-goto-month t]
|
315
|
+
("Goto"
|
316
|
+
["Next day" mhc-calendar-next-day t]
|
317
|
+
["Prev day" mhc-calendar-prev-day t]
|
318
|
+
["Next week" mhc-calendar-next-week t]
|
319
|
+
["Prev week" mhc-calendar-prev-week t]
|
320
|
+
["Next month" mhc-calendar-next-month t]
|
321
|
+
["Prev month" mhc-calendar-prev-month t]
|
322
|
+
["Next year" mhc-calendar-next-year t]
|
323
|
+
["Prev year" mhc-calendar-prev-year t])
|
324
|
+
["Rescan" mhc-calendar-rescan t]
|
325
|
+
["MHC summary scan" mhc-calendar-scan t]
|
326
|
+
"----"
|
327
|
+
["Save to kill ring" mhc-calendar-get-day t]
|
328
|
+
["Insert" mhc-calendar-get-day-insert t]
|
329
|
+
["Insert/Quit" mhc-calendar-get-day-insert-quit t]
|
330
|
+
["Mark set" mhc-calendar-set-mark-command t]
|
331
|
+
["Exchange point & mark" mhc-calendar-exchange-point-and-mark
|
332
|
+
mhc-calendar/mark-date t]
|
333
|
+
["Count days in region" mhc-calendar-count-days-region
|
334
|
+
mhc-calendar/mark-date t]
|
335
|
+
"----"
|
336
|
+
["Goto view area" mhc-calendar-goto-view
|
337
|
+
(not (or (mhc-calendar/in-summary-p) (mhc-calendar/in-summary-hnf-p)))]
|
338
|
+
["Schedule view" mhc-calendar-goto-view
|
339
|
+
(or (mhc-calendar/in-summary-p) (mhc-calendar/in-summary-hnf-p))]
|
340
|
+
("Schedule edit"
|
341
|
+
["Schedule addition" mhc-calendar-edit
|
342
|
+
(or (mhc-calendar/in-date-p) (mhc-calendar/in-summary-p))]
|
343
|
+
["Schedule modify" mhc-calendar-modify (mhc-calendar/in-summary-p)]
|
344
|
+
["Schedule delete" mhc-calendar-delete (mhc-calendar/in-summary-p)]
|
345
|
+
["HNF file edit" mhc-calendar-hnf-edit
|
346
|
+
(and mhc-calendar-link-hnf
|
347
|
+
(or (mhc-calendar/in-date-p) (mhc-calendar/in-summary-p)
|
348
|
+
(mhc-calendar/in-summary-hnf-p)))])
|
349
|
+
"----"
|
350
|
+
("Misc"
|
351
|
+
["Reset" mhc-reset t]
|
352
|
+
["Quit" mhc-calendar-quit t]
|
353
|
+
["Kill" mhc-calendar-exit t]
|
354
|
+
["Help" describe-mode t]))))
|
355
|
+
|
356
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
357
|
+
;; make rectangle like calendar.el
|
358
|
+
|
359
|
+
(defun mhc-calendar-toggle-insert-rectangle (&optional hide-private)
|
360
|
+
"Toggle 3 month calendar."
|
361
|
+
(interactive "P")
|
362
|
+
(setq mhc-insert-calendar (not mhc-insert-calendar))
|
363
|
+
(mhc-rescan-month hide-private))
|
364
|
+
|
365
|
+
(defun mhc-calendar-setup ()
|
366
|
+
(setq mhc-calendar/week-header nil)
|
367
|
+
(setq mhc-calendar/separator-str (char-to-string mhc-calendar-separator))
|
368
|
+
(mhc-face-put mhc-calendar/separator-str 'mhc-summary-face-separator)
|
369
|
+
(if (mhc-calendar/cw-week)
|
370
|
+
(when (< mhc-calendar-next-offset 27)
|
371
|
+
(setq mhc-calendar-next-offset 27))
|
372
|
+
(when (< mhc-calendar-next-offset 23)
|
373
|
+
(setq mhc-calendar-next-offset 23)))
|
374
|
+
(setq mhc-calendar-width (if (mhc-calendar/cw-week) 28 24))
|
375
|
+
(when (mhc-calendar/cw-week)
|
376
|
+
(setq mhc-calendar/week-header
|
377
|
+
(mhc-calendar/cw-string
|
378
|
+
(format "%s " mhc-calendar-cw-indicator))))
|
379
|
+
(let ((days (copy-sequence (nthcdr mhc-start-day-of-week
|
380
|
+
(append mhc-calendar-day-strings
|
381
|
+
mhc-calendar-day-strings nil))))
|
382
|
+
(i 0) day)
|
383
|
+
(while (< i 7)
|
384
|
+
(setq day (car days))
|
385
|
+
(cond
|
386
|
+
((= (% (+ i mhc-start-day-of-week) 7) 0)
|
387
|
+
(mhc-face-put day 'mhc-calendar-face-sunday))
|
388
|
+
((= (% (+ i mhc-start-day-of-week) 7) 6)
|
389
|
+
(mhc-face-put day 'mhc-calendar-face-saturday))
|
390
|
+
(t (mhc-face-put day 'mhc-calendar-face-default)))
|
391
|
+
(setq mhc-calendar/week-header
|
392
|
+
(concat mhc-calendar/week-header
|
393
|
+
(if mhc-calendar/week-header " ") day))
|
394
|
+
(setq days (cdr days))
|
395
|
+
(setq i (1+ i)))))
|
396
|
+
|
397
|
+
(defun mhc-calendar-insert-rectangle-at (date col &optional months dayinfo-list)
|
398
|
+
(let ((m nil) (rect nil) (center nil))
|
399
|
+
(save-excursion
|
400
|
+
(setq date (mhc-date-mm-first date))
|
401
|
+
(put-text-property (point-min) (point-max) 'rear-nonsticky t)
|
402
|
+
(goto-char (point-min))
|
403
|
+
(when mhc-use-wide-scope
|
404
|
+
(mhc-summary-search-date date))
|
405
|
+
(beginning-of-line)
|
406
|
+
(mhc-misc-move-to-column col)
|
407
|
+
(if (consp months)
|
408
|
+
(setq m (car months)
|
409
|
+
center (- m (cdr months)))
|
410
|
+
(setq m (or months 3))
|
411
|
+
(setq center (/ (1+ m) 2)))
|
412
|
+
(while (> m 0)
|
413
|
+
(setq rect
|
414
|
+
(nconc
|
415
|
+
rect
|
416
|
+
(mhc-calendar/make-rectangle
|
417
|
+
(mhc-date-mm- date (- m center)) mhc-calendar/separator-str
|
418
|
+
dayinfo-list)
|
419
|
+
(if (> m 1) (list (concat mhc-calendar/separator-str " ")))))
|
420
|
+
(setq m (1- m)))
|
421
|
+
(mhc-misc-insert-rectangle rect))))
|
422
|
+
|
423
|
+
(defun mhc-calendar-make-header (date)
|
424
|
+
(let ((ret (mhc-date-format date "%s %04d"
|
425
|
+
(mhc-date-digit-to-mm-string mm t) yy))
|
426
|
+
cw)
|
427
|
+
(when (eq mhc-calendar-use-cw 'month)
|
428
|
+
(setq cw (mhc-calendar/cw-string
|
429
|
+
(format "w%d" (mhc-date-cw (mhc-date-mm-first date)))))
|
430
|
+
;; (length "September 2002 w35") => 18
|
431
|
+
;; (length "Mo Tu We Th Fr Sa Su") => 20
|
432
|
+
(setq cw (concat (make-string (- 18 (length ret) (length cw)) ? )
|
433
|
+
cw)))
|
434
|
+
(if (mhc-date-yymm= (mhc-date-now) date)
|
435
|
+
(mhc-face-put
|
436
|
+
ret (mhc-face-get-today-face 'mhc-calendar-face-saturday))
|
437
|
+
(mhc-face-put ret 'mhc-calendar-face-saturday))
|
438
|
+
(concat " " (if (mhc-calendar/cw-week) " " "")
|
439
|
+
ret cw)))
|
440
|
+
|
441
|
+
(defun mhc-calendar-make-header-ja (date)
|
442
|
+
(let ((ret (mhc-date-format date "%04d年%2d月" yy mm))
|
443
|
+
(cw ""))
|
444
|
+
(when (eq mhc-calendar-use-cw 'month)
|
445
|
+
(setq cw (mhc-calendar/cw-string
|
446
|
+
(format " (%d)" (mhc-date-cw (mhc-date-mm-first date))))))
|
447
|
+
(if (mhc-date-yymm= (mhc-date-now) date)
|
448
|
+
(mhc-face-put
|
449
|
+
ret (mhc-face-get-today-face 'mhc-calendar-face-saturday))
|
450
|
+
(mhc-face-put ret 'mhc-calendar-face-saturday))
|
451
|
+
(concat " " (if (mhc-calendar/cw-week) " " "")
|
452
|
+
ret cw)))
|
453
|
+
|
454
|
+
(defun mhc-calendar/make-rectangle (&optional date separator dayinfo-list)
|
455
|
+
(let* ((today (mhc-date-now))
|
456
|
+
(month (list (concat separator " "
|
457
|
+
mhc-calendar/week-header)
|
458
|
+
(concat separator " "
|
459
|
+
(funcall mhc-calendar-header-function
|
460
|
+
(or date today)))))
|
461
|
+
(mm (mhc-date-mm (or date today)))
|
462
|
+
(days (or dayinfo-list (mhc-db-scan-month (mhc-date-yy (or date today)) mm t)))
|
463
|
+
(dayinfo-cache days)
|
464
|
+
(separator (if separator separator mhc-calendar/separator-str))
|
465
|
+
(i 0)
|
466
|
+
(from (mhc-date-mm-first date))
|
467
|
+
(to (mhc-date-mm-last date))
|
468
|
+
(start (mhc-date-ww date))
|
469
|
+
(cdate from)
|
470
|
+
week color cw day map dayinfo)
|
471
|
+
(when (mhc-calendar/cw-week)
|
472
|
+
(setq cw (mhc-date-cw from))
|
473
|
+
(setq week (cons (mhc-calendar/cw-string cw) week)))
|
474
|
+
(unless (= (mhc-end-day-of-week) 6)
|
475
|
+
(setq start (+ start 6))
|
476
|
+
(when (> start 6)
|
477
|
+
(setq start (- start 7))))
|
478
|
+
(while (< i start)
|
479
|
+
(setq week (cons " " week))
|
480
|
+
(setq i (1+ i)))
|
481
|
+
(while (mhc-date<= cdate to)
|
482
|
+
(setq dayinfo (assoc cdate days))
|
483
|
+
(when (and (null week) (mhc-calendar/cw-week))
|
484
|
+
(if (or (eq mm 1) (eq mm 12))
|
485
|
+
(setq cw (mhc-date-cw cdate))
|
486
|
+
(setq cw (1+ cw)))
|
487
|
+
(setq week (cons (mhc-calendar/cw-string cw) week)))
|
488
|
+
(setq color
|
489
|
+
(cond
|
490
|
+
((= 0 (mhc-date-ww cdate))
|
491
|
+
'mhc-calendar-face-sunday)
|
492
|
+
((and dayinfo (mhc-day-holiday dayinfo))
|
493
|
+
(mhc-face-category-to-face "Holiday"))
|
494
|
+
((= 6 (mhc-date-ww cdate))
|
495
|
+
'mhc-calendar-face-saturday)
|
496
|
+
(t 'mhc-calendar-face-default)))
|
497
|
+
(when (mhc-date= today cdate)
|
498
|
+
(setq color (mhc-face-get-today-face color)))
|
499
|
+
(when (and dayinfo (mhc-day-busy-p dayinfo))
|
500
|
+
(setq color (mhc-face-get-busy-face color)))
|
501
|
+
(setq day (format "%2d" (mhc-date-dd cdate)))
|
502
|
+
(when color (mhc-face-put day color))
|
503
|
+
(add-text-properties 0 (length day)
|
504
|
+
`(mhc-calendar/date-prop ,cdate
|
505
|
+
mouse-face ,(if mhc-calendar-use-mouse-highlight
|
506
|
+
'highlight nil)
|
507
|
+
help-echo ,(if mhc-calendar-use-help-echo
|
508
|
+
(and dayinfo (mhc-calendar/get-contents cdate dayinfo-cache)) nil))
|
509
|
+
day)
|
510
|
+
(setq week (cons day week))
|
511
|
+
(when (= (mhc-end-day-of-week) (mhc-date-ww cdate))
|
512
|
+
(setq month (cons (mapconcat
|
513
|
+
(function identity)
|
514
|
+
(cons separator (nreverse week))
|
515
|
+
" ")
|
516
|
+
month)
|
517
|
+
week nil))
|
518
|
+
(setq cdate (mhc-date++ cdate)))
|
519
|
+
(when week
|
520
|
+
(setq month (cons (mapconcat
|
521
|
+
(function identity)
|
522
|
+
(cons separator (nreverse week))
|
523
|
+
" ")
|
524
|
+
month)))
|
525
|
+
(nreverse month)))
|
526
|
+
|
527
|
+
(defun mhc-calendar-mouse-goto-date-view (event)
|
528
|
+
(interactive "e")
|
529
|
+
(mhc-calendar-mouse-goto-date event 'view))
|
530
|
+
|
531
|
+
(eval-and-compile
|
532
|
+
(if (featurep 'xemacs)
|
533
|
+
(defun mhc-calendar-mouse-icon-function (event)
|
534
|
+
(mhc-xmas-icon-call-function event))
|
535
|
+
(defun mhc-calendar-mouse-icon-function (event)
|
536
|
+
(mhc-e21-icon-call-function event))))
|
537
|
+
|
538
|
+
(defun mhc-calendar-mouse-goto-date (event &optional view)
|
539
|
+
(interactive "e")
|
540
|
+
(let (cdate dayinfo pos cpos func)
|
541
|
+
(with-current-buffer (mhc-calendar/event-buffer event)
|
542
|
+
(goto-char (mhc-calendar/event-point event))
|
543
|
+
(setq cdate (get-text-property (point) 'mhc-calendar/date-prop)))
|
544
|
+
(cond
|
545
|
+
(cdate
|
546
|
+
(unless (= (mhc-current-date-month)
|
547
|
+
(mhc-date-let cdate (mhc-date-new yy mm 1)))
|
548
|
+
(mhc-goto-month cdate mhc-default-hide-private-schedules))
|
549
|
+
(setq pos (point))
|
550
|
+
(goto-char (point-min))
|
551
|
+
(setq cpos (point))
|
552
|
+
(catch 'detect
|
553
|
+
(while (setq cpos (next-single-property-change cpos 'mhc-dayinfo))
|
554
|
+
(when (and (setq dayinfo (get-text-property cpos 'mhc-dayinfo))
|
555
|
+
(= cdate (mhc-day-date dayinfo)))
|
556
|
+
(setq pos cpos)
|
557
|
+
(throw 'detect t))))
|
558
|
+
(goto-char pos)
|
559
|
+
(funcall (mhc-get-function 'goto-message) view))
|
560
|
+
(t
|
561
|
+
(unless (mhc-calendar-mouse-icon-function event)
|
562
|
+
(setq func (or (lookup-key (current-local-map) (this-command-keys))
|
563
|
+
(lookup-key (current-global-map) (this-command-keys))))
|
564
|
+
(when func
|
565
|
+
(call-interactively func event)))))))
|
566
|
+
|
567
|
+
;; function
|
568
|
+
(defun mhc-calendar-mode ()
|
569
|
+
"\\<mhc-calendar-mode-map>
|
570
|
+
MHC Calendar mode:: major mode to view calendar and select day.
|
571
|
+
|
572
|
+
The keys that are defined for mhc-calendar-mode are:
|
573
|
+
\\[mhc-calendar-goto-home] Recover positioning and toggle show 'view area'.
|
574
|
+
\\[mhc-calendar-goto-today] Jump to today.
|
575
|
+
\\[mhc-calendar-inc-month] Slide to the next month.
|
576
|
+
\\[mhc-calendar-dec-month] Slide to the previous month.
|
577
|
+
\\[mhc-calendar-goto-month] Jump to your prefer month.
|
578
|
+
\\[mhc-calendar-rescan] Rescan current calendar.
|
579
|
+
\\[mhc-calendar-scan] Scan the point day's schedule summary with MUA.
|
580
|
+
If '\\[mhc-calendar-scan]' executed with 'prefix argument', hide private category.
|
581
|
+
|
582
|
+
\\[mhc-calendar-next-day] Goto the next day.
|
583
|
+
\\[mhc-calendar-prev-day] Goto the previous day.
|
584
|
+
\\[mhc-calendar-next-week] Goto the next week or goto the next summary.
|
585
|
+
\\[mhc-calendar-prev-week] Goto previous week or goto the previous summary.
|
586
|
+
\\[mhc-calendar-next-month] Goto next month.
|
587
|
+
\\[mhc-calendar-prev-month] Goto previous month.
|
588
|
+
\\[mhc-calendar-next-year] Goto next year.
|
589
|
+
\\[mhc-calendar-prev-year] Goto previous year.
|
590
|
+
'\\[mhc-calendar-next-day]' '\\[mhc-calendar-prev-day]' '\\[mhc-calendar-next-week]' '\\[mhc-calendar-prev-week]' '\\[mhc-calendar-next-month]' '\\[mhc-calendar-prev-month]' '\\[mhc-calendar-inc-month]' '\\[mhc-calendar-dec-month]' '\\[mhc-calendar-next-year]' '\\[mhc-calendar-prev-year]'
|
591
|
+
effected by 'prefix argument(integer number)'.
|
592
|
+
\\[mhc-calendar-day-at-mouse] Day positioning or view schedule file.
|
593
|
+
|
594
|
+
\\[mhc-calendar-set-mark-command] Duration start point set.
|
595
|
+
\\[mhc-calendar-exchange-point-and-mark] Duration start point exchange.
|
596
|
+
\\[mhc-calendar-count-days-region] Count days in region.
|
597
|
+
|
598
|
+
\\[mhc-calendar-get-day] Get day at point to save kill ring.
|
599
|
+
\\[mhc-calendar-get-day-insert] Get day at point to insert call buffer.
|
600
|
+
\\[mhc-calendar-get-day-insert-quit] Get day at point to insert call buffer, quit.
|
601
|
+
if '\\[mhc-calendar-get-day]' '\\[mhc-calendar-get-day-insert]' '\\[mhc-calendar-get-day-insert-quit]' executed with 'prefix argument', means to treat the duration.
|
602
|
+
|
603
|
+
\\[mhc-calendar-goto-view] Goto summary view position or view schedule file.
|
604
|
+
\\[mhc-calendar-edit] Create new schdule file.
|
605
|
+
If optional argument IMPORT-BUFFER is specified, import its content.
|
606
|
+
\\[mhc-calendar-modify] Edit the schdule on the cursor point.
|
607
|
+
\\[mhc-calendar-delete] Delete the schdule on the cursor point.
|
608
|
+
\\[mhc-calendar-hnf-edit] Edit the Hyper Nikki File.
|
609
|
+
|
610
|
+
\\[mhc-reset] Reset MHC.
|
611
|
+
\\[mhc-calendar-quit] Quit and calendar buffer bury.
|
612
|
+
\\[mhc-calendar-exit] Quit and calendar buffer kill.
|
613
|
+
\\[describe-mode] Show mode help.
|
614
|
+
"
|
615
|
+
(interactive)
|
616
|
+
(kill-all-local-variables)
|
617
|
+
(use-local-map mhc-calendar-mode-map)
|
618
|
+
(make-local-variable 'mhc-calendar-date)
|
619
|
+
(make-local-variable 'mhc-calendar-view-date)
|
620
|
+
(make-local-variable 'mhc-calendar/mark-date)
|
621
|
+
(make-local-variable 'indent-tabs-mode)
|
622
|
+
(setq major-mode 'mhc-calendar-mode)
|
623
|
+
(setq mode-name "mhc-calendar")
|
624
|
+
(setq indent-tabs-mode nil)
|
625
|
+
(setq truncate-lines t)
|
626
|
+
(when (featurep 'xemacs)
|
627
|
+
(easy-menu-add mhc-calendar-mode-menu))
|
628
|
+
(unless (memq 'mhc-calendar/duration-show post-command-hook)
|
629
|
+
(add-hook 'post-command-hook 'mhc-calendar/duration-show))
|
630
|
+
(run-hooks 'mhc-calendar-mode-hook))
|
631
|
+
|
632
|
+
(defun mhc-calendar (&optional date)
|
633
|
+
"Display 3-month mini calendar."
|
634
|
+
(interactive)
|
635
|
+
(setq date (or date (mhc-current-date) (mhc-calendar-get-date)))
|
636
|
+
(when (and (get-buffer mhc-calendar/buffer) (set-buffer mhc-calendar/buffer))
|
637
|
+
(setq date (or date mhc-calendar-view-date))
|
638
|
+
(unless (mhc-date-yymm= date mhc-calendar-date)
|
639
|
+
(mhc-calendar/create-buffer date)))
|
640
|
+
(mhc-calendar/goto-date (or date (mhc-date-now))))
|
641
|
+
|
642
|
+
(defun mhc-calendar-goto-today ()
|
643
|
+
(interactive)
|
644
|
+
(mhc-calendar (mhc-date-now)))
|
645
|
+
|
646
|
+
(defun mhc-calendar/goto-date (date)
|
647
|
+
(let ((mhc-calendar-view-summary nil) pos)
|
648
|
+
(unless (memq 'mhc-calendar/duration-show post-command-hook)
|
649
|
+
(add-hook 'post-command-hook 'mhc-calendar/duration-show))
|
650
|
+
(unless (get-buffer mhc-calendar/buffer)
|
651
|
+
(mhc-calendar/create-buffer date))
|
652
|
+
(set-buffer (get-buffer mhc-calendar/buffer))
|
653
|
+
(pop-to-buffer mhc-calendar/buffer)
|
654
|
+
(while (not pos)
|
655
|
+
(setq pos (mhc-calendar/tp-any (point-min) (point-max)
|
656
|
+
'mhc-calendar/date-prop date))
|
657
|
+
(or pos (mhc-calendar/create-buffer date)))
|
658
|
+
(goto-char (1+ pos)))
|
659
|
+
(setq mhc-calendar-view-date date)
|
660
|
+
(save-excursion
|
661
|
+
(mhc-calendar/view-summary-delete)
|
662
|
+
(when mhc-calendar-view-summary
|
663
|
+
(mhc-calendar/view-summary-insert)
|
664
|
+
(and mhc-calendar-link-hnf
|
665
|
+
(mhc-calendar/hnf-summary-insert))
|
666
|
+
(mhc-calendar/put-property-summary)))
|
667
|
+
(mhc-calendar/shrink-window))
|
668
|
+
|
669
|
+
(defun mhc-calendar/view-summary-delete ()
|
670
|
+
(goto-char (point-min))
|
671
|
+
(when (re-search-forward "^--" nil t)
|
672
|
+
(let ((buffer-read-only nil))
|
673
|
+
(beginning-of-line)
|
674
|
+
(forward-char -1)
|
675
|
+
(set-text-properties (point) (point-max) nil)
|
676
|
+
(delete-region (point) (point-max))
|
677
|
+
(set-buffer-modified-p nil))))
|
678
|
+
|
679
|
+
(defun mhc-calendar/view-summary-insert ()
|
680
|
+
(let ((date mhc-calendar-view-date)
|
681
|
+
(buffer-read-only nil)
|
682
|
+
(mhc-use-week-separator nil))
|
683
|
+
(goto-char (point-max))
|
684
|
+
(insert "\n")
|
685
|
+
(mhc-summary/insert-separator nil nil
|
686
|
+
(min (1- (window-width))
|
687
|
+
(* mhc-calendar-next-offset 3)))
|
688
|
+
(mhc-summary-make-contents (mhc-db-scan date date) date date 'mhc-calendar)
|
689
|
+
(delete-char -1)
|
690
|
+
(set-buffer-modified-p nil)))
|
691
|
+
|
692
|
+
(defun mhc-calendar/put-property-summary ()
|
693
|
+
(condition-case nil
|
694
|
+
(when mhc-calendar-use-mouse-highlight
|
695
|
+
(let ((buffer-read-only nil)
|
696
|
+
beg)
|
697
|
+
(goto-char (point-min))
|
698
|
+
(when (re-search-forward "^--" nil t)
|
699
|
+
(forward-line)
|
700
|
+
(while (not (eobp))
|
701
|
+
(setq beg (point))
|
702
|
+
(end-of-line)
|
703
|
+
(put-text-property beg (point) 'mouse-face 'highlight)
|
704
|
+
(forward-line))))
|
705
|
+
(set-buffer-modified-p nil))
|
706
|
+
(error nil)))
|
707
|
+
|
708
|
+
(defun mhc-calendar/shrink-window ()
|
709
|
+
(or (one-window-p t)
|
710
|
+
(/= (frame-width) (window-width))
|
711
|
+
(let ((winh (+ (count-lines (point-min) (point-max))
|
712
|
+
mhc-calendar-height-offset)))
|
713
|
+
(cond
|
714
|
+
((< winh mhc-calendar-height)
|
715
|
+
(setq winh mhc-calendar-height))
|
716
|
+
((< winh window-min-height)
|
717
|
+
(setq winh window-min-height)))
|
718
|
+
(shrink-window (- (window-height) winh)))))
|
719
|
+
|
720
|
+
(defun mhc-calendar/create-buffer (date)
|
721
|
+
(set-buffer (get-buffer-create mhc-calendar/buffer))
|
722
|
+
(setq buffer-read-only t)
|
723
|
+
(unless (eq major-mode 'mhc-calendar-mode)
|
724
|
+
(mhc-calendar-mode)
|
725
|
+
(buffer-disable-undo))
|
726
|
+
(or (mhc-date-p date) (setq date (mhc-date-now)))
|
727
|
+
(let ((buffer-read-only nil)
|
728
|
+
(caldate (mhc-date-mm+ date -1))
|
729
|
+
(col mhc-calendar-start-column)
|
730
|
+
(prefix " +|")
|
731
|
+
(i 3))
|
732
|
+
(mhc-calendar/delete-overlay)
|
733
|
+
(set-text-properties (point-min) (point-max) nil)
|
734
|
+
(erase-buffer)
|
735
|
+
(message "mhc-calendar create...")
|
736
|
+
(while (> i 0)
|
737
|
+
(goto-char (point-min))
|
738
|
+
(mhc-misc-move-to-column col)
|
739
|
+
(mhc-misc-insert-rectangle
|
740
|
+
(mhc-calendar/make-rectangle caldate (if (= i 3) "" "|")))
|
741
|
+
(setq caldate (mhc-date-mm+ caldate 1))
|
742
|
+
(setq col (- (+ col mhc-calendar-next-offset) (if (= i 3) 1 0)))
|
743
|
+
(setq i (1- i)))
|
744
|
+
(goto-char (point-min))
|
745
|
+
(while (re-search-forward prefix nil t)
|
746
|
+
(delete-region (match-end 0) (match-beginning 0))
|
747
|
+
(insert (make-string (- (match-end 0) (match-beginning 0)) ?\ )))
|
748
|
+
(setq mhc-calendar-date date)
|
749
|
+
;; (mhc-calendar/put-property-date)
|
750
|
+
(and mhc-calendar-link-hnf (mhc-calendar/hnf-mark-diary-entries))
|
751
|
+
(run-hooks 'mhc-calendar-create-buffer-hook)
|
752
|
+
(set-buffer-modified-p nil)
|
753
|
+
(message "mhc-calendar create...done")))
|
754
|
+
|
755
|
+
(defvar mhc-calendar/date-format nil)
|
756
|
+
|
757
|
+
(defun mhc-calendar/get-contents (date dayinfo-alist)
|
758
|
+
(unless mhc-calendar/date-format
|
759
|
+
(setq mhc-calendar/date-format
|
760
|
+
(if (eq mhc-calendar-language 'japanese)
|
761
|
+
"%04d年%2d月%2d日(%s)\n"
|
762
|
+
"%04d-%02d-%02d (%s)\n")))
|
763
|
+
(with-temp-buffer
|
764
|
+
(let* ((dayinfo (assoc date dayinfo-alist))
|
765
|
+
(schedules (mhc-day-schedules dayinfo))
|
766
|
+
schedule begin end subject location)
|
767
|
+
(mhc-date-let date
|
768
|
+
(insert (format mhc-calendar/date-format
|
769
|
+
yy mm dd
|
770
|
+
(aref mhc-calendar-day-strings ww))))
|
771
|
+
(when schedules (insert "\n"))
|
772
|
+
(while (setq schedule (car schedules))
|
773
|
+
(setq schedules (cdr schedules))
|
774
|
+
(setq begin (mhc-schedule-time-begin schedule))
|
775
|
+
(setq end (mhc-schedule-time-end schedule))
|
776
|
+
(setq subject (or (mhc-schedule-subject schedule) ""))
|
777
|
+
(setq location (or (mhc-schedule-location schedule) ""))
|
778
|
+
(when (> (length location) 0)
|
779
|
+
(setq location (concat " [" location "]")))
|
780
|
+
(when (or begin end subject location)
|
781
|
+
(insert (format "%s%s%s%s%s\n"
|
782
|
+
(if begin
|
783
|
+
(format "%02d:%02d" (/ begin 60) (% begin 60))
|
784
|
+
"")
|
785
|
+
(if end
|
786
|
+
(format "-%02d:%02d" (/ end 60) (% end 60))
|
787
|
+
"")
|
788
|
+
(if (or begin end) " " "")
|
789
|
+
subject location))))
|
790
|
+
(buffer-substring-no-properties (point-min) (point-max)))))
|
791
|
+
|
792
|
+
(defun mhc-calendar-edit ()
|
793
|
+
(interactive)
|
794
|
+
(if (or (mhc-calendar/in-date-p)
|
795
|
+
(mhc-calendar/in-summary-p))
|
796
|
+
(progn
|
797
|
+
(mhc-window-push)
|
798
|
+
(mhc-edit nil)
|
799
|
+
(delete-other-windows))
|
800
|
+
(message "Nothing to do in this point.")))
|
801
|
+
|
802
|
+
(defun mhc-calendar-delete ()
|
803
|
+
(interactive)
|
804
|
+
(let ((filename (mhc-calendar/in-summary-p)) key)
|
805
|
+
(if (null filename)
|
806
|
+
(message "Nothing to do in this point.")
|
807
|
+
(mhc-delete-file
|
808
|
+
(mhc-parse-file filename)))))
|
809
|
+
|
810
|
+
(defun mhc-calendar-modify ()
|
811
|
+
(interactive)
|
812
|
+
(if (mhc-calendar/in-summary-p)
|
813
|
+
(mhc-modify-file (mhc-calendar/in-summary-p))
|
814
|
+
(message "Nothing to do in this point.")))
|
815
|
+
|
816
|
+
(defun mhc-calendar-toggle-view ()
|
817
|
+
(interactive)
|
818
|
+
(setq mhc-calendar-view-summary (not mhc-calendar-view-summary))
|
819
|
+
(mhc-calendar/goto-date (mhc-calendar-get-date)))
|
820
|
+
|
821
|
+
(defun mhc-calendar-goto-view ()
|
822
|
+
(interactive)
|
823
|
+
(cond
|
824
|
+
((mhc-calendar/in-summary-p)
|
825
|
+
(mhc-calendar/view-file (mhc-calendar/in-summary-p)))
|
826
|
+
((mhc-calendar/in-summary-hnf-p)
|
827
|
+
(mhc-calendar/hnf-view))
|
828
|
+
(t
|
829
|
+
(setq mhc-calendar-view-summary t)
|
830
|
+
(mhc-calendar/goto-date (mhc-calendar-get-date))
|
831
|
+
(goto-char (next-single-property-change
|
832
|
+
(point) 'mhc-calendar/summary-prop)))))
|
833
|
+
|
834
|
+
(defun mhc-calendar/view-file (file)
|
835
|
+
(if (and (stringp file) (file-exists-p file))
|
836
|
+
(let ((newname (mhc-date-format
|
837
|
+
mhc-calendar-view-date "+%04d/%02d/%02d" yy mm dd)))
|
838
|
+
(mhc-window-push)
|
839
|
+
(view-file-other-window file)
|
840
|
+
;; eword decode
|
841
|
+
(mhc-calendar/view-file-decode-header)
|
842
|
+
(setq view-exit-action 'mhc-calendar-view-exit-action)
|
843
|
+
(set-visited-file-name nil)
|
844
|
+
(rename-buffer newname 'unique)
|
845
|
+
(run-hooks 'mhc-calendar-view-file-hook)
|
846
|
+
(set-buffer-modified-p nil)
|
847
|
+
(setq buffer-read-only t))
|
848
|
+
(message "File does not exist (%s)." file)))
|
849
|
+
|
850
|
+
(defun mhc-calendar/view-file-decode-header ()
|
851
|
+
(let ((buffer-read-only nil))
|
852
|
+
(goto-char (point-min))
|
853
|
+
(mhc-decode-header)
|
854
|
+
(mhc-highlight-message)))
|
855
|
+
|
856
|
+
;; insert function
|
857
|
+
(defun mhc-calendar-get-day (&optional arg)
|
858
|
+
(interactive "P")
|
859
|
+
(let (str)
|
860
|
+
(if (null arg)
|
861
|
+
(setq str (mhc-calendar/get-day))
|
862
|
+
(setq str (mhc-calendar/get-day-region)))
|
863
|
+
(kill-new str)
|
864
|
+
(message "\"%s\" to the latest kill in the kill ring." str)))
|
865
|
+
|
866
|
+
(defun mhc-calendar-get-day-insert-quit (&optional arg)
|
867
|
+
(interactive "P")
|
868
|
+
(when (mhc-calendar-get-day-insert arg)
|
869
|
+
(mhc-calendar-quit)))
|
870
|
+
|
871
|
+
(defun mhc-calendar-get-day-insert (&optional arg)
|
872
|
+
(interactive "P")
|
873
|
+
(let ((callbuf mhc-calendar/inserter-call-buffer)
|
874
|
+
(type mhc-calendar/inserter-type)
|
875
|
+
(defbuff (buffer-name
|
876
|
+
(car (delete (get-buffer mhc-calendar/buffer)
|
877
|
+
(buffer-list)))))
|
878
|
+
str)
|
879
|
+
;; in mhc-calendar/buffer
|
880
|
+
(if (null arg)
|
881
|
+
(setq str (mhc-calendar/get-day type))
|
882
|
+
(setq str (mhc-calendar/get-day-region type)))
|
883
|
+
(kill-new str)
|
884
|
+
(unless (and callbuf (get-buffer callbuf) (buffer-name callbuf))
|
885
|
+
(setq callbuf (read-buffer "Insert buffer? " defbuff t)))
|
886
|
+
;; in mhc-clendar-call-buffer
|
887
|
+
(if (not (get-buffer callbuf))
|
888
|
+
(message "No buffer detect \"%s\"" callbuf)
|
889
|
+
(set-buffer (get-buffer callbuf))
|
890
|
+
(pop-to-buffer callbuf)
|
891
|
+
(cond
|
892
|
+
((window-minibuffer-p)
|
893
|
+
(insert str) t)
|
894
|
+
(t (condition-case err
|
895
|
+
(progn
|
896
|
+
(insert str)
|
897
|
+
(message "\"%s\" insert done." str) t)
|
898
|
+
(error
|
899
|
+
(pop-to-buffer (get-buffer mhc-calendar/buffer))
|
900
|
+
(message "\"%s\" insert failed." str) nil)))))))
|
901
|
+
|
902
|
+
(defun mhc-calendar/get-day (&optional type)
|
903
|
+
(let ((date (mhc-calendar-get-date))
|
904
|
+
datelst rlst)
|
905
|
+
(cond
|
906
|
+
((eq type 'minibuffer)
|
907
|
+
(setq datelst mhc-calendar/inserter-for-minibuffer))
|
908
|
+
((or (eq type 'duration) (eq type 'day))
|
909
|
+
(setq datelst mhc-calendar/inserter-for-draft))
|
910
|
+
(t (setq datelst mhc-calendar-inserter-date-list)))
|
911
|
+
(setq rlst (mhc-calendar/get-day-list date datelst))
|
912
|
+
(mhc-calendar/get-day-select rlst)))
|
913
|
+
|
914
|
+
(defun mhc-calendar/get-day-region (&optional type)
|
915
|
+
(let (cat datebeg dateend datetmp datelst rlst)
|
916
|
+
(if (not (mhc-date-p mhc-calendar/mark-date))
|
917
|
+
(error "No mark set in this buffer")
|
918
|
+
(setq dateend (mhc-calendar-get-date))
|
919
|
+
(setq datebeg mhc-calendar/mark-date)
|
920
|
+
;; swap
|
921
|
+
(when (mhc-date> datebeg dateend)
|
922
|
+
(setq datetmp dateend)
|
923
|
+
(setq dateend datebeg)
|
924
|
+
(setq datebeg datetmp))
|
925
|
+
(if (eq type 'day)
|
926
|
+
;; for X-SC-Day: (20000101 200000102 ... 20000131)
|
927
|
+
(progn
|
928
|
+
(setq datetmp nil)
|
929
|
+
(while (mhc-date<= datebeg dateend)
|
930
|
+
(setq datetmp (cons datebeg datetmp))
|
931
|
+
(setq datebeg (mhc-date++ datebeg)))
|
932
|
+
(mapconcat
|
933
|
+
(lambda (x)
|
934
|
+
(mhc-date-format x "%04d%02d%02d" yy mm dd))
|
935
|
+
(nreverse datetmp) " "))
|
936
|
+
(cond
|
937
|
+
((eq type 'minibuffer)
|
938
|
+
(setq datelst mhc-calendar/inserter-for-minibuffer))
|
939
|
+
((eq type 'duration)
|
940
|
+
(setq datelst mhc-calendar/inserter-for-draft))
|
941
|
+
(t (setq datelst mhc-calendar-inserter-date-list)))
|
942
|
+
(setq rlst (mhc-calendar/get-day-list datebeg datelst dateend))
|
943
|
+
(mhc-calendar/get-day-select rlst)))))
|
944
|
+
|
945
|
+
;; selector
|
946
|
+
(defvar mhc-calendar/select-alist nil)
|
947
|
+
(defvar mhc-calendar/select-hist nil)
|
948
|
+
(defvar mhc-calendar/select-map nil)
|
949
|
+
(defvar mhc-calendar/select-buffer "*Completions*")
|
950
|
+
|
951
|
+
(defun mhc-calendar/get-day-select (lst)
|
952
|
+
(cond
|
953
|
+
((= (length lst) 0) (error "Something error occur."))
|
954
|
+
((= (length lst) 1) (car lst))
|
955
|
+
(t
|
956
|
+
(let ((i 0)
|
957
|
+
(completion-ignore-case nil)
|
958
|
+
alst hist cell input)
|
959
|
+
(while lst
|
960
|
+
(setq cell (format "%d: %s" i (car lst)))
|
961
|
+
(setq hist (cons cell hist))
|
962
|
+
(setq alst (cons (cons cell (car lst)) alst))
|
963
|
+
(setq i (1+ i))
|
964
|
+
(setq lst (cdr lst)))
|
965
|
+
(setq hist (nreverse hist))
|
966
|
+
(setq alst (nreverse alst))
|
967
|
+
(setq mhc-calendar/select-alist alst) ;; for completion
|
968
|
+
(setq input (mhc-calendar/select-comp "Select format: " 'active))
|
969
|
+
(when (string= input "")
|
970
|
+
(setq input (cdr (car alst))))
|
971
|
+
(when (string-match "^\\([0-9]+\\)$" input)
|
972
|
+
(setq i (string-to-number input))
|
973
|
+
(when (> (length alst) i)
|
974
|
+
(setq input (cdr (nth i alst)))))
|
975
|
+
(when (string-match "^[0-9]+:[ \t]*" input)
|
976
|
+
(setq input (substring input (match-end 0))))
|
977
|
+
input))))
|
978
|
+
|
979
|
+
(defun mhc-calendar-count-days-region ()
|
980
|
+
(interactive)
|
981
|
+
(let ((mark mhc-calendar/mark-date)
|
982
|
+
(date (mhc-calendar-get-date)))
|
983
|
+
(if (null mark)
|
984
|
+
(error "No mark set in this buffer")
|
985
|
+
(setq date (mhc-date++ (mhc-date- (max mark date) (min mark date))))
|
986
|
+
(kill-new (int-to-string date))
|
987
|
+
(if (< date 7)
|
988
|
+
(message "%d days in region." date)
|
989
|
+
(if (= (% date 7) 0)
|
990
|
+
(message "%d days (%d weeks) in region." date (/ date 7))
|
991
|
+
(message "%d days (%d weeks + %d days) in region."
|
992
|
+
date (/ date 7) (% date 7)))))))
|
993
|
+
|
994
|
+
(if mhc-calendar/select-map
|
995
|
+
()
|
996
|
+
(setq mhc-calendar/select-map (make-sparse-keymap))
|
997
|
+
(define-key mhc-calendar/select-map "\t" 'mhc-calendar/select-comp-window)
|
998
|
+
(define-key mhc-calendar/select-map "\r" 'exit-minibuffer)
|
999
|
+
(define-key mhc-calendar/select-map "\n" 'exit-minibuffer)
|
1000
|
+
(define-key mhc-calendar/select-map "\C-g" 'abort-recursive-edit)
|
1001
|
+
(define-key mhc-calendar/select-map "\M-s" 'next-matching-history-element)
|
1002
|
+
(define-key mhc-calendar/select-map "\M-p" 'previous-history-element)
|
1003
|
+
(define-key mhc-calendar/select-map "\M-n" 'next-history-element)
|
1004
|
+
(define-key mhc-calendar/select-map "\M-v" 'switch-to-completions))
|
1005
|
+
|
1006
|
+
(defun mhc-calendar/select-comp-setup ()
|
1007
|
+
(mhc-calendar/select-comp-window ""))
|
1008
|
+
|
1009
|
+
(defun mhc-calendar/select-comp-window (&optional word)
|
1010
|
+
(interactive)
|
1011
|
+
(let ((completion-ignore-case nil)
|
1012
|
+
outp pos)
|
1013
|
+
(when (not word)
|
1014
|
+
(setq word (buffer-substring-no-properties
|
1015
|
+
(save-excursion (beginning-of-line) (point))
|
1016
|
+
(point-max)))
|
1017
|
+
(setq outp (try-completion word mhc-calendar/select-alist))
|
1018
|
+
(when (and (stringp outp)
|
1019
|
+
(window-minibuffer-p (get-buffer-window (current-buffer))))
|
1020
|
+
(beginning-of-line)
|
1021
|
+
(delete-region (point) (point-max))
|
1022
|
+
(insert outp)))
|
1023
|
+
(with-output-to-temp-buffer mhc-calendar/select-buffer
|
1024
|
+
(display-completion-list
|
1025
|
+
(all-completions word mhc-calendar/select-alist)))))
|
1026
|
+
|
1027
|
+
(defvar mhc-calendar/select-comp-active nil)
|
1028
|
+
(defadvice choose-completion-string (around mhc-calendar-select activate)
|
1029
|
+
ad-do-it
|
1030
|
+
(when mhc-calendar/select-comp-active
|
1031
|
+
(select-window (active-minibuffer-window))))
|
1032
|
+
|
1033
|
+
(defun mhc-calendar/select-comp (&optional prompt active)
|
1034
|
+
(let ((minibuffer-setup-hook minibuffer-setup-hook)
|
1035
|
+
(ret ""))
|
1036
|
+
(unless prompt (setq prompt "Select: "))
|
1037
|
+
(unwind-protect
|
1038
|
+
(progn
|
1039
|
+
;; Select minibuffer forcibly
|
1040
|
+
(setq mhc-calendar/select-comp-active t)
|
1041
|
+
;; completion buffer setup
|
1042
|
+
(when active
|
1043
|
+
(add-hook 'minibuffer-setup-hook 'mhc-calendar/select-comp-setup))
|
1044
|
+
(setq ret (read-from-minibuffer
|
1045
|
+
prompt
|
1046
|
+
nil mhc-calendar/select-map nil 'mhc-calendar/select-hist)))
|
1047
|
+
(setq mhc-calendar/select-comp-active nil)
|
1048
|
+
(remove-hook 'minibuffer-setup-hook
|
1049
|
+
'mhc-calendar/select-comp-setup)
|
1050
|
+
(and (buffer-live-p (get-buffer mhc-calendar/select-buffer))
|
1051
|
+
(kill-buffer mhc-calendar/select-buffer))
|
1052
|
+
ret)))
|
1053
|
+
|
1054
|
+
;; inserter
|
1055
|
+
(defun mhc-calendar/get-day-list-func (form)
|
1056
|
+
(let (func)
|
1057
|
+
(cond
|
1058
|
+
((stringp form) form)
|
1059
|
+
((symbolp form)
|
1060
|
+
(setq func (intern-soft
|
1061
|
+
(concat "mhc-calendar/inserter-" (symbol-name form))))
|
1062
|
+
(and func (funcall func))))))
|
1063
|
+
|
1064
|
+
(defun mhc-calendar/inserter-yy ()
|
1065
|
+
(format "%4d" mhc-yy))
|
1066
|
+
|
1067
|
+
(defun mhc-calendar/inserter-nengo ()
|
1068
|
+
(if (> mhc-yy 1987)
|
1069
|
+
(format "平成%2d年" (- mhc-yy 1988))
|
1070
|
+
(if (> mhc-yy 1924)
|
1071
|
+
(format "昭和%2d年" (- mhc-yy 1925))
|
1072
|
+
"昔々")))
|
1073
|
+
|
1074
|
+
(defun mhc-calendar/inserter-mm ()
|
1075
|
+
(format "%d" mhc-mm))
|
1076
|
+
|
1077
|
+
(defun mhc-calendar/inserter-mm02 ()
|
1078
|
+
(format "%02d" mhc-mm))
|
1079
|
+
|
1080
|
+
(defun mhc-calendar/inserter-mm2 ()
|
1081
|
+
(format "%2d" mhc-mm))
|
1082
|
+
|
1083
|
+
(defun mhc-calendar/inserter-mm-string ()
|
1084
|
+
(mhc-date-digit-to-mm-string mhc-mm))
|
1085
|
+
|
1086
|
+
(defun mhc-calendar/inserter-mm-string-long ()
|
1087
|
+
(mhc-date-digit-to-mm-string mhc-mm t))
|
1088
|
+
|
1089
|
+
(defun mhc-calendar/inserter-dd ()
|
1090
|
+
(format "%d" mhc-dd))
|
1091
|
+
|
1092
|
+
(defun mhc-calendar/inserter-dd02 ()
|
1093
|
+
(format "%02d" mhc-dd))
|
1094
|
+
|
1095
|
+
(defun mhc-calendar/inserter-dd2 ()
|
1096
|
+
(format "%2d" mhc-dd))
|
1097
|
+
|
1098
|
+
(defun mhc-calendar/inserter-ww ()
|
1099
|
+
(format "%d" mhc-ww))
|
1100
|
+
|
1101
|
+
(defun mhc-calendar/inserter-ww-string ()
|
1102
|
+
(mhc-date-digit-to-ww-string mhc-ww))
|
1103
|
+
|
1104
|
+
(defun mhc-calendar/inserter-ww-string-long ()
|
1105
|
+
(mhc-date-digit-to-ww-string mhc-ww t))
|
1106
|
+
|
1107
|
+
(defun mhc-calendar/inserter-ww-japanese ()
|
1108
|
+
(mhc-date-digit-to-ww-japanese-string mhc-ww))
|
1109
|
+
|
1110
|
+
(defun mhc-calendar/inserter-ww-japanese-long ()
|
1111
|
+
(mhc-date-digit-to-ww-japanese-string mhc-ww t))
|
1112
|
+
|
1113
|
+
(defun mhc-calendar/get-day-list (date &optional datelst dateend)
|
1114
|
+
(let (lst-org formlst retlst retlst2 ret con)
|
1115
|
+
(setq lst-org (or datelst mhc-calendar-inserter-date-list))
|
1116
|
+
(setq datelst lst-org)
|
1117
|
+
;; begin
|
1118
|
+
(mhc-date-let date
|
1119
|
+
(while datelst
|
1120
|
+
(setq formlst (car (car datelst)))
|
1121
|
+
(setq ret nil)
|
1122
|
+
(while formlst
|
1123
|
+
(setq ret (concat
|
1124
|
+
ret (mhc-calendar/get-day-list-func (car formlst))))
|
1125
|
+
(setq formlst (cdr formlst)))
|
1126
|
+
(setq retlst (cons ret retlst))
|
1127
|
+
(setq datelst (cdr datelst))))
|
1128
|
+
(setq retlst (nreverse retlst))
|
1129
|
+
(if (not dateend)
|
1130
|
+
retlst ;; return
|
1131
|
+
;; duration
|
1132
|
+
(setq datelst lst-org)
|
1133
|
+
(mhc-date-let dateend
|
1134
|
+
(while datelst
|
1135
|
+
(setq con (cdr (car datelst)))
|
1136
|
+
(if (listp con) ;; multiple connectoer
|
1137
|
+
(while con
|
1138
|
+
(setq formlst (car (car datelst)))
|
1139
|
+
(setq ret (car con))
|
1140
|
+
(while formlst
|
1141
|
+
(setq ret (concat
|
1142
|
+
ret (mhc-calendar/get-day-list-func (car formlst))))
|
1143
|
+
(setq formlst (cdr formlst)))
|
1144
|
+
(setq retlst2 (cons (concat (car retlst) ret) retlst2))
|
1145
|
+
(setq con (cdr con)))
|
1146
|
+
(setq formlst (car (car datelst)))
|
1147
|
+
(setq ret (cdr (car datelst)))
|
1148
|
+
(while formlst
|
1149
|
+
(setq ret (concat
|
1150
|
+
ret (mhc-calendar/get-day-list-func (car formlst))))
|
1151
|
+
(setq formlst (cdr formlst)))
|
1152
|
+
(setq retlst2 (cons (concat (car retlst) ret) retlst2)))
|
1153
|
+
(setq retlst (cdr retlst))
|
1154
|
+
(setq datelst (cdr datelst))))
|
1155
|
+
(nreverse retlst2))))
|
1156
|
+
|
1157
|
+
;; scan & move functions
|
1158
|
+
(defun mhc-calendar-scan (&optional hide-private)
|
1159
|
+
(interactive "P")
|
1160
|
+
(let ((date (mhc-calendar-get-date)))
|
1161
|
+
(mhc-calendar-quit)
|
1162
|
+
(mhc-goto-month date hide-private)
|
1163
|
+
(goto-char (point-min))
|
1164
|
+
(if (mhc-summary-search-date date)
|
1165
|
+
(progn
|
1166
|
+
(beginning-of-line)
|
1167
|
+
(if (not (pos-visible-in-window-p (point)))
|
1168
|
+
(recenter))))))
|
1169
|
+
|
1170
|
+
(defun mhc-calendar-quit ()
|
1171
|
+
(interactive)
|
1172
|
+
(let ((win (get-buffer-window mhc-calendar/buffer))
|
1173
|
+
(buf (get-buffer mhc-calendar/buffer)))
|
1174
|
+
(with-current-buffer buf
|
1175
|
+
(mhc-calendar/delete-overlay))
|
1176
|
+
(if (null win)
|
1177
|
+
()
|
1178
|
+
(bury-buffer buf)
|
1179
|
+
(if (null (one-window-p))
|
1180
|
+
(delete-windows-on buf)
|
1181
|
+
(set-window-buffer win (other-buffer))
|
1182
|
+
(select-window (next-window))))))
|
1183
|
+
|
1184
|
+
(defun mhc-calendar-input-exit ()
|
1185
|
+
(setq mhc-calendar/inserter-type nil)
|
1186
|
+
(setq mhc-calendar/inserter-call-buffer nil))
|
1187
|
+
|
1188
|
+
(defun mhc-calendar-exit ()
|
1189
|
+
(interactive)
|
1190
|
+
(mhc-calendar-quit)
|
1191
|
+
(remove-hook 'post-command-hook 'mhc-calendar/duration-show)
|
1192
|
+
(kill-buffer (get-buffer mhc-calendar/buffer)))
|
1193
|
+
|
1194
|
+
(defun mhc-calendar-goto-month (&optional date)
|
1195
|
+
(interactive)
|
1196
|
+
(mhc-calendar/goto-date (if (integerp date) date (mhc-input-month "Month "))))
|
1197
|
+
|
1198
|
+
(defun mhc-calendar-rescan ()
|
1199
|
+
(interactive)
|
1200
|
+
(set-buffer (get-buffer mhc-calendar/buffer))
|
1201
|
+
(let ((cdate mhc-calendar-date)
|
1202
|
+
(pdate (mhc-calendar-get-date)))
|
1203
|
+
(setq mhc-calendar-date nil)
|
1204
|
+
(mhc-calendar/create-buffer cdate)
|
1205
|
+
(mhc-calendar/goto-date pdate)))
|
1206
|
+
|
1207
|
+
(defun mhc-calendar-goto-home ()
|
1208
|
+
(interactive)
|
1209
|
+
(setq mhc-calendar-view-summary
|
1210
|
+
(not (and (eq last-command 'mhc-calendar-goto-home)
|
1211
|
+
mhc-calendar-view-summary)))
|
1212
|
+
(mhc-calendar/goto-date (mhc-calendar-get-date))
|
1213
|
+
(set-window-start (selected-window) (point-min)))
|
1214
|
+
|
1215
|
+
(defun mhc-calendar-next-day (&optional arg)
|
1216
|
+
(interactive "p")
|
1217
|
+
(let ((date (mhc-calendar-get-date)))
|
1218
|
+
(mhc-calendar/goto-date (+ date arg))))
|
1219
|
+
|
1220
|
+
(defun mhc-calendar-prev-day (&optional arg)
|
1221
|
+
(interactive "p")
|
1222
|
+
(mhc-calendar-next-day (- arg)))
|
1223
|
+
|
1224
|
+
(defun mhc-calendar-next-week (&optional arg)
|
1225
|
+
(interactive "p")
|
1226
|
+
(if (or (mhc-calendar/in-summary-p) (mhc-calendar/in-summary-hnf-p))
|
1227
|
+
(let ((pos (point)))
|
1228
|
+
(forward-line)
|
1229
|
+
(if (eobp) (goto-char pos)))
|
1230
|
+
(mhc-calendar-next-day (* arg 7))))
|
1231
|
+
|
1232
|
+
(defun mhc-calendar-prev-week (&optional arg)
|
1233
|
+
(interactive "p")
|
1234
|
+
(if (or (mhc-calendar/in-summary-p) (mhc-calendar/in-summary-hnf-p))
|
1235
|
+
(let ((pos (point)))
|
1236
|
+
(forward-line -1)
|
1237
|
+
(if (or (mhc-calendar/in-summary-p) (mhc-calendar/in-summary-hnf-p))
|
1238
|
+
()
|
1239
|
+
(goto-char pos)))
|
1240
|
+
(mhc-calendar-next-day (- (* arg 7)))))
|
1241
|
+
|
1242
|
+
(defun mhc-calendar-next-month (&optional arg)
|
1243
|
+
(interactive "p")
|
1244
|
+
(mhc-calendar/goto-date (mhc-date-mm+ (mhc-calendar-get-date) arg)))
|
1245
|
+
|
1246
|
+
(defun mhc-calendar-prev-month (&optional arg)
|
1247
|
+
(interactive "p")
|
1248
|
+
(mhc-calendar-next-month (- arg)))
|
1249
|
+
|
1250
|
+
(defun mhc-calendar-next-year (&optional arg)
|
1251
|
+
(interactive "p")
|
1252
|
+
(mhc-calendar/goto-date (mhc-date-yy+ (mhc-calendar-get-date) arg)))
|
1253
|
+
|
1254
|
+
(defun mhc-calendar-prev-year (&optional arg)
|
1255
|
+
(interactive "p")
|
1256
|
+
(mhc-calendar-next-year (- arg)))
|
1257
|
+
|
1258
|
+
(defun mhc-calendar-inc-month (&optional arg)
|
1259
|
+
(interactive "p")
|
1260
|
+
(set-buffer (get-buffer mhc-calendar/buffer))
|
1261
|
+
(let* ((dnew (mhc-date-mm+ mhc-calendar-date arg))
|
1262
|
+
(ddold (mhc-date-dd (mhc-calendar-get-date)))
|
1263
|
+
(dnew2 (mhc-date-let dnew
|
1264
|
+
(if (mhc-date/check yy mm ddold)
|
1265
|
+
(mhc-date-new yy mm ddold)
|
1266
|
+
(mhc-date-new yy mm (mhc-date/last-day-of-month yy mm))))))
|
1267
|
+
(mhc-calendar/create-buffer dnew)
|
1268
|
+
(mhc-calendar/goto-date dnew2)))
|
1269
|
+
|
1270
|
+
(defun mhc-calendar-dec-month (&optional arg)
|
1271
|
+
(interactive "p")
|
1272
|
+
(mhc-calendar-inc-month (- arg)))
|
1273
|
+
|
1274
|
+
(defun mhc-calendar-get-date ()
|
1275
|
+
(when (mhc-calendar-p)
|
1276
|
+
(if (mhc-calendar/in-date-p)
|
1277
|
+
(mhc-calendar/in-date-p)
|
1278
|
+
(if (or (mhc-calendar/in-summary-p) (mhc-calendar/in-summary-hnf-p))
|
1279
|
+
mhc-calendar-view-date
|
1280
|
+
(let* ((pos (point))
|
1281
|
+
(col (current-column))
|
1282
|
+
(colnum (mhc-calendar/get-date-colnum col))
|
1283
|
+
(line (+ (count-lines (point-min) (point)) (if (= col 0) 1 0)))
|
1284
|
+
(date (mhc-date-mm+ mhc-calendar-date colnum))
|
1285
|
+
(date1 (mhc-date-mm-first date))
|
1286
|
+
(datelast (mhc-date-mm-last date))
|
1287
|
+
daypos)
|
1288
|
+
(cond
|
1289
|
+
((< line 3) date1)
|
1290
|
+
((> line 9) datelast)
|
1291
|
+
(t
|
1292
|
+
(setq daypos (next-single-property-change (point) 'mhc-calendar/date-prop))
|
1293
|
+
(if daypos
|
1294
|
+
(progn
|
1295
|
+
(goto-char daypos)
|
1296
|
+
(if (= colnum (mhc-calendar/get-date-colnum (current-column)))
|
1297
|
+
(mhc-calendar/in-date-p)
|
1298
|
+
(goto-char pos)
|
1299
|
+
(if (or (and (goto-char (previous-single-property-change
|
1300
|
+
(point) 'mhc-calendar/date-prop))
|
1301
|
+
(mhc-calendar/in-date-p))
|
1302
|
+
(and (goto-char (previous-single-property-change
|
1303
|
+
(point) 'mhc-calendar/date-prop))
|
1304
|
+
(mhc-calendar/in-date-p)))
|
1305
|
+
(if (= colnum (mhc-calendar/get-date-colnum (current-column)))
|
1306
|
+
(mhc-calendar/in-date-p)
|
1307
|
+
datelast)
|
1308
|
+
datelast)))
|
1309
|
+
datelast))))))))
|
1310
|
+
|
1311
|
+
(defun mhc-calendar-view-date ()
|
1312
|
+
(and (mhc-calendar-p) mhc-calendar-view-date))
|
1313
|
+
|
1314
|
+
;; mouse function
|
1315
|
+
(defun mhc-calendar-day-at-mouse (event)
|
1316
|
+
(interactive "e")
|
1317
|
+
(set-buffer (mhc-calendar/event-buffer event))
|
1318
|
+
(pop-to-buffer (mhc-calendar/event-buffer event))
|
1319
|
+
(goto-char (mhc-calendar/event-point event))
|
1320
|
+
(cond
|
1321
|
+
((mhc-calendar/in-date-p)
|
1322
|
+
(mhc-calendar-goto-home))
|
1323
|
+
((mhc-calendar/in-summary-p)
|
1324
|
+
(mhc-calendar/view-file (mhc-calendar/in-summary-p)))
|
1325
|
+
((mhc-calendar/in-summary-hnf-p)
|
1326
|
+
(mhc-calendar/hnf-view))
|
1327
|
+
(t (message "Nothing to do in this point."))))
|
1328
|
+
|
1329
|
+
;; mark
|
1330
|
+
(defun mhc-calendar-set-mark-command (arg)
|
1331
|
+
(interactive "P")
|
1332
|
+
(if (null arg)
|
1333
|
+
(progn
|
1334
|
+
(setq mhc-calendar/mark-date (mhc-calendar-get-date))
|
1335
|
+
(message "Mark set"))
|
1336
|
+
(setq mhc-calendar/mark-date nil)
|
1337
|
+
(mhc-calendar/duration-show)
|
1338
|
+
(message "Mark unset")))
|
1339
|
+
|
1340
|
+
(defun mhc-calendar-exchange-point-and-mark ()
|
1341
|
+
(interactive)
|
1342
|
+
(let ((mark mhc-calendar/mark-date)
|
1343
|
+
(date (mhc-calendar-get-date)))
|
1344
|
+
(if (null mark)
|
1345
|
+
(error "No mark set in this buffer")
|
1346
|
+
(setq mhc-calendar/mark-date date)
|
1347
|
+
(mhc-calendar/goto-date mark)
|
1348
|
+
(mhc-calendar/duration-show))))
|
1349
|
+
|
1350
|
+
;; post-command-hook
|
1351
|
+
(defun mhc-calendar/duration-show ()
|
1352
|
+
(when (eq this-command 'keyboard-quit)
|
1353
|
+
(setq mhc-calendar/mark-date nil))
|
1354
|
+
(if (not (mhc-calendar-p))
|
1355
|
+
(remove-hook 'post-command-hook 'mhc-calendar/duration-show)
|
1356
|
+
(when (mhc-calendar-p)
|
1357
|
+
(mhc-calendar/delete-overlay)
|
1358
|
+
(setq mode-name "mhc-calendar")
|
1359
|
+
(when (and mhc-calendar-use-duration-show mhc-calendar/mark-date)
|
1360
|
+
(let ((datebeg mhc-calendar/mark-date)
|
1361
|
+
(dateend (point))
|
1362
|
+
datetmp pos)
|
1363
|
+
(save-excursion
|
1364
|
+
(goto-char dateend)
|
1365
|
+
(setq dateend (mhc-calendar-get-date))
|
1366
|
+
(when (and datebeg dateend
|
1367
|
+
(not (mhc-date= datebeg dateend)))
|
1368
|
+
(when (mhc-date> datebeg dateend)
|
1369
|
+
(setq datetmp dateend)
|
1370
|
+
(setq dateend datebeg)
|
1371
|
+
(setq datebeg datetmp))
|
1372
|
+
(when (or (eq mhc-calendar-use-duration-show 'modeline)
|
1373
|
+
(eq mhc-calendar-use-duration-show 'mixed))
|
1374
|
+
(setq mode-name
|
1375
|
+
(format "mhc-calendar %s-%s"
|
1376
|
+
(mhc-date-format
|
1377
|
+
datebeg "%04d/%02d/%02d(%s)"
|
1378
|
+
yy mm dd (mhc-date-digit-to-ww-string ww))
|
1379
|
+
(mhc-date-format
|
1380
|
+
dateend "%04d/%02d/%02d(%s)"
|
1381
|
+
yy mm dd (mhc-date-digit-to-ww-string ww)))))
|
1382
|
+
(when (or (eq mhc-calendar-use-duration-show 'face)
|
1383
|
+
(eq mhc-calendar-use-duration-show 'mixed))
|
1384
|
+
(goto-char (point-min))
|
1385
|
+
(setq datetmp (mhc-calendar-get-date))
|
1386
|
+
(if (mhc-date< datebeg datetmp)
|
1387
|
+
(setq datebeg datetmp))
|
1388
|
+
(setq pos t)
|
1389
|
+
(while (and pos (mhc-date<= datebeg dateend))
|
1390
|
+
(setq pos (mhc-calendar/tp-any
|
1391
|
+
(point-min) (point-max)
|
1392
|
+
'mhc-calendar/date-prop datebeg))
|
1393
|
+
(when pos
|
1394
|
+
(overlay-put (make-overlay pos (+ pos 2))
|
1395
|
+
'face 'mhc-calendar-face-duration))
|
1396
|
+
(setq datebeg (mhc-date++ datebeg)))))))
|
1397
|
+
(when (or (eq mhc-calendar-use-duration-show 'modeline)
|
1398
|
+
(eq mhc-calendar-use-duration-show 'mixed))
|
1399
|
+
(force-mode-line-update))))))
|
1400
|
+
|
1401
|
+
;; misc
|
1402
|
+
(defun mhc-calendar/delete-overlay ()
|
1403
|
+
(when (or (eq mhc-calendar-use-duration-show 'face)
|
1404
|
+
(eq mhc-calendar-use-duration-show 'mixed))
|
1405
|
+
(let ((ovlin (overlays-in (point-min) (point-max))))
|
1406
|
+
(while ovlin
|
1407
|
+
(delete-overlay (car ovlin))
|
1408
|
+
(setq ovlin (cdr ovlin))))))
|
1409
|
+
|
1410
|
+
(defun mhc-calendar/delete-region (yy mm dd pos)
|
1411
|
+
(condition-case err
|
1412
|
+
(if (mhc-date/check yy mm dd)
|
1413
|
+
(progn
|
1414
|
+
(delete-region (point) pos)
|
1415
|
+
(mhc-date-new yy mm dd))
|
1416
|
+
nil)
|
1417
|
+
(error nil)))
|
1418
|
+
|
1419
|
+
(defun mhc-calendar-view-exit-action (buff)
|
1420
|
+
(kill-buffer buff)
|
1421
|
+
(and (get-buffer mhc-calendar/buffer) (mhc-window-pop)))
|
1422
|
+
|
1423
|
+
;; mhc-minibuffer support
|
1424
|
+
(defun mhc-minibuf-insert-calendar ()
|
1425
|
+
(interactive)
|
1426
|
+
(let ((yy 1) (mm 1) (dd 1) date pos)
|
1427
|
+
(setq mhc-calendar/inserter-type 'minibuffer)
|
1428
|
+
(setq mhc-calendar/inserter-call-buffer (current-buffer))
|
1429
|
+
(save-excursion
|
1430
|
+
(setq pos (point))
|
1431
|
+
(skip-chars-backward "0-9/")
|
1432
|
+
(cond
|
1433
|
+
((looking-at "\\([12][0-9][0-9][0-9]\\)/\\([0-2][0-9]\\)/\\([0-3][0-9]\\)")
|
1434
|
+
(setq yy (mhc-calendar/buffer-substring-to-num 1))
|
1435
|
+
(setq mm (mhc-calendar/buffer-substring-to-num 2))
|
1436
|
+
(setq dd (mhc-calendar/buffer-substring-to-num 3))
|
1437
|
+
(setq date (mhc-calendar/delete-region yy mm dd pos)))
|
1438
|
+
((looking-at "\\([12][0-9][0-9][0-9]\\)/\\([0-2][0-9]\\)/?")
|
1439
|
+
(setq yy (mhc-calendar/buffer-substring-to-num 1))
|
1440
|
+
(setq mm (mhc-calendar/buffer-substring-to-num 2))
|
1441
|
+
(setq date (mhc-calendar/delete-region yy mm dd pos)))
|
1442
|
+
((looking-at "\\([12][0-9][0-9][0-9]\\)/?")
|
1443
|
+
(setq yy (mhc-calendar/buffer-substring-to-num 1))
|
1444
|
+
(setq date (mhc-calendar/delete-region yy mm dd pos)))))
|
1445
|
+
(mhc-calendar date)))
|
1446
|
+
|
1447
|
+
;; mhc-draft support
|
1448
|
+
(defun mhc-draft-insert-calendar ()
|
1449
|
+
(interactive)
|
1450
|
+
(let ((yy 1) (mm 1) (dd 1)
|
1451
|
+
(case-fold-search t)
|
1452
|
+
date pos)
|
1453
|
+
(setq mhc-calendar/inserter-call-buffer (current-buffer))
|
1454
|
+
(setq mhc-calendar/inserter-type nil)
|
1455
|
+
(save-excursion
|
1456
|
+
(setq pos (point))
|
1457
|
+
(goto-char (point-min))
|
1458
|
+
(if (and (re-search-forward
|
1459
|
+
(concat "^" (regexp-quote mail-header-separator) "$\\|^$") nil t)
|
1460
|
+
(< pos (point)))
|
1461
|
+
(progn
|
1462
|
+
(setq mhc-calendar/inserter-type 'duration)
|
1463
|
+
(save-excursion
|
1464
|
+
(goto-char pos)
|
1465
|
+
(and (re-search-backward "x-[^:]+: " nil t)
|
1466
|
+
(looking-at "^x-sc-day: ")
|
1467
|
+
(setq mhc-calendar/inserter-type 'day)))))
|
1468
|
+
(goto-char pos)
|
1469
|
+
(skip-chars-backward "0-9")
|
1470
|
+
(cond
|
1471
|
+
((looking-at "\\([12][0-9][0-9][0-9]\\)\\([0-2][0-9]\\)\\([0-3][0-9]\\)")
|
1472
|
+
(setq yy (mhc-calendar/buffer-substring-to-num 1))
|
1473
|
+
(setq mm (mhc-calendar/buffer-substring-to-num 2))
|
1474
|
+
(setq dd (mhc-calendar/buffer-substring-to-num 3))
|
1475
|
+
(setq date (mhc-calendar/delete-region yy mm dd pos)))
|
1476
|
+
((looking-at "\\([12][0-9][0-9][0-9]\\)\\([0-2][0-9]\\)")
|
1477
|
+
(setq yy (mhc-calendar/buffer-substring-to-num 1))
|
1478
|
+
(setq mm (mhc-calendar/buffer-substring-to-num 2))
|
1479
|
+
(setq date (mhc-calendar/delete-region yy mm dd pos)))
|
1480
|
+
((looking-at "\\([12][0-9][0-9][0-9]\\)")
|
1481
|
+
(setq yy (mhc-calendar/buffer-substring-to-num 1))
|
1482
|
+
(setq date (mhc-calendar/delete-region yy mm dd pos)))))
|
1483
|
+
(mhc-calendar date)))
|
1484
|
+
|
1485
|
+
;; hnf-mode interface
|
1486
|
+
(defun mhc-calendar/hnf-get-filename (date)
|
1487
|
+
(expand-file-name
|
1488
|
+
(mhc-date-format date "d%04d%02d%02d.hnf" yy mm dd)
|
1489
|
+
(if hnf-diary-year-directory-flag
|
1490
|
+
(expand-file-name (mhc-date-format date "%04d" yy) hnf-diary-dir)
|
1491
|
+
hnf-diary-dir)))
|
1492
|
+
|
1493
|
+
(defun mhc-calendar/hnf-file-list (date)
|
1494
|
+
(let ((i -1) flst)
|
1495
|
+
(setq date (mhc-date-mm+ date -1))
|
1496
|
+
(while (< i 2)
|
1497
|
+
(let* ((dir (if hnf-diary-year-directory-flag
|
1498
|
+
(expand-file-name (mhc-date-format date "%04d" yy) hnf-diary-dir)
|
1499
|
+
(expand-file-name hnf-diary-dir)))
|
1500
|
+
(fnexp (mhc-date-format date "d%04d%02d[0-3][0-9]\\.hnf" yy mm)))
|
1501
|
+
(if (file-directory-p dir)
|
1502
|
+
(setq flst (append (directory-files dir nil fnexp 'no-sort) flst))
|
1503
|
+
(setq flst nil))
|
1504
|
+
(setq date (mhc-date-mm+ date 1))
|
1505
|
+
(setq i (1+ i))))
|
1506
|
+
flst))
|
1507
|
+
|
1508
|
+
(defvar mhc-calendar/hnf-ignore-categories nil)
|
1509
|
+
|
1510
|
+
(defun mhc-calendar-hnf-edit (&optional args)
|
1511
|
+
(interactive "P")
|
1512
|
+
(if (not mhc-calendar-link-hnf)
|
1513
|
+
(message "Nothing to do.")
|
1514
|
+
(let ((hnffile (mhc-calendar/hnf-get-filename (mhc-calendar-get-date)))
|
1515
|
+
(mhcfile (mhc-calendar/in-summary-p))
|
1516
|
+
(count (mhc-calendar/in-summary-hnf-p))
|
1517
|
+
cats subj uri lst)
|
1518
|
+
(save-excursion
|
1519
|
+
(when (and args mhcfile (file-readable-p mhcfile))
|
1520
|
+
(unless mhc-calendar/hnf-ignore-categories
|
1521
|
+
(setq lst mhc-icon-function-alist)
|
1522
|
+
(while lst
|
1523
|
+
(setq mhc-calendar/hnf-ignore-categories
|
1524
|
+
(cons (downcase (car (car lst)))
|
1525
|
+
mhc-calendar/hnf-ignore-categories))
|
1526
|
+
(setq lst (cdr lst))))
|
1527
|
+
(with-temp-buffer
|
1528
|
+
(insert-file-contents mhcfile)
|
1529
|
+
(mhc-decode-header)
|
1530
|
+
(mhc-header-narrowing
|
1531
|
+
(setq cats (mhc-header-get-value "x-sc-category"))
|
1532
|
+
(setq subj (mhc-header-get-value "x-sc-subject"))
|
1533
|
+
(setq lst (mhc-misc-split cats))
|
1534
|
+
(when (member "Link" lst)
|
1535
|
+
(setq uri (or (mhc-header-get-value "x-uri")
|
1536
|
+
(mhc-header-get-value "x-url"))))
|
1537
|
+
(setq cats nil)
|
1538
|
+
(while lst
|
1539
|
+
(unless (member (downcase (car lst))
|
1540
|
+
mhc-calendar/hnf-ignore-categories)
|
1541
|
+
(setq cats (cons (car lst) cats)))
|
1542
|
+
(setq lst (cdr lst)))
|
1543
|
+
(setq cats (nreverse cats))))))
|
1544
|
+
(find-file-other-window hnffile)
|
1545
|
+
(hnf-mode)
|
1546
|
+
(and (integerp count) (mhc-calendar/hnf-search-title count))
|
1547
|
+
(when subj
|
1548
|
+
(goto-char (point-max))
|
1549
|
+
(insert "\n")
|
1550
|
+
(when cats
|
1551
|
+
(insert (format "CAT %s\n"
|
1552
|
+
(mapconcat 'identity cats " "))))
|
1553
|
+
(if uri
|
1554
|
+
(insert (format "LNEW %s %s\n" uri subj))
|
1555
|
+
(insert (format "NEW %s\n" subj)))))))
|
1556
|
+
;; xxxxx
|
1557
|
+
|
1558
|
+
(defun mhc-calendar/hnf-view ()
|
1559
|
+
(interactive)
|
1560
|
+
(let ((fname (mhc-calendar/hnf-get-filename (mhc-calendar-get-date)))
|
1561
|
+
(count (mhc-calendar/in-summary-hnf-p)))
|
1562
|
+
(if (not (file-readable-p fname))
|
1563
|
+
(message "File does not exist (%s)." fname)
|
1564
|
+
(mhc-window-push)
|
1565
|
+
(view-file-other-window fname)
|
1566
|
+
(setq view-exit-action 'mhc-calendar-view-exit-action)
|
1567
|
+
(and (integerp count) (mhc-calendar/hnf-search-title count)))))
|
1568
|
+
|
1569
|
+
(defun mhc-calendar/hnf-search-title (count)
|
1570
|
+
(goto-char (point-min))
|
1571
|
+
(while (and (> count 0) (not (eobp)))
|
1572
|
+
(re-search-forward "^\\(L?NEW\\|L?SUB\\)[ \t]+" nil t)
|
1573
|
+
(setq count (1- count)))
|
1574
|
+
(beginning-of-line)
|
1575
|
+
(recenter (/ (window-height) 4)))
|
1576
|
+
|
1577
|
+
(defun mhc-calendar/hnf-mark-diary-entries ()
|
1578
|
+
(let ((cdate (mhc-date-mm-first (mhc-date-mm+ mhc-calendar-date -1)))
|
1579
|
+
(edate (mhc-date-mm-last (mhc-date-mm+ mhc-calendar-date 1)))
|
1580
|
+
(flst (mhc-calendar/hnf-file-list mhc-calendar-date))
|
1581
|
+
(mark "'"))
|
1582
|
+
(mhc-face-put mark 'mhc-calendar-hnf-face-mark)
|
1583
|
+
(while (<= cdate edate)
|
1584
|
+
(if (member (mhc-date-format cdate "d%04d%02d%02d.hnf" yy mm dd) flst)
|
1585
|
+
(progn
|
1586
|
+
(goto-char (+ 2 (mhc-calendar/tp-any (point-min) (point-max)
|
1587
|
+
'mhc-calendar/date-prop cdate)))
|
1588
|
+
(insert mark)
|
1589
|
+
(if (eq (char-after (point)) ?\ )
|
1590
|
+
(delete-char 1))))
|
1591
|
+
(setq cdate (1+ cdate)))))
|
1592
|
+
|
1593
|
+
(defun mhc-calendar/hnf-summary-insert ()
|
1594
|
+
(let ((fname (mhc-calendar/hnf-get-filename mhc-calendar-view-date))
|
1595
|
+
(buffer-read-only nil)
|
1596
|
+
(newmark "#") (sub "@") (cat "")
|
1597
|
+
(count 1) (ncount 1)
|
1598
|
+
new summary str uri)
|
1599
|
+
(if (not (file-readable-p fname))
|
1600
|
+
()
|
1601
|
+
(goto-char (point-max))
|
1602
|
+
(with-temp-buffer ;; hnf-mode.el require APEL :-)
|
1603
|
+
(insert-file-contents fname)
|
1604
|
+
(goto-char (point-min))
|
1605
|
+
(mhc-face-put sub 'mhc-calendar-hnf-face-subtag)
|
1606
|
+
(while (not (eobp))
|
1607
|
+
(cond
|
1608
|
+
;; CAT
|
1609
|
+
((looking-at "^CAT[ \t]+\\(.*\\)$")
|
1610
|
+
(setq cat (buffer-substring (match-beginning 1) (match-end 1)))
|
1611
|
+
(while (string-match "[ \t]+" cat)
|
1612
|
+
(setq cat (concat (substring cat 0 (match-beginning 0))
|
1613
|
+
"]["
|
1614
|
+
(substring cat (match-end 0)))))
|
1615
|
+
(setq cat (concat "[" cat "]"))
|
1616
|
+
(mhc-face-put cat 'mhc-calendar-hnf-face-cat)
|
1617
|
+
(setq cat (concat cat " ")))
|
1618
|
+
;; NEW
|
1619
|
+
((looking-at "^NEW[ \t]+\\(.*\\)$")
|
1620
|
+
(setq str (buffer-substring (match-beginning 1) (match-end 1)))
|
1621
|
+
(mhc-face-put str 'mhc-calendar-hnf-face-new)
|
1622
|
+
(setq new (format "%s%d" newmark ncount))
|
1623
|
+
(mhc-face-put new 'mhc-calendar-hnf-face-newtag)
|
1624
|
+
(setq str (concat " " new " " cat str "\n"))
|
1625
|
+
(put-text-property 0 (length str) 'mhc-calendar/summary-hnf-prop count str)
|
1626
|
+
(setq summary (concat summary str)
|
1627
|
+
count (1+ count)
|
1628
|
+
ncount (1+ ncount)
|
1629
|
+
cat ""))
|
1630
|
+
;; LNEW
|
1631
|
+
((looking-at "^LNEW[ \t]+\\([^ \t]+\\)[ \t]+\\(.*\\)$")
|
1632
|
+
(setq uri (concat "<"
|
1633
|
+
(buffer-substring (match-beginning 1) (match-end 1))
|
1634
|
+
">"))
|
1635
|
+
(mhc-face-put uri 'mhc-calendar-hnf-face-uri)
|
1636
|
+
(setq str (buffer-substring (match-beginning 2) (match-end 2)))
|
1637
|
+
(mhc-face-put str 'mhc-calendar-hnf-face-new)
|
1638
|
+
(setq new (format "%s%d" newmark ncount))
|
1639
|
+
(mhc-face-put new 'mhc-calendar-hnf-face-newtag)
|
1640
|
+
(setq str (concat " " new " " cat str " " uri "\n"))
|
1641
|
+
(put-text-property 0 (length str) 'mhc-calendar/summary-hnf-prop count str)
|
1642
|
+
(setq summary (concat summary str)
|
1643
|
+
count (1+ count)
|
1644
|
+
ncount (1+ ncount)
|
1645
|
+
cat ""))
|
1646
|
+
;; SUB
|
1647
|
+
((looking-at "^SUB[ \t]+\\(.*\\)$")
|
1648
|
+
(setq str (buffer-substring (match-beginning 1) (match-end 1)))
|
1649
|
+
(mhc-face-put str 'mhc-calendar-hnf-face-sub)
|
1650
|
+
(setq str (concat " " sub " " cat str "\n"))
|
1651
|
+
(put-text-property 0 (length str) 'mhc-calendar/summary-hnf-prop count str)
|
1652
|
+
(setq summary (concat summary str)
|
1653
|
+
count (1+ count)
|
1654
|
+
cat ""))
|
1655
|
+
;; LSUB
|
1656
|
+
((looking-at "^LSUB[ \t]+\\([^ \t]+\\)[ \t]+\\(.*\\)$")
|
1657
|
+
(setq uri (concat "<"
|
1658
|
+
(buffer-substring (match-beginning 1) (match-end 1))
|
1659
|
+
">"))
|
1660
|
+
(mhc-face-put uri 'mhc-calendar-hnf-face-uri)
|
1661
|
+
(setq str (buffer-substring (match-beginning 2) (match-end 2)))
|
1662
|
+
(mhc-face-put str 'mhc-calendar-hnf-face-sub)
|
1663
|
+
(setq str (concat " " sub " " cat str " " uri "\n"))
|
1664
|
+
(put-text-property 0 (length str) 'mhc-calendar/summary-hnf-prop count str)
|
1665
|
+
(setq summary (concat summary str)
|
1666
|
+
count (1+ count)
|
1667
|
+
cat "")))
|
1668
|
+
(forward-line)))
|
1669
|
+
(if summary (insert "\n" summary))
|
1670
|
+
(delete-char -1)
|
1671
|
+
(set-buffer-modified-p nil))))
|
1672
|
+
|
1673
|
+
(defun mhc-calendar-hnf-face-setup ()
|
1674
|
+
(interactive)
|
1675
|
+
(let ((ow (called-interactively-p 'interactive)))
|
1676
|
+
(mhc-face-setup-internal mhc-calendar-hnf-face-alist ow)
|
1677
|
+
(mhc-face-setup-internal mhc-calendar-hnf-face-alist-internal nil)))
|
1678
|
+
|
1679
|
+
;;; Pseudo MUA Backend Methods:
|
1680
|
+
(defun mhc-calendar-insert-summary-contents (inserter)
|
1681
|
+
(let ((beg (point))
|
1682
|
+
(name (or (mhc-record-name
|
1683
|
+
(mhc-schedule-record mhc-tmp-schedule))
|
1684
|
+
"Dummy")))
|
1685
|
+
(funcall inserter)
|
1686
|
+
(put-text-property beg (point) 'mhc-calendar/summary-prop name)
|
1687
|
+
(insert "\n")))
|
1688
|
+
|
1689
|
+
(provide 'mhc-calendar)
|
1690
|
+
(put 'mhc-calendar 'insert-summary-contents 'mhc-calendar-insert-summary-contents)
|
1691
|
+
|
1692
|
+
;;; Copyright Notice:
|
1693
|
+
|
1694
|
+
;; Copyright (C) 1999, 2000 Yoshinari Nomura. All rights reserved.
|
1695
|
+
;; Copyright (C) 2000 MHC developing team. All rights reserved.
|
1696
|
+
|
1697
|
+
;; Redistribution and use in source and binary forms, with or without
|
1698
|
+
;; modification, are permitted provided that the following conditions
|
1699
|
+
;; are met:
|
1700
|
+
;;
|
1701
|
+
;; 1. Redistributions of source code must retain the above copyright
|
1702
|
+
;; notice, this list of conditions and the following disclaimer.
|
1703
|
+
;; 2. Redistributions in binary form must reproduce the above copyright
|
1704
|
+
;; notice, this list of conditions and the following disclaimer in the
|
1705
|
+
;; documentation and/or other materials provided with the distribution.
|
1706
|
+
;; 3. Neither the name of the team nor the names of its contributors
|
1707
|
+
;; may be used to endorse or promote products derived from this software
|
1708
|
+
;; without specific prior written permission.
|
1709
|
+
;;
|
1710
|
+
;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS''
|
1711
|
+
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
1712
|
+
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
1713
|
+
;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
1714
|
+
;; THE TEAM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
1715
|
+
;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1716
|
+
;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
1717
|
+
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
1718
|
+
;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
1719
|
+
;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
1720
|
+
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
1721
|
+
;; OF THE POSSIBILITY OF SUCH DAMAGE.
|
1722
|
+
|
1723
|
+
;; mhc-calendar.el ends here
|