aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2014-05-04 08:16:58 +0800
committerLeo Liu2014-05-04 08:16:58 +0800
commitbbdcf64f499636ba9567e8fed8f209e06380352c (patch)
tree36f63f7f60f4b8972576b843b1354244e7f82f5f
parentc3a435feddf2e1c1e74e41a05d4dd8a59bc766b0 (diff)
downloademacs-bbdcf64f499636ba9567e8fed8f209e06380352c.tar.gz
emacs-bbdcf64f499636ba9567e8fed8f209e06380352c.zip
Support Chinese diary entries in calendar and diary
* doc/emacs/cal-xtra.texi (Non-Gregorian Diary): Document new features for Chinese calendar and diary. * etc/NEWS: Mention support for Chinese dates in calendar and diary. * lisp/calendar/cal-china.el (calendar-chinese-month-name-array): New var. (calendar-chinese-from-absolute-for-diary) (calendar-chinese-to-absolute-for-diary) (calendar-chinese-mark-date-pattern, diary-chinese-mark-entries) (diary-chinese-list-entries): New functions to list and mark Chinese diary entries in the calendar window. (diary-chinese-anniversary) (diary-chinese-insert-anniversary-entry) (diary-chinese-insert-entry, diary-chinese-insert-monthly-entry) (diary-chinese-insert-yearly-entry): New commands to insert Chinese diary entries. * lisp/calendar/cal-menu.el (cal-menu-diary-menu): Add entries for inserting Chinese diary entries. * lisp/calendar/calendar.el (diary-chinese-entry-symbol): New customizable variable. (calendar-mode-map): Add bindings for inserting Chinese diary entries. * lisp/calendar/diary-lib.el (diary-font-lock-keywords): Support font-locking Chinese dates. Fixes: debbugs:17393
-rw-r--r--doc/emacs/ChangeLog5
-rw-r--r--doc/emacs/cal-xtra.texi30
-rw-r--r--etc/ChangeLog4
-rw-r--r--etc/NEWS12
-rw-r--r--lisp/ChangeLog26
-rw-r--r--lisp/calendar/cal-china.el118
-rw-r--r--lisp/calendar/cal-menu.el5
-rw-r--r--lisp/calendar/calendar.el10
-rw-r--r--lisp/calendar/diary-lib.el8
9 files changed, 211 insertions, 7 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index d7fa9c66729..46eee3c31a9 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,8 @@
12014-05-04 Leo Liu <sdl.web@gmail.com>
2
3 * cal-xtra.texi (Non-Gregorian Diary): Document new features for
4 Chinese calendar and diary.
5
12014-04-30 Eli Zaretskii <eliz@gnu.org> 62014-04-30 Eli Zaretskii <eliz@gnu.org>
2 7
3 * trouble.texi (Quitting, DEL Does Not Delete, Emergency Escape) 8 * trouble.texi (Quitting, DEL Does Not Delete, Emergency Escape)
diff --git a/doc/emacs/cal-xtra.texi b/doc/emacs/cal-xtra.texi
index 82864859473..cf1eba17dec 100644
--- a/doc/emacs/cal-xtra.texi
+++ b/doc/emacs/cal-xtra.texi
@@ -517,7 +517,7 @@ the fourth pattern.
517@subsection Diary Entries Using non-Gregorian Calendars 517@subsection Diary Entries Using non-Gregorian Calendars
518 518
519 As well as entries based on the standard Gregorian calendar, your 519 As well as entries based on the standard Gregorian calendar, your
520diary can have entries based on Bahá'í, Hebrew, or Islamic dates. 520diary can have entries based on Bahá'í, Chinese, Hebrew, or Islamic dates.
521Recognition of such entries can be time-consuming, however, and since 521Recognition of such entries can be time-consuming, however, and since
522most people don't use them, you must explicitly enable their use. If 522most people don't use them, you must explicitly enable their use. If
523you want the diary to recognize Hebrew-date diary entries, for example, 523you want the diary to recognize Hebrew-date diary entries, for example,
@@ -531,22 +531,27 @@ you must do this:
531@findex diary-islamic-mark-entries 531@findex diary-islamic-mark-entries
532@findex diary-bahai-list-entries 532@findex diary-bahai-list-entries
533@findex diary-bahai-mark-entries 533@findex diary-bahai-mark-entries
534@findex diary-chinese-list-entries
535@findex diary-chinese-mark-entries
534@smallexample 536@smallexample
535(add-hook 'diary-nongregorian-listing-hook 'diary-hebrew-list-entries) 537(add-hook 'diary-nongregorian-listing-hook 'diary-hebrew-list-entries)
536(add-hook 'diary-nongregorian-marking-hook 'diary-hebrew-mark-entries) 538(add-hook 'diary-nongregorian-marking-hook 'diary-hebrew-mark-entries)
537@end smallexample 539@end smallexample
538 540
539@noindent 541@noindent
540Similarly, for Islamic and Bahá'í entries, add 542Similarly, for Islamic, Bahá'í and Chinese entries, add
541@code{diary-islamic-list-entries} and @code{diary-islamic-mark-entries}, or 543@code{diary-islamic-list-entries} and @code{diary-islamic-mark-entries},
542@code{diary-bahai-list-entries} and @code{diary-bahai-mark-entries}. 544@code{diary-bahai-list-entries} and @code{diary-bahai-mark-entries},
545or @code{diary-chinese-list-entries} and @code{diary-chinese-mark-entries}.
543 546
544@vindex diary-bahai-entry-symbol 547@vindex diary-bahai-entry-symbol
548@vindex diary-chinese-entry-symbol
545@vindex diary-hebrew-entry-symbol 549@vindex diary-hebrew-entry-symbol
546@vindex diary-islamic-entry-symbol 550@vindex diary-islamic-entry-symbol
547 These diary entries have the same formats as Gregorian-date diary 551 These diary entries have the same formats as Gregorian-date diary
548entries; except that @code{diary-bahai-entry-symbol} (default @samp{B}) 552entries; except that @code{diary-bahai-entry-symbol} (default @samp{B})
549must precede a Bahá'í date, @code{diary-hebrew-entry-symbol} (default 553must precede a Bahá'í date, @code{diary-chinese-entry-symbol} (default
554@samp{C}) a Chinese date, @code{diary-hebrew-entry-symbol} (default
550@samp{H}) a Hebrew date, and @code{diary-islamic-entry-symbol} (default 555@samp{H}) a Hebrew date, and @code{diary-islamic-entry-symbol} (default
551@samp{I}) an Islamic date. Moreover, non-Gregorian month names may not 556@samp{I}) an Islamic date. Moreover, non-Gregorian month names may not
552be abbreviated (because the first three letters are often not unique). 557be abbreviated (because the first three letters are often not unique).
@@ -573,7 +578,7 @@ nonmarking if preceded by @code{diary-nonmarking-symbol} (default
573 578
574 Here is a table of commands used in the calendar to create diary 579 Here is a table of commands used in the calendar to create diary
575entries that match the selected date and other dates that are similar in 580entries that match the selected date and other dates that are similar in
576the Bahá'í, Hebrew, or Islamic calendars: 581the Bahá'í, Chinese, Hebrew, or Islamic calendars:
577 582
578@table @kbd 583@table @kbd
579@item i h d 584@item i h d
@@ -594,6 +599,14 @@ the Bahá'í, Hebrew, or Islamic calendars:
594@code{diary-bahai-insert-monthly-entry} 599@code{diary-bahai-insert-monthly-entry}
595@item i B y 600@item i B y
596@code{diary-bahai-insert-yearly-entry} 601@code{diary-bahai-insert-yearly-entry}
602@item i C d
603@code{diary-chinese-insert-entry}
604@item i C m
605@code{diary-chinese-insert-monthly-entry}
606@item i C y
607@code{diary-chinese-insert-yearly-entry}
608@item i C a
609@code{diary-chinese-insert-anniversary-entry}
597@end table 610@end table
598 611
599@findex diary-hebrew-insert-entry 612@findex diary-hebrew-insert-entry
@@ -605,6 +618,11 @@ the Bahá'í, Hebrew, or Islamic calendars:
605@findex diary-bahai-insert-entry 618@findex diary-bahai-insert-entry
606@findex diary-bahai-insert-monthly-entry 619@findex diary-bahai-insert-monthly-entry
607@findex diary-bahai-insert-yearly-entry 620@findex diary-bahai-insert-yearly-entry
621@findex diary-chinese-insert-entry
622@findex diary-chinese-insert-monthly-entry
623@findex diary-chinese-insert-yearly-entry
624@findex diary-chinese-insert-anniversary-entry
625
608 These commands work much like the corresponding commands for ordinary 626 These commands work much like the corresponding commands for ordinary
609diary entries: they apply to the date that point is on in the calendar 627diary entries: they apply to the date that point is on in the calendar
610window, and what they do is insert just the date portion of a diary 628window, and what they do is insert just the date portion of a diary
diff --git a/etc/ChangeLog b/etc/ChangeLog
index 77294aae776..3eb1c564fad 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,7 @@
12014-05-04 Leo Liu <sdl.web@gmail.com>
2
3 * NEWS: Mention support for Chinese dates in calendar and diary.
4
12014-04-20 Daniel Colascione <dancol@dancol.org> 52014-04-20 Daniel Colascione <dancol@dancol.org>
2 6
3 * NEWS: Mention new struct functions and changes to `cl-the'. 7 * NEWS: Mention new struct functions and changes to `cl-the'.
diff --git a/etc/NEWS b/etc/NEWS
index 5a4410c685c..eed1c43af44 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -74,6 +74,18 @@ performance improvements when pasting large amounts of text.
74** The Rmail commands d, C-d and u now handle repeat counts 74** The Rmail commands d, C-d and u now handle repeat counts
75to delete or undelete multiple messages. 75to delete or undelete multiple messages.
76 76
77** Calendar and diary
78
79+++
80*** New commands to insert diary entries with Chinese dates:
81`diary-chinese-insert-anniversary-entry' `diary-chinese-insert-entry'
82`diary-chinese-insert-monthly-entry'
83`diary-chinese-insert-yearly-entry'
84
85+++
86*** Calendar can list and mark diary entires with Chinese dates:
87`diary-chinese-list-entries' and `diary-chinese-mark-entries'.
88
77** The URL package accepts now the protocols "ssh", "scp" and "rsync". 89** The URL package accepts now the protocols "ssh", "scp" and "rsync".
78When `url-handler-mode' is enabled, file operations for these 90When `url-handler-mode' is enabled, file operations for these
79protocols as well as for "telnet" and "ftp" are passed to Tramp. 91protocols as well as for "telnet" and "ftp" are passed to Tramp.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 561e7908486..051d0e669b4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,29 @@
12014-05-04 Leo Liu <sdl.web@gmail.com>
2
3 Support Chinese diary entries in calendar and diary. (Bug#17393)
4 * calendar/cal-china.el (calendar-chinese-month-name-array): New var.
5 (calendar-chinese-from-absolute-for-diary)
6 (calendar-chinese-to-absolute-for-diary)
7 (calendar-chinese-mark-date-pattern, diary-chinese-mark-entries)
8 (diary-chinese-list-entries): New functions to list and mark
9 Chinese diary entries in the calendar window.
10 (diary-chinese-anniversary)
11 (diary-chinese-insert-anniversary-entry)
12 (diary-chinese-insert-entry, diary-chinese-insert-monthly-entry)
13 (diary-chinese-insert-yearly-entry): New commands to insert
14 Chinese diary entries.
15
16 * calendar/diary-lib.el (diary-font-lock-keywords): Support
17 font-locking Chinese dates.
18
19 * calendar/cal-menu.el (cal-menu-diary-menu): Add entries for
20 inserting Chinese diary entries.
21
22 * calendar/calendar.el (diary-chinese-entry-symbol): New
23 customizable variable.
24 (calendar-mode-map): Add bindings for inserting Chinese diary
25 entries.
26
12014-05-03 Juri Linkov <juri@jurta.org> 272014-05-03 Juri Linkov <juri@jurta.org>
2 28
3 * dired.el (dired-check-switches, dired-switches-recursive-p): 29 * dired.el (dired-check-switches, dired-switches-recursive-p):
diff --git a/lisp/calendar/cal-china.el b/lisp/calendar/cal-china.el
index 538d2320b30..e266613680a 100644
--- a/lisp/calendar/cal-china.el
+++ b/lisp/calendar/cal-china.el
@@ -682,6 +682,124 @@ Echo Chinese date unless NOECHO is non-nil."
682 "Chinese calendar equivalent of date diary entry." 682 "Chinese calendar equivalent of date diary entry."
683 (format "Chinese date: %s" (calendar-chinese-date-string date))) 683 (format "Chinese date: %s" (calendar-chinese-date-string date)))
684 684
685;;;; diary support
686
687(autoload 'calendar-mark-1 "diary-lib")
688(autoload 'diary-mark-entries-1 "diary-lib")
689(autoload 'diary-list-entries-1 "diary-lib")
690(autoload 'diary-insert-entry-1 "diary-lib")
691(autoload 'diary-date-display-form "diary-lib")
692(autoload 'diary-make-date "diary-lib")
693(autoload 'diary-ordinal-suffix "diary-lib")
694(defvar diary-sexp-entry-symbol)
695(defvar entry) ;used by `diary-chinese-anniversary'
696
697(defvar calendar-chinese-month-name-array
698 ["正月" "二月" "三月" "四月" "五月" "六月"
699 "七月" "八月" "九月" "十月" "冬月" "臘月"])
700
701;;; NOTE: In the diary the cycle and year of a Chinese date is
702;;; combined using this formula: (+ (* cycle 100) year).
703;;;
704;;; These two functions convert to and back from this representation.
705(defun calendar-chinese-from-absolute-for-diary (date)
706 (pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute date)))
707 (list m d (+ (* c 100) y))))
708
709(defun calendar-chinese-to-absolute-for-diary (date)
710 (pcase-let ((`(,m ,d ,y) date))
711 (calendar-chinese-to-absolute
712 (list (floor y 100) (mod y 100) m d))))
713
714(defun calendar-chinese-mark-date-pattern (month day year &optional color)
715 (calendar-mark-1 month day year
716 #'calendar-chinese-from-absolute-for-diary
717 #'calendar-chinese-to-absolute-for-diary
718 color))
719
720;;;###cal-autoload
721(defun diary-chinese-mark-entries ()
722 "Mark days in the calendar window that have Chinese date diary entries.
723Marks each entry in `diary-file' (or included files) visible in the calendar
724window. See `diary-chinese-list-entries' for more information.
725
726This function is provided for use with `diary-nongregorian-marking-hook'."
727 (diary-mark-entries-1 #'calendar-chinese-mark-date-pattern
728 calendar-chinese-month-name-array
729 diary-chinese-entry-symbol
730 #'calendar-chinese-from-absolute-for-diary))
731
732;;;###cal-autoload
733(defun diary-chinese-list-entries ()
734 "Add any Chinese date entries from the diary file to `diary-entries-list'.
735Chinese date diary entries must be prefixed by `diary-chinese-entry-symbol'
736\(normally a `C'). The same `diary-date-forms' govern the style
737of the Chinese calendar entries. If a Chinese date diary entry begins with
738`diary-nonmarking-symbol', the entry will appear in the diary listing,
739but will not be marked in the calendar.
740
741This function is provided for use with `diary-nongregorian-listing-hook'."
742 (diary-list-entries-1 calendar-chinese-month-name-array
743 diary-chinese-entry-symbol
744 #'calendar-chinese-from-absolute-for-diary))
745
746;;;###cal-autoload
747(defun diary-chinese-anniversary (month day &optional year mark)
748 "Like `diary-anniversary' (which see) but accepts Chinese date."
749 (pcase-let* ((ddate (diary-make-date month day year))
750 (`(,dc ,dy ,dm ,dd) ;diary chinese date
751 (if year
752 (calendar-chinese-from-absolute
753 (calendar-chinese-to-absolute-for-diary ddate))
754 (list nil nil (calendar-extract-month ddate)
755 (calendar-extract-day ddate))))
756 (`(,cc ,cy ,cm ,cd) ;current chinese date
757 (calendar-chinese-from-absolute
758 (calendar-absolute-from-gregorian date)))
759 (diff (if (and dc dy)
760 (+ (* 60 (- cc dc)) (- cy dy))
761 100)))
762 (and (> diff 0) (= dm cm) (= dd cd)
763 (cons mark (format entry diff (diary-ordinal-suffix diff))))))
764
765;;;###cal-autoload
766(defun diary-chinese-insert-anniversary-entry (&optional arg)
767 "Insert an anniversary diary entry for the Chinese date at point.
768Prefix argument ARG makes the entry nonmarking."
769 (interactive "P")
770 (let ((calendar-date-display-form (diary-date-display-form)))
771 (diary-make-entry
772 (format "%s(diary-chinese-anniversary %s)"
773 diary-sexp-entry-symbol
774 (calendar-date-string
775 (calendar-chinese-from-absolute-for-diary
776 (calendar-absolute-from-gregorian (calendar-cursor-to-date t)))))
777 arg)))
778
779;;;###cal-autoload
780(defun diary-chinese-insert-entry (&optional arg)
781 "Insert a diary entry for the Chinese date at point."
782 (interactive "P")
783 (diary-insert-entry-1 nil arg calendar-chinese-month-name-array
784 diary-chinese-entry-symbol
785 #'calendar-chinese-from-absolute-for-diary))
786
787;;;###cal-autoload
788(defun diary-chinese-insert-monthly-entry (&optional arg)
789 "Insert a monthly diary entry for the Chinese date at point."
790 (interactive "P")
791 (diary-insert-entry-1 'monthly arg calendar-chinese-month-name-array
792 diary-chinese-entry-symbol
793 #'calendar-chinese-from-absolute-for-diary))
794
795;;;###cal-autoload
796(defun diary-chinese-insert-yearly-entry (&optional arg)
797 "Insert a yearly diary entry for the Chinese date at point."
798 (interactive "P")
799 (diary-insert-entry-1 'yearly arg calendar-chinese-month-name-array
800 diary-chinese-entry-symbol
801 #'calendar-chinese-from-absolute-for-diary))
802
685(provide 'cal-china) 803(provide 'cal-china)
686 804
687;;; cal-china.el ends here 805;;; cal-china.el ends here
diff --git a/lisp/calendar/cal-menu.el b/lisp/calendar/cal-menu.el
index e71fccf19bc..23e1b5e0e97 100644
--- a/lisp/calendar/cal-menu.el
+++ b/lisp/calendar/cal-menu.el
@@ -56,6 +56,11 @@
56 ["One time" diary-bahai-insert-entry] 56 ["One time" diary-bahai-insert-entry]
57 ["Monthly" diary-bahai-insert-monthly-entry] 57 ["Monthly" diary-bahai-insert-monthly-entry]
58 ["Yearly" diary-bahai-insert-yearly-entry]) 58 ["Yearly" diary-bahai-insert-yearly-entry])
59 ("Insert Chinese"
60 ["One time" diary-chinese-insert-entry]
61 ["Monthly" diary-chinese-insert-monthly-entry]
62 ["Yearly" diary-chinese-insert-yearly-entry]
63 ["Anniversary" diary-chinese-insert-anniversary-entry])
59 ("Insert Islamic" 64 ("Insert Islamic"
60 ["One time" diary-islamic-insert-entry] 65 ["One time" diary-islamic-insert-entry]
61 ["Monthly" diary-islamic-insert-monthly-entry] 66 ["Monthly" diary-islamic-insert-monthly-entry]
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 57cb488a838..bba3e520e1a 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -689,6 +689,12 @@ details, see the documentation for the variable `diary-list-entries-hook'."
689 :type 'string 689 :type 'string
690 :group 'diary) 690 :group 'diary)
691 691
692(defcustom diary-chinese-entry-symbol "C"
693 "Symbol indicating a diary entry according to the Chinese calendar."
694 :type 'string
695 :group 'diary
696 :version "24.5")
697
692(define-obsolete-variable-alias 'hebrew-diary-entry-symbol 698(define-obsolete-variable-alias 'hebrew-diary-entry-symbol
693 'diary-hebrew-entry-symbol "23.1") 699 'diary-hebrew-entry-symbol "23.1")
694 700
@@ -1709,6 +1715,10 @@ line."
1709 (define-key map "iBd" 'diary-bahai-insert-entry) 1715 (define-key map "iBd" 'diary-bahai-insert-entry)
1710 (define-key map "iBm" 'diary-bahai-insert-monthly-entry) 1716 (define-key map "iBm" 'diary-bahai-insert-monthly-entry)
1711 (define-key map "iBy" 'diary-bahai-insert-yearly-entry) 1717 (define-key map "iBy" 'diary-bahai-insert-yearly-entry)
1718 (define-key map "iCd" 'diary-chinese-insert-entry)
1719 (define-key map "iCm" 'diary-chinese-insert-monthly-entry)
1720 (define-key map "iCy" 'diary-chinese-insert-yearly-entry)
1721 (define-key map "iCa" 'diary-chinese-insert-anniversary-entry)
1712 (define-key map "?" 'calendar-goto-info-node) 1722 (define-key map "?" 'calendar-goto-info-node)
1713 (define-key map "Hm" 'cal-html-cursor-month) 1723 (define-key map "Hm" 'cal-html-cursor-month)
1714 (define-key map "Hy" 'cal-html-cursor-year) 1724 (define-key map "Hy" 'cal-html-cursor-year)
diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el
index c609cee7d6f..b89b808f690 100644
--- a/lisp/calendar/diary-lib.el
+++ b/lisp/calendar/diary-lib.el
@@ -2396,6 +2396,11 @@ return a font-lock pattern matching array of MONTHS and marking SYMBOL."
2396 cal-bahai 2396 cal-bahai
2397 calendar-bahai-month-name-array 2397 calendar-bahai-month-name-array
2398 diary-bahai-entry-symbol) 2398 diary-bahai-entry-symbol)
2399 (diary-font-lock-keywords-1 diary-chinese-mark-entries
2400 diary-chinese-list-entries
2401 cal-china
2402 calendar-chinese-month-name-array
2403 diary-chinese-entry-symbol)
2399 (list 2404 (list
2400 (cons 2405 (cons
2401 (format "^%s.*$" (regexp-quote diary-include-string)) 2406 (format "^%s.*$" (regexp-quote diary-include-string))
@@ -2412,7 +2417,8 @@ return a font-lock pattern matching array of MONTHS and marking SYMBOL."
2412 (regexp-opt (mapcar 'regexp-quote 2417 (regexp-opt (mapcar 'regexp-quote
2413 (list diary-hebrew-entry-symbol 2418 (list diary-hebrew-entry-symbol
2414 diary-islamic-entry-symbol 2419 diary-islamic-entry-symbol
2415 diary-bahai-entry-symbol)) 2420 diary-bahai-entry-symbol
2421 diary-chinese-entry-symbol))
2416 t)) 2422 t))
2417 '(1 font-lock-constant-face)) 2423 '(1 font-lock-constant-face))
2418 '(diary-font-lock-sexps . font-lock-keyword-face) 2424 '(diary-font-lock-sexps . font-lock-keyword-face)