diff options
| author | Markus Rost | 2002-11-16 19:17:20 +0000 |
|---|---|---|
| committer | Markus Rost | 2002-11-16 19:17:20 +0000 |
| commit | 86432f811eb38e79a87f476ca33a930bcd0d5ffb (patch) | |
| tree | c3c738fb5618cea0615dd7c57d5d86e7a6509253 | |
| parent | ffd5cede9d64ae266f1d397d81a6cb2bce4a82fc (diff) | |
| download | emacs-86432f811eb38e79a87f476ca33a930bcd0d5ffb.tar.gz emacs-86432f811eb38e79a87f476ca33a930bcd0d5ffb.zip | |
Patch of Alan Shutko <ats@acm.org> by way of rms.
(list-diary-entries): Pass a marker
indicating source of entry to add-to-diary-list.
(diary-button-face, diary-entry, diary-goto-entry): New, to
support click to diary file.
(fancy-diary-display): Buttonize diary entries.
(list-sexp-diary-entries): Pass a marker indicating source of
entry to add-to-diary-list.
(diary-date): Return mark as well as entry.
| -rw-r--r-- | lisp/calendar/diary-lib.el | 171 |
1 files changed, 164 insertions, 7 deletions
diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index 0b058a3bdfa..2905583a610 100644 --- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el | |||
| @@ -313,7 +313,8 @@ These hooks have the following distinct roles: | |||
| 313 | (buffer-substring | 313 | (buffer-substring |
| 314 | entry-start (point)) | 314 | entry-start (point)) |
| 315 | (buffer-substring | 315 | (buffer-substring |
| 316 | (1+ date-start) (1- entry-start))))))) | 316 | (1+ date-start) (1- entry-start)) |
| 317 | (copy-marker entry-start)))))) | ||
| 317 | (setq d (cdr d))) | 318 | (setq d (cdr d))) |
| 318 | (or entry-found | 319 | (or entry-found |
| 319 | (not diary-list-include-blanks) | 320 | (not diary-list-include-blanks) |
| @@ -412,6 +413,20 @@ changing the variable `diary-include-string'." | |||
| 412 | (display-buffer (find-buffer-visiting d-file)) | 413 | (display-buffer (find-buffer-visiting d-file)) |
| 413 | (message "Preparing diary...done")))) | 414 | (message "Preparing diary...done")))) |
| 414 | 415 | ||
| 416 | (defface diary-button-face '((((type pc) (class color)) | ||
| 417 | (:foreground "lightblue"))) | ||
| 418 | "Default face used for buttons.") | ||
| 419 | |||
| 420 | (define-button-type 'diary-entry | ||
| 421 | 'action #'diary-goto-entry | ||
| 422 | 'face #'diary-button-face) | ||
| 423 | |||
| 424 | (defun diary-goto-entry (button) | ||
| 425 | (let ((marker (button-get button 'marker))) | ||
| 426 | (when marker | ||
| 427 | (pop-to-buffer (marker-buffer marker)) | ||
| 428 | (goto-char (marker-position marker))))) | ||
| 429 | |||
| 415 | (defun fancy-diary-display () | 430 | (defun fancy-diary-display () |
| 416 | "Prepare a diary buffer with relevant entries in a fancy, noneditable form. | 431 | "Prepare a diary buffer with relevant entries in a fancy, noneditable form. |
| 417 | This function is provided for optional use as the `diary-display-hook'." | 432 | This function is provided for optional use as the `diary-display-hook'." |
| @@ -497,12 +512,17 @@ This function is provided for optional use as the `diary-display-hook'." | |||
| 497 | (concat "\n" (make-string l ? )))) | 512 | (concat "\n" (make-string l ? )))) |
| 498 | (insert ?\n (make-string (+ l longest) ?=) ?\n))))) | 513 | (insert ?\n (make-string (+ l longest) ?=) ?\n))))) |
| 499 | (if (< 0 (length (car (cdr (car entry-list))))) | 514 | (if (< 0 (length (car (cdr (car entry-list))))) |
| 500 | (insert (car (cdr (car entry-list))) ?\n)) | 515 | (if (nth 3 (car entry-list)) |
| 516 | (insert-button (concat (car (cdr (car entry-list))) "\n") | ||
| 517 | 'marker (nth 3 (car entry-list)) | ||
| 518 | :type 'diary-entry) | ||
| 519 | (insert (car (cdr (car entry-list))) ?\n))) | ||
| 501 | (setq entry-list (cdr entry-list)))) | 520 | (setq entry-list (cdr entry-list)))) |
| 502 | (set-buffer-modified-p nil) | 521 | (set-buffer-modified-p nil) |
| 503 | (goto-char (point-min)) | 522 | (goto-char (point-min)) |
| 504 | (setq buffer-read-only t) | 523 | (setq buffer-read-only t) |
| 505 | (display-buffer fancy-diary-buffer) | 524 | (display-buffer fancy-diary-buffer) |
| 525 | (fancy-diary-display-mode) | ||
| 506 | (message "Preparing diary...done")))) | 526 | (message "Preparing diary...done")))) |
| 507 | 527 | ||
| 508 | (defun make-fancy-diary-buffer () | 528 | (defun make-fancy-diary-buffer () |
| @@ -1164,7 +1184,8 @@ best if they are nonmarking." | |||
| 1164 | (re-search-backward "\^M\\|\n\\|\\`") | 1184 | (re-search-backward "\^M\\|\n\\|\\`") |
| 1165 | (setq line-start (point))) | 1185 | (setq line-start (point))) |
| 1166 | (setq specifier | 1186 | (setq specifier |
| 1167 | (buffer-substring-no-properties (1+ line-start) (point))) | 1187 | (buffer-substring-no-properties (1+ line-start) (point)) |
| 1188 | entry-start (1+ line-start)) | ||
| 1168 | (forward-char 1) | 1189 | (forward-char 1) |
| 1169 | (if (and (or (char-equal (preceding-char) ?\^M) | 1190 | (if (and (or (char-equal (preceding-char) ?\^M) |
| 1170 | (char-equal (preceding-char) ?\n)) | 1191 | (char-equal (preceding-char) ?\n)) |
| @@ -1187,7 +1208,9 @@ best if they are nonmarking." | |||
| 1187 | (if (consp diary-entry) | 1208 | (if (consp diary-entry) |
| 1188 | (cdr diary-entry) | 1209 | (cdr diary-entry) |
| 1189 | diary-entry) | 1210 | diary-entry) |
| 1190 | specifier) | 1211 | specifier |
| 1212 | (if entry-start (copy-marker entry-start) | ||
| 1213 | nil)) | ||
| 1191 | (setq entry-found (or entry-found diary-entry))))) | 1214 | (setq entry-found (or entry-found diary-entry))))) |
| 1192 | entry-found)) | 1215 | entry-found)) |
| 1193 | 1216 | ||
| @@ -1245,7 +1268,7 @@ use when highlighting the day in the calendar." | |||
| 1245 | (or (and (listp year) (memq y year)) | 1268 | (or (and (listp year) (memq y year)) |
| 1246 | (equal y year) | 1269 | (equal y year) |
| 1247 | (eq year t))) | 1270 | (eq year t))) |
| 1248 | entry))) | 1271 | (cons mark entry)))) |
| 1249 | 1272 | ||
| 1250 | (defun diary-block (m1 d1 y1 m2 d2 y2 &optional mark) | 1273 | (defun diary-block (m1 d1 y1 m2 d2 y2 &optional mark) |
| 1251 | "Block diary entry. | 1274 | "Block diary entry. |
| @@ -1445,12 +1468,13 @@ marked on the calendar." | |||
| 1445 | (or (diary-remind sexp (car days) marking) | 1468 | (or (diary-remind sexp (car days) marking) |
| 1446 | (diary-remind sexp (cdr days) marking)))))) | 1469 | (diary-remind sexp (cdr days) marking)))))) |
| 1447 | 1470 | ||
| 1448 | (defun add-to-diary-list (date string specifier) | 1471 | (defun add-to-diary-list (date string specifier marker) |
| 1449 | "Add the entry (DATE STRING SPECIFIER) to `diary-entries-list'. | 1472 | "Add the entry (DATE STRING SPECIFIER) to `diary-entries-list'. |
| 1450 | Do nothing if DATE or STRING is nil." | 1473 | Do nothing if DATE or STRING is nil." |
| 1451 | (and date string | 1474 | (and date string |
| 1452 | (setq diary-entries-list | 1475 | (setq diary-entries-list |
| 1453 | (append diary-entries-list (list (list date string specifier)))))) | 1476 | (append diary-entries-list |
| 1477 | (list (list date string specifier marker)))))) | ||
| 1454 | 1478 | ||
| 1455 | (defun make-diary-entry (string &optional nonmarking file) | 1479 | (defun make-diary-entry (string &optional nonmarking file) |
| 1456 | "Insert a diary entry STRING which may be NONMARKING in FILE. | 1480 | "Insert a diary entry STRING which may be NONMARKING in FILE. |
| @@ -1563,6 +1587,139 @@ Prefix arg will make the entry nonmarking." | |||
| 1563 | (calendar-date-string (calendar-cursor-to-date t) nil t)) | 1587 | (calendar-date-string (calendar-cursor-to-date t) nil t)) |
| 1564 | arg))) | 1588 | arg))) |
| 1565 | 1589 | ||
| 1590 | ;;;###autoload | ||
| 1591 | (define-derived-mode diary-mode text-mode | ||
| 1592 | "Diary" | ||
| 1593 | "Major mode for editing the diary file." | ||
| 1594 | (set (make-local-variable 'font-lock-defaults) | ||
| 1595 | '(diary-font-lock-keywords t))) | ||
| 1596 | |||
| 1597 | (define-derived-mode fancy-diary-display-mode text-mode | ||
| 1598 | "Diary" | ||
| 1599 | "Major mode used while displaying diary entries using Fancy Display." | ||
| 1600 | (set (make-local-variable 'font-lock-defaults) | ||
| 1601 | '(fancy-diary-font-lock-keywords t))) | ||
| 1602 | |||
| 1603 | |||
| 1604 | (defvar fancy-diary-font-lock-keywords | ||
| 1605 | (list | ||
| 1606 | (cons | ||
| 1607 | (concat | ||
| 1608 | (let ((dayname | ||
| 1609 | (concat "\\(" | ||
| 1610 | (diary-name-pattern calendar-day-name-array t) | ||
| 1611 | "\\)")) | ||
| 1612 | (monthname | ||
| 1613 | (concat "\\(" | ||
| 1614 | (diary-name-pattern calendar-month-name-array t) | ||
| 1615 | "\\)")) | ||
| 1616 | (day "[0-9]+") | ||
| 1617 | (year "-?[0-9]+")) | ||
| 1618 | (mapconcat 'eval calendar-date-display-form "")) | ||
| 1619 | "\\(\\(: .*\\)\\|\\(\n +.*\\)\\)*\n=+$") | ||
| 1620 | 'diary-face) | ||
| 1621 | '("^.*anniversary.*$" . font-lock-keyword-face) | ||
| 1622 | '("^.*birthday.*$" . font-lock-keyword-face) | ||
| 1623 | '("^.*Yahrzeit.*$" . font-lock-reference-face) | ||
| 1624 | '("^\\(Erev \\)?Rosh Hodesh.*" . font-lock-function-name-face) | ||
| 1625 | '("^Day.*omer.*$" . font-lock-builtin-face) | ||
| 1626 | '("^Parashat.*$" . font-lock-comment-face) | ||
| 1627 | '("^[ \t]*[0-9]?[0-9]\\(:?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)?\\(-[0-9]?[0-9]\\(:?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)?\\)?" | ||
| 1628 | . font-lock-variable-name-face)) | ||
| 1629 | "Keywords to highlight in fancy diary display") | ||
| 1630 | |||
| 1631 | |||
| 1632 | (defun font-lock-diary-sexps (limit) | ||
| 1633 | "Recognize sexp diary entry for font-locking." | ||
| 1634 | (if (re-search-forward | ||
| 1635 | (concat "^" (regexp-quote diary-nonmarking-symbol) | ||
| 1636 | "?\\(" (regexp-quote sexp-diary-entry-symbol) "\\)") | ||
| 1637 | limit t) | ||
| 1638 | (condition-case nil | ||
| 1639 | (save-restriction | ||
| 1640 | (narrow-to-region (point-min) limit) | ||
| 1641 | (let ((start (point))) | ||
| 1642 | (forward-sexp 1) | ||
| 1643 | (store-match-data (list start (point))) | ||
| 1644 | t)) | ||
| 1645 | (error t)))) | ||
| 1646 | |||
| 1647 | (defun font-lock-diary-date-forms (month-list &optional symbol noabbrev) | ||
| 1648 | "Create a list of font-lock patterns for `diary-date-forms' with MONTH-LIST. | ||
| 1649 | If given, optional SYMBOL must be a prefix to entries. | ||
| 1650 | If optional NOABBREV is t, do not allow abbreviations in names." | ||
| 1651 | (let* ((dayname | ||
| 1652 | (concat "\\(" (diary-name-pattern calendar-day-name-array) "\\)")) | ||
| 1653 | (monthname (concat "\\(" | ||
| 1654 | (diary-name-pattern month-list noabbrev) | ||
| 1655 | "\\|\\*\\)")) | ||
| 1656 | (month "\\([0-9]+\\|\\*\\)") | ||
| 1657 | (day "\\([0-9]+\\|\\*\\)") | ||
| 1658 | (year "-?\\([0-9]+\\|\\*\\)")) | ||
| 1659 | (mapcar '(lambda (x) | ||
| 1660 | (cons | ||
| 1661 | (concat "^" (regexp-quote diary-nonmarking-symbol) "?" | ||
| 1662 | (if symbol (regexp-quote symbol) "") "\\(" | ||
| 1663 | (mapconcat 'eval | ||
| 1664 | ;; If backup, omit first item (backup) | ||
| 1665 | ;; and last item (not part of date) | ||
| 1666 | (if (equal (car x) 'backup) | ||
| 1667 | (reverse (cdr (reverse (cdr x)))) | ||
| 1668 | x) | ||
| 1669 | "") | ||
| 1670 | ;; With backup, last item is not part of date | ||
| 1671 | (if (equal (car x) 'backup) | ||
| 1672 | (concat "\\)" (eval (car (reverse x)))) | ||
| 1673 | "\\)")) | ||
| 1674 | '(1 diary-face))) | ||
| 1675 | diary-date-forms))) | ||
| 1676 | |||
| 1677 | (defvar diary-font-lock-keywords | ||
| 1678 | (append | ||
| 1679 | (font-lock-diary-date-forms calendar-month-name-array) | ||
| 1680 | (if (or (memq 'mark-hebrew-diary-entries | ||
| 1681 | nongregorian-diary-marking-hook) | ||
| 1682 | (memq 'list-hebrew-diary-entries | ||
| 1683 | nongregorian-diary-listing-hook)) | ||
| 1684 | (progn | ||
| 1685 | (require 'cal-hebrew) | ||
| 1686 | (font-lock-diary-date-forms | ||
| 1687 | calendar-hebrew-month-name-array-leap-year | ||
| 1688 | hebrew-diary-entry-symbol t))) | ||
| 1689 | (if (or (memq 'mark-islamic-diary-entries | ||
| 1690 | nongregorian-diary-marking-hook) | ||
| 1691 | (memq 'list-islamic-diary-entries | ||
| 1692 | nongregorian-diary-listing-hook)) | ||
| 1693 | (progn | ||
| 1694 | (require 'cal-islamic) | ||
| 1695 | (font-lock-diary-date-forms | ||
| 1696 | calendar-islamic-month-name-array-leap-year | ||
| 1697 | islamic-diary-entry-symbol t))) | ||
| 1698 | (list | ||
| 1699 | (cons | ||
| 1700 | (concat "^" (regexp-quote diary-include-string) ".*$") | ||
| 1701 | 'font-lock-keyword-face) | ||
| 1702 | (cons | ||
| 1703 | (concat "^" (regexp-quote diary-nonmarking-symbol) | ||
| 1704 | "?\\(" (regexp-quote sexp-diary-entry-symbol) "\\)") | ||
| 1705 | '(1 font-lock-reference-face)) | ||
| 1706 | (cons | ||
| 1707 | (concat "^" (regexp-quote diary-nonmarking-symbol)) | ||
| 1708 | 'font-lock-reference-face) | ||
| 1709 | (cons | ||
| 1710 | (concat "^" (regexp-quote diary-nonmarking-symbol) | ||
| 1711 | "?\\(" (regexp-quote hebrew-diary-entry-symbol) "\\)") | ||
| 1712 | '(1 font-lock-reference-face)) | ||
| 1713 | (cons | ||
| 1714 | (concat "^" (regexp-quote diary-nonmarking-symbol) | ||
| 1715 | "?\\(" (regexp-quote islamic-diary-entry-symbol) "\\)") | ||
| 1716 | '(1 font-lock-reference-face)) | ||
| 1717 | '(font-lock-diary-sexps . font-lock-keyword-face) | ||
| 1718 | '("[0-9]?[0-9]\\(:?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)\\(-[0-9]?[0-9]\\(:?[0-9][0-9]\\)?\\(am\\|pm\\|AM\\|PM\\)\\)?" | ||
| 1719 | . font-lock-function-name-face))) | ||
| 1720 | "Forms to highlight in diary-mode") | ||
| 1721 | |||
| 1722 | |||
| 1566 | (provide 'diary-lib) | 1723 | (provide 'diary-lib) |
| 1567 | 1724 | ||
| 1568 | ;;; diary-lib.el ends here | 1725 | ;;; diary-lib.el ends here |