emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117056: Support Chinese diary entries in calendar a


From: Leo Liu
Subject: [Emacs-diffs] trunk r117056: Support Chinese diary entries in calendar and diary
Date: Sun, 04 May 2014 00:20:45 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117056
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17393
committer: Leo Liu <address@hidden>
branch nick: trunk
timestamp: Sun 2014-05-04 08:16:58 +0800
message:
  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.
modified:
  doc/emacs/ChangeLog            changelog-20091113204419-o5vbwnq5f7feedwu-6227
  doc/emacs/cal-xtra.texi        
calxtra.texi-20091113204419-o5vbwnq5f7feedwu-6236
  etc/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1485
  etc/NEWS                       news-20100311060928-aoit31wvzf25yr1z-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/calendar/cal-china.el     calchina.el-20091113204419-o5vbwnq5f7feedwu-896
  lisp/calendar/cal-menu.el      calmenu.el-20091113204419-o5vbwnq5f7feedwu-683
  lisp/calendar/calendar.el      calendar.el-20091113204419-o5vbwnq5f7feedwu-478
  lisp/calendar/diary-lib.el     diarylib.el-20091113204419-o5vbwnq5f7feedwu-902
=== modified file 'doc/emacs/ChangeLog'
--- a/doc/emacs/ChangeLog       2014-04-30 19:54:52 +0000
+++ b/doc/emacs/ChangeLog       2014-05-04 00:16:58 +0000
@@ -1,3 +1,8 @@
+2014-05-04  Leo Liu  <address@hidden>
+
+       * cal-xtra.texi (Non-Gregorian Diary): Document new features for
+       Chinese calendar and diary.
+
 2014-04-30  Eli Zaretskii  <address@hidden>
 
        * trouble.texi (Quitting, DEL Does Not Delete, Emergency Escape)

=== modified file 'doc/emacs/cal-xtra.texi'
--- a/doc/emacs/cal-xtra.texi   2014-01-07 01:46:23 +0000
+++ b/doc/emacs/cal-xtra.texi   2014-05-04 00:16:58 +0000
@@ -517,7 +517,7 @@
 @subsection Diary Entries Using non-Gregorian Calendars
 
   As well as entries based on the standard Gregorian calendar, your
-diary can have entries based on Bahá'í, Hebrew, or Islamic dates.
+diary can have entries based on Bahá'í, Chinese, Hebrew, or Islamic dates.
 Recognition of such entries can be time-consuming, however, and since
 most people don't use them, you must explicitly enable their use.  If
 you want the diary to recognize Hebrew-date diary entries, for example,
@@ -531,22 +531,27 @@
 @findex diary-islamic-mark-entries
 @findex diary-bahai-list-entries
 @findex diary-bahai-mark-entries
address@hidden diary-chinese-list-entries
address@hidden diary-chinese-mark-entries
 @smallexample
 (add-hook 'diary-nongregorian-listing-hook 'diary-hebrew-list-entries)
 (add-hook 'diary-nongregorian-marking-hook 'diary-hebrew-mark-entries)
 @end smallexample
 
 @noindent
-Similarly, for Islamic and Bahá'í entries, add
address@hidden and @code{diary-islamic-mark-entries}, or
address@hidden and @code{diary-bahai-mark-entries}.
+Similarly, for Islamic, Bahá'í and Chinese entries, add
address@hidden and @code{diary-islamic-mark-entries},
address@hidden and @code{diary-bahai-mark-entries},
+or @code{diary-chinese-list-entries} and @code{diary-chinese-mark-entries}.
 
 @vindex diary-bahai-entry-symbol
address@hidden diary-chinese-entry-symbol
 @vindex diary-hebrew-entry-symbol
 @vindex diary-islamic-entry-symbol
   These diary entries have the same formats as Gregorian-date diary
 entries; except that @code{diary-bahai-entry-symbol} (default @samp{B})
-must precede a Bahá'í date, @code{diary-hebrew-entry-symbol} (default
+must precede a Bahá'í date, @code{diary-chinese-entry-symbol} (default
address@hidden) a Chinese date, @code{diary-hebrew-entry-symbol} (default
 @samp{H}) a Hebrew date, and @code{diary-islamic-entry-symbol} (default
 @samp{I}) an Islamic date.  Moreover, non-Gregorian month names may not
 be abbreviated (because the first three letters are often not unique).
@@ -573,7 +578,7 @@
 
   Here is a table of commands used in the calendar to create diary
 entries that match the selected date and other dates that are similar in
-the Bahá'í, Hebrew, or Islamic calendars:
+the Bahá'í, Chinese, Hebrew, or Islamic calendars:
 
 @table @kbd
 @item i h d
@@ -594,6 +599,14 @@
 @code{diary-bahai-insert-monthly-entry}
 @item i B y
 @code{diary-bahai-insert-yearly-entry}
address@hidden i C d
address@hidden
address@hidden i C m
address@hidden
address@hidden i C y
address@hidden
address@hidden i C a
address@hidden
 @end table
 
 @findex diary-hebrew-insert-entry
@@ -605,6 +618,11 @@
 @findex diary-bahai-insert-entry
 @findex diary-bahai-insert-monthly-entry
 @findex diary-bahai-insert-yearly-entry
address@hidden diary-chinese-insert-entry
address@hidden diary-chinese-insert-monthly-entry
address@hidden diary-chinese-insert-yearly-entry
address@hidden diary-chinese-insert-anniversary-entry
+
   These commands work much like the corresponding commands for ordinary
 diary entries: they apply to the date that point is on in the calendar
 window, and what they do is insert just the date portion of a diary

=== modified file 'etc/ChangeLog'
--- a/etc/ChangeLog     2014-04-20 02:50:36 +0000
+++ b/etc/ChangeLog     2014-05-04 00:16:58 +0000
@@ -1,3 +1,7 @@
+2014-05-04  Leo Liu  <address@hidden>
+
+       * NEWS: Mention support for Chinese dates in calendar and diary.
+
 2014-04-20  Daniel Colascione  <address@hidden>
 
        * NEWS: Mention new struct functions and changes to `cl-the'.

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2014-05-02 23:29:57 +0000
+++ b/etc/NEWS  2014-05-04 00:16:58 +0000
@@ -74,6 +74,18 @@
 ** The Rmail commands d, C-d and u now handle repeat counts
 to delete or undelete multiple messages.
 
+** Calendar and diary
+
++++
+*** New commands to insert diary entries with Chinese dates:
+`diary-chinese-insert-anniversary-entry' `diary-chinese-insert-entry'
+`diary-chinese-insert-monthly-entry'
+`diary-chinese-insert-yearly-entry'
+
++++
+*** Calendar can list and mark diary entires with Chinese dates:
+`diary-chinese-list-entries' and `diary-chinese-mark-entries'.
+
 ** The URL package accepts now the protocols "ssh", "scp" and "rsync".
 When `url-handler-mode' is enabled, file operations for these
 protocols as well as for "telnet" and "ftp" are passed to Tramp.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-05-03 14:42:26 +0000
+++ b/lisp/ChangeLog    2014-05-04 00:16:58 +0000
@@ -1,3 +1,29 @@
+2014-05-04  Leo Liu  <address@hidden>
+
+       Support Chinese diary entries in calendar and diary.  (Bug#17393)
+       * 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.
+
+       * calendar/diary-lib.el (diary-font-lock-keywords): Support
+       font-locking Chinese dates.
+
+       * calendar/cal-menu.el (cal-menu-diary-menu): Add entries for
+       inserting Chinese diary entries.
+
+       * calendar/calendar.el (diary-chinese-entry-symbol): New
+       customizable variable.
+       (calendar-mode-map): Add bindings for inserting Chinese diary
+       entries.
+
 2014-05-03  Juri Linkov  <address@hidden>
 
        * dired.el (dired-check-switches, dired-switches-recursive-p):

=== modified file 'lisp/calendar/cal-china.el'
--- a/lisp/calendar/cal-china.el        2014-01-01 07:43:34 +0000
+++ b/lisp/calendar/cal-china.el        2014-05-04 00:16:58 +0000
@@ -682,6 +682,124 @@
   "Chinese calendar equivalent of date diary entry."
   (format "Chinese date: %s" (calendar-chinese-date-string date)))
 
+;;;; diary support
+
+(autoload 'calendar-mark-1         "diary-lib")
+(autoload 'diary-mark-entries-1    "diary-lib")
+(autoload 'diary-list-entries-1    "diary-lib")
+(autoload 'diary-insert-entry-1    "diary-lib")
+(autoload 'diary-date-display-form "diary-lib")
+(autoload 'diary-make-date         "diary-lib")
+(autoload 'diary-ordinal-suffix    "diary-lib")
+(defvar diary-sexp-entry-symbol)
+(defvar entry)                    ;used by `diary-chinese-anniversary'
+
+(defvar calendar-chinese-month-name-array
+  ["正月" "二月" "三月" "四月" "五月" "六月"
+   "七月" "八月" "九月" "十月" "冬月" "臘月"])
+
+;;; NOTE: In the diary the cycle and year of a Chinese date is
+;;; combined using this formula: (+ (* cycle 100) year).
+;;;
+;;; These two functions convert to and back from this representation.
+(defun calendar-chinese-from-absolute-for-diary (date)
+  (pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute date)))
+    (list m d (+ (* c 100) y))))
+
+(defun calendar-chinese-to-absolute-for-diary (date)
+  (pcase-let ((`(,m ,d ,y) date))
+    (calendar-chinese-to-absolute
+     (list (floor y 100) (mod y 100) m d))))
+
+(defun calendar-chinese-mark-date-pattern (month day year &optional color)
+  (calendar-mark-1 month day year
+                   #'calendar-chinese-from-absolute-for-diary
+                   #'calendar-chinese-to-absolute-for-diary
+                   color))
+
+;;;###cal-autoload
+(defun diary-chinese-mark-entries ()
+  "Mark days in the calendar window that have Chinese date diary entries.
+Marks each entry in `diary-file' (or included files) visible in the calendar
+window.  See `diary-chinese-list-entries' for more information.
+
+This function is provided for use with `diary-nongregorian-marking-hook'."
+  (diary-mark-entries-1 #'calendar-chinese-mark-date-pattern
+                        calendar-chinese-month-name-array
+                        diary-chinese-entry-symbol
+                        #'calendar-chinese-from-absolute-for-diary))
+
+;;;###cal-autoload
+(defun diary-chinese-list-entries ()
+  "Add any Chinese date entries from the diary file to `diary-entries-list'.
+Chinese date diary entries must be prefixed by `diary-chinese-entry-symbol'
+\(normally a `C').  The same `diary-date-forms' govern the style
+of the Chinese calendar entries.  If a Chinese date diary entry begins with
+`diary-nonmarking-symbol', the entry will appear in the diary listing,
+but will not be marked in the calendar.
+
+This function is provided for use with `diary-nongregorian-listing-hook'."
+  (diary-list-entries-1 calendar-chinese-month-name-array
+                        diary-chinese-entry-symbol
+                        #'calendar-chinese-from-absolute-for-diary))
+
+;;;###cal-autoload
+(defun diary-chinese-anniversary (month day &optional year mark)
+  "Like `diary-anniversary' (which see) but accepts Chinese date."
+  (pcase-let* ((ddate (diary-make-date month day year))
+               (`(,dc ,dy ,dm ,dd)      ;diary chinese date
+                (if year
+                    (calendar-chinese-from-absolute
+                     (calendar-chinese-to-absolute-for-diary ddate))
+                  (list nil nil (calendar-extract-month ddate)
+                        (calendar-extract-day ddate))))
+               (`(,cc ,cy ,cm ,cd)      ;current chinese date
+                (calendar-chinese-from-absolute
+                 (calendar-absolute-from-gregorian date)))
+               (diff (if (and dc dy)
+                         (+ (* 60 (- cc dc)) (- cy dy))
+                       100)))
+    (and (> diff 0) (= dm cm) (= dd cd)
+         (cons mark (format entry diff (diary-ordinal-suffix diff))))))
+
+;;;###cal-autoload
+(defun diary-chinese-insert-anniversary-entry (&optional arg)
+  "Insert an anniversary diary entry for the Chinese date at point.
+Prefix argument ARG makes the entry nonmarking."
+  (interactive "P")
+  (let ((calendar-date-display-form (diary-date-display-form)))
+    (diary-make-entry
+     (format "%s(diary-chinese-anniversary %s)"
+             diary-sexp-entry-symbol
+             (calendar-date-string
+              (calendar-chinese-from-absolute-for-diary
+               (calendar-absolute-from-gregorian (calendar-cursor-to-date 
t)))))
+     arg)))
+
+;;;###cal-autoload
+(defun diary-chinese-insert-entry (&optional arg)
+  "Insert a diary entry for the Chinese date at point."
+  (interactive "P")
+  (diary-insert-entry-1 nil arg calendar-chinese-month-name-array
+                        diary-chinese-entry-symbol
+                        #'calendar-chinese-from-absolute-for-diary))
+
+;;;###cal-autoload
+(defun diary-chinese-insert-monthly-entry (&optional arg)
+  "Insert a monthly diary entry for the Chinese date at point."
+  (interactive "P")
+  (diary-insert-entry-1 'monthly arg calendar-chinese-month-name-array
+                        diary-chinese-entry-symbol
+                        #'calendar-chinese-from-absolute-for-diary))
+
+;;;###cal-autoload
+(defun diary-chinese-insert-yearly-entry (&optional arg)
+  "Insert a yearly diary entry for the Chinese date at point."
+  (interactive "P")
+  (diary-insert-entry-1 'yearly arg calendar-chinese-month-name-array
+                        diary-chinese-entry-symbol
+                        #'calendar-chinese-from-absolute-for-diary))
+
 (provide 'cal-china)
 
 ;;; cal-china.el ends here

=== modified file 'lisp/calendar/cal-menu.el'
--- a/lisp/calendar/cal-menu.el 2014-01-01 07:43:34 +0000
+++ b/lisp/calendar/cal-menu.el 2014-05-04 00:16:58 +0000
@@ -56,6 +56,11 @@
      ["One time" diary-bahai-insert-entry]
      ["Monthly" diary-bahai-insert-monthly-entry]
      ["Yearly" diary-bahai-insert-yearly-entry])
+    ("Insert Chinese"
+     ["One time" diary-chinese-insert-entry]
+     ["Monthly" diary-chinese-insert-monthly-entry]
+     ["Yearly" diary-chinese-insert-yearly-entry]
+     ["Anniversary" diary-chinese-insert-anniversary-entry])
     ("Insert Islamic"
      ["One time" diary-islamic-insert-entry]
      ["Monthly" diary-islamic-insert-monthly-entry]

=== modified file 'lisp/calendar/calendar.el'
--- a/lisp/calendar/calendar.el 2014-03-17 16:04:32 +0000
+++ b/lisp/calendar/calendar.el 2014-05-04 00:16:58 +0000
@@ -689,6 +689,12 @@
   :type 'string
   :group 'diary)
 
+(defcustom diary-chinese-entry-symbol "C"
+  "Symbol indicating a diary entry according to the Chinese calendar."
+  :type 'string
+  :group 'diary
+  :version "24.5")
+
 (define-obsolete-variable-alias 'hebrew-diary-entry-symbol
   'diary-hebrew-entry-symbol "23.1")
 
@@ -1709,6 +1715,10 @@
     (define-key map "iBd" 'diary-bahai-insert-entry)
     (define-key map "iBm" 'diary-bahai-insert-monthly-entry)
     (define-key map "iBy" 'diary-bahai-insert-yearly-entry)
+    (define-key map "iCd" 'diary-chinese-insert-entry)
+    (define-key map "iCm" 'diary-chinese-insert-monthly-entry)
+    (define-key map "iCy" 'diary-chinese-insert-yearly-entry)
+    (define-key map "iCa" 'diary-chinese-insert-anniversary-entry)
     (define-key map "?"   'calendar-goto-info-node)
     (define-key map "Hm" 'cal-html-cursor-month)
     (define-key map "Hy" 'cal-html-cursor-year)

=== modified file 'lisp/calendar/diary-lib.el'
--- a/lisp/calendar/diary-lib.el        2014-01-01 07:43:34 +0000
+++ b/lisp/calendar/diary-lib.el        2014-05-04 00:16:58 +0000
@@ -2396,6 +2396,11 @@
                                cal-bahai
                                calendar-bahai-month-name-array
                                diary-bahai-entry-symbol)
+   (diary-font-lock-keywords-1 diary-chinese-mark-entries
+                               diary-chinese-list-entries
+                               cal-china
+                               calendar-chinese-month-name-array
+                               diary-chinese-entry-symbol)
    (list
     (cons
      (format "^%s.*$" (regexp-quote diary-include-string))
@@ -2412,7 +2417,8 @@
              (regexp-opt (mapcar 'regexp-quote
                                  (list diary-hebrew-entry-symbol
                                        diary-islamic-entry-symbol
-                                       diary-bahai-entry-symbol))
+                                       diary-bahai-entry-symbol
+                                       diary-chinese-entry-symbol))
                          t))
      '(1 font-lock-constant-face))
     '(diary-font-lock-sexps . font-lock-keyword-face)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]