From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#17393: 24.4.50; [PATCH] diary Chinese support Date: Sat, 03 May 2014 12:25:49 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1399091263 21768 80.91.229.3 (3 May 2014 04:27:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 3 May 2014 04:27:43 +0000 (UTC) Cc: William Xu To: 17393@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 03 06:27:35 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WgRXy-00022K-2K for geb-bug-gnu-emacs@m.gmane.org; Sat, 03 May 2014 06:27:34 +0200 Original-Received: from localhost ([::1]:47430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgRXx-0004IV-Bq for geb-bug-gnu-emacs@m.gmane.org; Sat, 03 May 2014 00:27:33 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgRXl-0004Hu-Gl for bug-gnu-emacs@gnu.org; Sat, 03 May 2014 00:27:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgRXc-0002ln-Cg for bug-gnu-emacs@gnu.org; Sat, 03 May 2014 00:27:21 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgRXS-0002jC-U7; Sat, 03 May 2014 00:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WgRXS-0000vQ-KE; Sat, 03 May 2014 00:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: "Debbugs-submit" Resent-CC: rgm@gnu.org, william.xwl@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Sat, 03 May 2014 04:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 17393 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Glenn Morris , William Xu Original-Received: via spool by submit@debbugs.gnu.org id=B.13990912003512 (code B ref -1); Sat, 03 May 2014 04:27:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 May 2014 04:26:40 +0000 Original-Received: from localhost ([127.0.0.1]:49000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WgRX4-0000uZ-Vb for submit@debbugs.gnu.org; Sat, 03 May 2014 00:26:39 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37695) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WgRX2-0000uI-Ds for submit@debbugs.gnu.org; Sat, 03 May 2014 00:26:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgRWn-0002O5-Ns for submit@debbugs.gnu.org; Sat, 03 May 2014 00:26:30 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:57935) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgRWn-0002Nz-K4 for submit@debbugs.gnu.org; Sat, 03 May 2014 00:26:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgRWe-0004CS-1s for bug-gnu-emacs@gnu.org; Sat, 03 May 2014 00:26:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WgRWU-0002Hn-VP for bug-gnu-emacs@gnu.org; Sat, 03 May 2014 00:26:12 -0400 Original-Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]:61401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WgRWU-0002H6-Jv for bug-gnu-emacs@gnu.org; Sat, 03 May 2014 00:26:02 -0400 Original-Received: by mail-pa0-f46.google.com with SMTP id kx10so3724209pab.33 for ; Fri, 02 May 2014 21:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type; bh=NGj5GfgdaczBEukNI59utqvvS9QMJG70/W1D9/DOVww=; b=RyQhfE9bv63BsyeVxHZtia0JBg3Q8OWFuAgJtgQudvWURnDcV55bmH+jbYKSrhSMPr LL+WsQ9tMq3rsEB45XMeeB1jbvJV9KgEVjT3lqO33uxway0otQlObwzoMJznC7nRAY6R K5O6HjHhoHdDK+NtZJnzCfayQvZzz2uRYA36c0P8Pr0+PqjY0Fj4/d0Cf6Q1+73Si+tG fca38EAdiHVZeA4yin77gsOgTo6E8Tv8Fd81zPzxhaFGdXiFAuMVycwb5LlUlpdxSzmj mJnzUw4UWKONGgcPp5NwrI5re1ty0vUVRX3umj2vUeianF8PXe0ykfc+z+jRAqNP+BVw dcVg== X-Received: by 10.66.142.201 with SMTP id ry9mr42758568pab.14.1399091161236; Fri, 02 May 2014 21:26:01 -0700 (PDT) Original-Received: from fortuna ([123.115.254.233]) by mx.google.com with ESMTPSA id fk4sm8075024pab.23.2014.05.02.21.25.58 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 21:26:00 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:88567 Archived-At: --=-=-= Content-Type: text/plain The patch adds support for Chinese dates in diary, in which the cycle and year are concatenated as cycleyear i.e. cycle 78 and year 31 is represented as 7831. The following commands are available in the calendar window: KEY COMMAND ====== ====================================== `i C a' diary-chinese-insert-anniversary-entry `i C d' diary-chinese-insert-entry `i C m' diary-chinese-insert-monthly-entry `i C y' diary-chinese-insert-yearly-entry ====== ====================================== --=-=-= Content-Type: text/x-patch; charset=gbk Content-Disposition: inline; filename=cal-china.patch Content-Transfer-Encoding: quoted-printable Content-Description: cal-china.patch =3D=3D=3D modified file 'lisp/calendar/cal-china.el' --- lisp/calendar/cal-china.el 2014-01-01 07:43:34 +0000 +++ lisp/calendar/cal-china.el 2014-05-03 04:15:59 +0000 @@ -682,6 +682,124 @@ "Chinese calendar equivalent of date diary entry." (format "Chinese date: %s" (calendar-chinese-date-string date))) =20 +;;;; diary support + +(declare-function calendar-mark-1 "diary-lib") +(declare-function diary-mark-entries-1 "diary-lib") +(declare-function diary-list-entries-1 "diary-lib") +(declare-function diary-insert-entry-1 "diary-lib") +(declare-function diary-date-display-form "diary-lib") +(declare-function diary-anniversary "diary-lib") +(declare-function diary-make-date "diary-lib") +(declare-function diary-ordinal-suffix "diary-lib") +(defvar diary-sexp-entry-symbol) +(defvar entry) ;used by `diary-chinese-anniversary' + +(defvar calendar-chinese-month-name-array + ["=D5=FD=D4=C2" "=B6=FE=D4=C2" "=C8=FD=D4=C2" "=CB=C4=D4=C2" "=CE=E5=D4= =C2" "=C1=F9=D4=C2" + "=C6=DF=D4=C2" "=B0=CB=D4=C2" "=BE=C5=D4=C2" "=CA=AE=D4=C2" "=B6=AC=D4= =C2" "=C5D=D4=C2"]) + +;;; 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 calend= ar +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 prefaced by `diary-chinese-entry-symbol' +\(normally an `C'). The same `diary-date-forms' govern the style +of the Chinese calendar entries. If an Chinese date diary entry begins wi= th +`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) + (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) (=3D dm cm) (=3D 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) =20 ;;; cal-china.el ends here =3D=3D=3D modified file 'lisp/calendar/cal-menu.el' --- lisp/calendar/cal-menu.el 2014-01-01 07:43:34 +0000 +++ lisp/calendar/cal-menu.el 2014-05-03 04:15:59 +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] =3D=3D=3D modified file 'lisp/calendar/calendar.el' --- lisp/calendar/calendar.el 2014-03-17 16:04:32 +0000 +++ lisp/calendar/calendar.el 2014-05-03 04:15:59 +0000 @@ -689,6 +689,11 @@ :type 'string :group 'diary) =20 +(defcustom diary-chinese-entry-symbol "C" + "Symbol indicating a diary entry according to the Chinese calendar." + :type 'string + :group 'diary) + (define-obsolete-variable-alias 'hebrew-diary-entry-symbol 'diary-hebrew-entry-symbol "23.1") =20 @@ -1709,6 +1714,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) =3D=3D=3D modified file 'lisp/calendar/diary-lib.el' --- lisp/calendar/diary-lib.el 2014-01-01 07:43:34 +0000 +++ lisp/calendar/diary-lib.el 2014-05-03 04:15:59 +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) --=-=-=--