Changeset 3939 for vendor/emacs-CVS_HEAD/lisp/calendar/diary-lib.el
- Timestamp:
- 11/01/05 07:08:22 (3 years ago)
- Files:
-
- vendor/emacs-CVS_HEAD/lisp/calendar/diary-lib.el (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
vendor/emacs-CVS_HEAD/lisp/calendar/diary-lib.el
r3892 r3939 5 5 6 6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu> 7 ;; Maintainer: Glenn Morris < gmorris@ast.cam.ac.uk>7 ;; Maintainer: Glenn Morris <rgm@gnu.org> 8 8 ;; Keywords: calendar 9 9 … … 272 272 ;; (see etc/TODO) is fixed. -- gm 273 273 (defcustom diary-header-line-flag t 274 " *If non-nil, `simple-diary-display' will show a header line.274 "If non-nil, `diary-simple-display' will show a header line. 275 275 The format of the header is specified by `diary-header-line-format'." 276 276 :group 'diary … … 278 278 :version "22.1") 279 279 280 (defvar diary-selective-display nil) 281 280 282 (defcustom diary-header-line-format 281 283 '(:eval (calendar-string-spread 282 (list (if selective-display284 (list (if diary-selective-display 283 285 "Selective display active - press \"s\" in calendar \ 284 286 before edit/copy" 285 287 "Diary")) 286 288 ?\s (frame-width))) 287 " *Format of the header line displayed by `simple-diary-display'.289 "Format of the header line displayed by `diary-simple-display'. 288 290 Only used if `diary-header-line-flag' is non-nil." 289 291 :group 'diary … … 323 325 324 326 (define-obsolete-function-alias 'list-diary-entries 'diary-list-entries) 325 (defun diary-list-entries (date number )327 (defun diary-list-entries (date number &optional list-only) 326 328 "Create and display a buffer containing the relevant lines in `diary-file'. 327 329 The arguments are DATE and NUMBER; the entries selected are those … … 330 332 331 333 Returns a list of all relevant diary entries found, if any, in order by date. 332 The list entries have the form (( month day year) string specifier) where333 \( month day year) is the date of the entry, stringis the entry text, and334 specifieris the applicability. If the variable `diary-list-include-blanks'335 is t, this list includes a dummy diary entry consisting of the empty string )334 The list entries have the form ((MONTH DAY YEAR) STRING SPECIFIER) where 335 \(MONTH DAY YEAR) is the date of the entry, STRING is the entry text, and 336 SPECIFIER is the applicability. If the variable `diary-list-include-blanks' 337 is t, this list includes a dummy diary entry consisting of the empty string 336 338 for a date with no diary entries. 337 339 … … 355 357 356 358 `diary-hook' is run last. This can be used for an appointment 357 notification function." 359 notification function. 360 361 If LIST-ONLY is non-nil don't modify or display the buffer, only return a list." 358 362 (unless number 359 363 (setq number (if (vectorp number-of-diary-entries) … … 374 378 (or (verify-visited-file-modtime diary-buffer) 375 379 (revert-buffer t t)))) 380 ;; Setup things like the header-line-format and invisibility-spec. 381 (when (eq major-mode 'fundamental-mode) (diary-mode)) 376 382 ;; d-s-p is passed to the diary display function. 377 383 (let ((diary-saved-point (point))) 378 384 (save-excursion 379 385 (setq file-glob-attrs (nth 1 (diary-pull-attrs nil ""))) 380 (setq selective-display t)381 (setq selective-display-ellipses nil)382 (if diary-header-line-flag383 (setq header-line-format diary-header-line-format))384 386 (with-syntax-table diary-syntax-table 385 (let ((buffer-read-only nil) 386 (diary-modified (buffer-modified-p)) 387 (mark (regexp-quote diary-nonmarking-symbol))) 388 ;; First and last characters must be ^M or \n for 389 ;; selective display to work properly 390 (goto-char (1- (point-max))) 391 (if (not (looking-at "\^M\\|\n")) 392 (progn 393 (goto-char (point-max)) 394 (insert "\^M"))) 387 (let ((mark (regexp-quote diary-nonmarking-symbol))) 395 388 (goto-char (point-min)) 396 (if (not (looking-at "\^M\\|\n")) 397 (insert "\^M")) 398 (subst-char-in-region (point-min) (point-max) ?\n ?\^M t) 389 (unless list-only 390 (let ((ol (make-overlay (point-min) (point-max) nil t nil))) 391 (set (make-local-variable 'diary-selective-display) t) 392 (overlay-put ol 'invisible 'diary) 393 (overlay-put ol 'evaporate t))) 399 394 (calendar-for-loop 400 395 i from 1 to number do … … 427 422 (concat 428 423 "\\(\\`\\|\^M\\|\n\\)" mark "?\\(" 429 (mapconcat 'eval date-form "\\)\\( ")424 (mapconcat 'eval date-form "\\)\\(?:") 430 425 "\\)")) 431 426 (case-fold-search t)) … … 445 440 (re-search-backward "\^M\\|\n\\|\\`") 446 441 (setq date-start (point)) 447 (re-search-forward "\^M\\|\n" nil t 2) 442 ;; When selective display (rather than 443 ;; overlays) was used, diary file used to 444 ;; start in a blank line and end in a 445 ;; newline. Now that neither of these 446 ;; need be true, 'move handles the latter 447 ;; and 1/2 kludge the former. 448 (re-search-forward 449 "\^M\\|\n" nil 'move 450 (if (and (bobp) (not (looking-at "\^M\\|\n"))) 451 1 452 2)) 448 453 (while (looking-at " \\|\^I") 449 (re-search-forward "\^M\\|\n" nil t)) 450 (backward-char 1) 451 (subst-char-in-region date-start 452 (point) ?\^M ?\n t) 454 (re-search-forward "\^M\\|\n" nil 'move)) 455 (unless (eobp) (backward-char 1)) 456 (unless list-only 457 (remove-overlays date-start (point) 458 'invisible 'diary)) 453 459 (setq entry (buffer-substring entry-start (point)) 454 460 temp (diary-pull-attrs entry file-glob-attrs) … … 468 474 (calendar-gregorian-from-absolute 469 475 (1+ (calendar-absolute-from-gregorian date)))) 470 (setq entry-found nil))) 471 (set-buffer-modified-p diary-modified))) 476 (setq entry-found nil))))) 472 477 (goto-char (point-min)) 473 478 (run-hooks 'nongregorian-diary-listing-hook 474 479 'list-diary-entries-hook) 475 (if diary-display-hook 476 (run-hooks 'diary-display-hook) 477 (simple-diary-display)) 480 (unless list-only 481 (if diary-display-hook 482 (run-hooks 'diary-display-hook) 483 (simple-diary-display))) 478 484 (run-hooks 'diary-hook) 479 485 diary-entries-list)))))) 480 486 481 487 (defun diary-unhide-everything () 482 (setq selective-display nil) 483 (let ((inhibit-read-only t) 484 (modified (buffer-modified-p))) 485 (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) 486 (set-buffer-modified-p modified)) 488 (kill-local-variable 'diary-selective-display) 489 (remove-overlays (point-min) (point-max) 'invisible 'diary) 487 490 (kill-local-variable 'mode-line-format)) 488 491 … … 604 607 (display-buffer holiday-buffer) 605 608 (message "No diary entries for %s" date-string))) 606 ( save-excursion;; Prepare the fancy diary buffer.607 (set-buffer (make-fancy-diary-buffer))609 (with-current-buffer;; Prepare the fancy diary buffer. 610 (make-fancy-diary-buffer) 608 611 (setq buffer-read-only nil) 609 612 (let ((entry-list diary-entries-list) … … 674 677 (apply 675 678 'concat "temp-face-" 676 (mapcar '(lambda (sym)677 (if (stringp sym)678 sym679 (symbol-name sym)))679 (mapcar (lambda (sym) 680 (if (stringp sym) 681 sym 682 (symbol-name sym))) 680 683 marks)))) 681 684 (faceinfo marks)) … … 688 691 (setcar (cdr faceinfo) nil)) 689 692 (setq marks (delq nil marks)) 690 ;; Apply the font aspects 693 ;; Apply the font aspects. 691 694 (apply 'set-face-attribute temp-face nil marks) 692 695 (search-backward entry) … … 705 708 (defun make-fancy-diary-buffer () 706 709 "Create and return the initial fancy diary buffer." 707 (save-excursion 708 (set-buffer (get-buffer-create fancy-diary-buffer)) 710 (with-current-buffer (get-buffer-create fancy-diary-buffer) 709 711 (setq buffer-read-only nil) 710 712 (calendar-set-mode-line "Diary Entries") … … 727 729 (interactive) 728 730 (if (bufferp (get-buffer fancy-diary-buffer)) 729 (save-excursion 730 (set-buffer (get-buffer fancy-diary-buffer)) 731 (with-current-buffer (get-buffer fancy-diary-buffer) 731 732 (run-hooks 'print-diary-entries-hook)) 732 733 (let ((diary-buffer 733 734 (find-buffer-visiting (substitute-in-file-name diary-file)))) 734 735 (if diary-buffer 735 (let ((temp-buffer (get-buffer-create " *Printable Diary Entries*"))736 (let ((temp-buffer (get-buffer-create " *Printable Diary Entries*")) 736 737 (heading)) 737 (save-excursion 738 (set-buffer diary-buffer) 738 (with-current-buffer diary-buffer 739 739 (setq heading 740 740 (if (not (stringp mode-line-format)) 741 741 "All Diary Entries" 742 742 (string-match "^-*\\([^-].*[^-]\\)-*$" mode-line-format) 743 (substring mode-line-format 744 (match-beginning 1) (match-end 1)))) 745 (copy-to-buffer temp-buffer (point-min) (point-max)) 743 (match-string 1 mode-line-format))) 744 (let ((start (point-min)) 745 end) 746 (while 747 (progn 748 (setq end (next-single-char-property-change 749 start 'invisible)) 750 (if (get-char-property start 'invisible) 751 nil 752 (with-current-buffer temp-buffer 753 (insert-buffer-substring diary-buffer 754 start (or end (point-max))))) 755 (setq start end) 756 (and end (< end (point-max)))))) 746 757 (set-buffer temp-buffer) 747 (while (re-search-forward "\^M.*$" nil t)748 (replace-match ""))749 758 (goto-char (point-min)) 750 759 (insert heading "\n" … … 765 774 (with-current-buffer (or (find-buffer-visiting d-file) 766 775 (find-file-noselect d-file t)) 776 (when (eq major-mode 'fundamental-mode) (diary-mode)) 767 777 (diary-unhide-everything) 768 778 (display-buffer (current-buffer))))) … … 770 780 (defcustom diary-mail-addr 771 781 (if (boundp 'user-mail-address) user-mail-address "") 772 " *Email address that `diary-mail-entries' will send email to."782 "Email address that `diary-mail-entries' will send email to." 773 783 :group 'diary 774 784 :type 'string … … 776 786 777 787 (defcustom diary-mail-days 7 778 " *Default number of days for `diary-mail-entries' to check."788 "Default number of days for `diary-mail-entries' to check." 779 789 :group 'diary 780 790 :type 'integer … … 867 877 (with-current-buffer (find-file-noselect (diary-check-diary-file) t) 868 878 (save-excursion 879 (when (eq major-mode 'fundamental-mode) (diary-mode)) 869 880 (setq mark-diary-entries-in-calendar t) 870 881 (message "Marking diary entries...") … … 1119 1130 (defcustom diary-unknown-time 1120 1131 -9999 1121 " *Value returned by diary-entry-time when no time is found.1132 "Value returned by diary-entry-time when no time is found. 1122 1133 The default value -9999 causes entries with no recognizable time to be placed 1123 1134 before those with times; 9999 would place entries with no recognizable time … … 1362 1373 (if diary-entry 1363 1374 (progn 1364 (subst-char-in-region line-start (point) ?\^M ?\n t)1375 (remove-overlays line-start (point) 'invisible 'diary) 1365 1376 (if (< 0 (length entry)) 1366 1377 (setq temp (diary-pull-attrs entry file-glob-attrs) … … 1512 1523 1513 1524 1514 (defun diary-anniversary (month day year &optionalmark)1525 (defun diary-anniversary (month day &optional year mark) 1515 1526 "Anniversary diary entry. 1516 1527 Entry applies if date is the anniversary of MONTH, DAY, YEAR if … … 1531 1542 month)) 1532 1543 (y (extract-calendar-year date)) 1533 (diff ( - y year)))1544 (diff (if year (- y year) 100))) 1534 1545 (if (and (= m 2) (= d 29) (not (calendar-leap-year-p y))) 1535 1546 (setq m 3 … … 1579 1590 " until " 1580 1591 diary-entry) 1581 " *Pseudo-pattern giving form of reminder messages in the fancy diary1592 "Pseudo-pattern giving form of reminder messages in the fancy diary 1582 1593 display. 1583 1594 … … 1658 1669 "Insert a diary entry STRING which may be NONMARKING in FILE. 1659 1670 If omitted, NONMARKING defaults to nil and FILE defaults to 1660 `diary-file'. Adds `diary-redraw-calendar' to 1661 `write-contents-functions' for FILE, so that the calendar will be 1662 redrawn with the new entry marked, if necessary." 1671 `diary-file'." 1663 1672 (let ((pop-up-frames (window-dedicated-p (selected-window)))) 1664 1673 (find-file-other-window (substitute-in-file-name (or file diary-file)))) 1665 ( add-hook 'after-save-hook 'diary-redraw-calendar nil t)1674 (when (eq major-mode 'fundamental-mode) (diary-mode)) 1666 1675 (widen) 1667 1676 (diary-unhide-everything) … … 1867 1876 (eval-when-compile (require 'cal-hebrew) 1868 1877 (require 'cal-islam)) 1878 1879 (defconst diary-time-regexp 1880 ;; Formats that should be accepted: 1881 ;; 10:00 10.00 10h00 10h 10am 10:00am 10.00am 1882 (concat "[0-9]?[0-9]\\([AaPp][mM]\\|\\(" 1883 "[Hh]\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]" 1884 "\\)\\([AaPp][Mm]\\)?\\)")) 1869 1885 1870 1886 (defvar diary-font-lock-keywords … … 1908 1924 '(1 font-lock-reference-face)) 1909 1925 '(diary-font-lock-sexps . font-lock-keyword-face) 1910 '("[0-9]?[0-9]\\([:.]?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)\\(-[0-9]?[0-9]\\([:.]?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)\\)?" 1911 . font-lock-function-name-face))) 1926 (cons 1927 (concat ;; "^[ \t]+" 1928 diary-time-regexp "\\(-" diary-time-regexp "\\)?") 1929 'font-lock-function-name-face))) 1912 1930 "Forms to highlight in `diary-mode'.") 1913 1931
