| | 321 | |
|---|
| | 322 | |
|---|
| | 323 | (defvar diary-modify-entry-list-string-function nil |
|---|
| | 324 | "Function applied to entry string before putting it into the entries list. |
|---|
| | 325 | Can be used by programs integrating a diary list into other buffers (e.g. |
|---|
| | 326 | org.el and planner.el) to modify the string or add properties to it. |
|---|
| | 327 | The function takes a string argument and must return a string.") |
|---|
| | 328 | |
|---|
| | 329 | (defun add-to-diary-list (date string specifier &optional marker |
|---|
| | 330 | globcolor literal) |
|---|
| | 331 | "Add an entry to `diary-entries-list'. |
|---|
| | 332 | Do nothing if DATE or STRING is nil. DATE is the (MONTH DAY |
|---|
| | 333 | YEAR) for which the entry applies; STRING is the text of the |
|---|
| | 334 | entry as it will appear in the diary (i.e. with any format |
|---|
| | 335 | strings such as \"%d\" expanded); SPECIFIER is the date part of |
|---|
| | 336 | the entry as it appears in the diary-file; LITERAL is the entry |
|---|
| | 337 | as it appears in the diary-file (i.e. before expansion). If |
|---|
| | 338 | LITERAL is nil, it is taken to be the same as STRING. |
|---|
| | 339 | |
|---|
| | 340 | The entry is added to the list as (DATE STRING SPECIFIER LOCATOR |
|---|
| | 341 | GLOBCOLOR), where LOCATOR has the form (MARKER FILENAME LITERAL), |
|---|
| | 342 | FILENAME being the file containing the diary entry." |
|---|
| | 343 | (when (and date string) |
|---|
| | 344 | (if diary-file-name-prefix |
|---|
| | 345 | (let ((prefix (funcall diary-file-name-prefix-function |
|---|
| | 346 | (buffer-file-name)))) |
|---|
| | 347 | (or (string= prefix "") |
|---|
| | 348 | (setq string (format "[%s] %s" prefix string))))) |
|---|
| | 349 | (and diary-modify-entry-list-string-function |
|---|
| | 350 | (setq string (funcall diary-modify-entry-list-string-function |
|---|
| | 351 | string))) |
|---|
| | 352 | (setq diary-entries-list |
|---|
| | 353 | (append diary-entries-list |
|---|
| | 354 | (list (list date string specifier |
|---|
| | 355 | (list marker (buffer-file-name) literal) |
|---|
| | 356 | globcolor)))))) |
|---|
| 580 | | (let ((marker (button-get button 'marker))) |
|---|
| 581 | | (when marker |
|---|
| 582 | | (pop-to-buffer (marker-buffer marker)) |
|---|
| 583 | | (goto-char (marker-position marker))))) |
|---|
| | 610 | (let* ((locator (button-get button 'locator)) |
|---|
| | 611 | (marker (car locator)) |
|---|
| | 612 | markbuf file) |
|---|
| | 613 | ;; If marker pointing to diary location is valid, use that. |
|---|
| | 614 | (if (and marker (setq markbuf (marker-buffer marker))) |
|---|
| | 615 | (progn |
|---|
| | 616 | (pop-to-buffer markbuf) |
|---|
| | 617 | (goto-char (marker-position marker))) |
|---|
| | 618 | ;; Marker is invalid (eg buffer has been killed). |
|---|
| | 619 | (or (and (setq file (cadr locator)) |
|---|
| | 620 | (file-exists-p file) |
|---|
| | 621 | (find-file-other-window file) |
|---|
| | 622 | (progn |
|---|
| | 623 | (when (eq major-mode default-major-mode) (diary-mode)) |
|---|
| | 624 | (goto-char (point-min)) |
|---|
| | 625 | (if (re-search-forward (format "%s.*\\(%s\\)" |
|---|
| | 626 | (regexp-quote (nth 2 locator)) |
|---|
| | 627 | (regexp-quote (nth 3 locator))) |
|---|
| | 628 | nil t) |
|---|
| | 629 | (goto-char (match-beginning 1))))) |
|---|
| | 630 | (message "Unable to locate this diary entry"))))) |
|---|
| 676 | | (let* ((marks (nth 4 (car entry-list))) |
|---|
| 677 | | (temp-face (make-symbol |
|---|
| 678 | | (apply |
|---|
| 679 | | 'concat "temp-face-" |
|---|
| 680 | | (mapcar (lambda (sym) |
|---|
| 681 | | (if (stringp sym) |
|---|
| 682 | | sym |
|---|
| 683 | | (symbol-name sym))) |
|---|
| 684 | | marks)))) |
|---|
| 685 | | (faceinfo marks)) |
|---|
| 686 | | (make-face temp-face) |
|---|
| 687 | | ;; Remove :face info from the marks, |
|---|
| 688 | | ;; copy the face info into temp-face |
|---|
| 689 | | (while (setq faceinfo (memq :face faceinfo)) |
|---|
| 690 | | (copy-face (read (nth 1 faceinfo)) temp-face) |
|---|
| 691 | | (setcar faceinfo nil) |
|---|
| 692 | | (setcar (cdr faceinfo) nil)) |
|---|
| 693 | | (setq marks (delq nil marks)) |
|---|
| 694 | | ;; Apply the font aspects. |
|---|
| 695 | | (apply 'set-face-attribute temp-face nil marks) |
|---|
| 696 | | (search-backward entry) |
|---|
| 697 | | (overlay-put |
|---|
| 698 | | (make-overlay (match-beginning 0) (match-end 0)) |
|---|
| 699 | | 'face temp-face))))) |
|---|
| | 729 | (let* ((marks (nth 4 this-entry)) |
|---|
| | 730 | (faceinfo marks) |
|---|
| | 731 | temp-face) |
|---|
| | 732 | (when marks |
|---|
| | 733 | (setq temp-face (make-symbol |
|---|
| | 734 | (apply |
|---|
| | 735 | 'concat "temp-face-" |
|---|
| | 736 | (mapcar (lambda (sym) |
|---|
| | 737 | (if (stringp sym) |
|---|
| | 738 | sym |
|---|
| | 739 | (symbol-name sym))) |
|---|
| | 740 | marks)))) |
|---|
| | 741 | (make-face temp-face) |
|---|
| | 742 | ;; Remove :face info from the marks, |
|---|
| | 743 | ;; copy the face info into temp-face |
|---|
| | 744 | (while (setq faceinfo (memq :face faceinfo)) |
|---|
| | 745 | (copy-face (read (nth 1 faceinfo)) temp-face) |
|---|
| | 746 | (setcar faceinfo nil) |
|---|
| | 747 | (setcar (cdr faceinfo) nil)) |
|---|
| | 748 | (setq marks (delq nil marks)) |
|---|
| | 749 | ;; Apply the font aspects. |
|---|
| | 750 | (apply 'set-face-attribute temp-face nil marks) |
|---|
| | 751 | (search-backward entry) |
|---|
| | 752 | (overlay-put |
|---|
| | 753 | (make-overlay (match-beginning 0) (match-end 0)) |
|---|
| | 754 | 'face temp-face)))))) |
|---|
| 1639 | | (defvar diary-modify-entry-list-string-function nil |
|---|
| 1640 | | "Function applied to entry string before putting it into the entries list. |
|---|
| 1641 | | Can be used by programs integrating a diary list into other buffers (e.g. |
|---|
| 1642 | | org.el and planner.el) to modify the string or add properties to it. |
|---|
| 1643 | | The function takes a string argument and must return a string.") |
|---|
| 1644 | | |
|---|
| 1645 | | (defun add-to-diary-list (date string specifier &optional marker globcolor) |
|---|
| 1646 | | "Add the entry (DATE STRING SPECIFIER MARKER GLOBCOLOR) to `diary-entries-list'. |
|---|
| 1647 | | Do nothing if DATE or STRING is nil." |
|---|
| 1648 | | (when (and date string) |
|---|
| 1649 | | (if diary-file-name-prefix |
|---|
| 1650 | | (let ((prefix (funcall diary-file-name-prefix-function |
|---|
| 1651 | | (buffer-file-name)))) |
|---|
| 1652 | | (or (string= prefix "") |
|---|
| 1653 | | (setq string (format "[%s] %s" prefix string))))) |
|---|
| 1654 | | (and diary-modify-entry-list-string-function |
|---|
| 1655 | | (setq string (funcall diary-modify-entry-list-string-function |
|---|
| 1656 | | string))) |
|---|
| 1657 | | (setq diary-entries-list |
|---|
| 1658 | | (append diary-entries-list |
|---|
| 1659 | | (list (list date string specifier marker globcolor)))))) |
|---|
| 1660 | | |
|---|
| | 1834 | |
|---|
| | 1835 | (defvar diary-fancy-date-pattern |
|---|
| | 1836 | (concat |
|---|
| | 1837 | (let ((dayname (diary-name-pattern calendar-day-name-array nil t)) |
|---|
| | 1838 | (monthname (diary-name-pattern calendar-month-name-array nil t)) |
|---|
| | 1839 | (day "[0-9]+") |
|---|
| | 1840 | (month "[0-9]+") |
|---|
| | 1841 | (year "-?[0-9]+")) |
|---|
| | 1842 | (mapconcat 'eval calendar-date-display-form "")) |
|---|
| | 1843 | ;; Optional ": holiday name" after the date. |
|---|
| | 1844 | "\\(: .*\\)?") |
|---|
| | 1845 | "Regular expression matching a date header in Fancy Diary.") |
|---|
| | 1846 | |
|---|
| | 1847 | (defconst diary-time-regexp |
|---|
| | 1848 | ;; Accepted formats: 10:00 10.00 10h00 10h 10am 10:00am 10.00am |
|---|
| | 1849 | ;; Use of "." as a separator annoyingly matches numbers, eg "123.45". |
|---|
| | 1850 | ;; Hence often prefix this with "\\(^\\|\\s-\\)." |
|---|
| | 1851 | (concat "[0-9]?[0-9]\\([AaPp][mM]\\|\\(" |
|---|
| | 1852 | "[Hh]\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]" |
|---|
| | 1853 | "\\)\\([AaPp][Mm]\\)?\\)") |
|---|
| | 1854 | "Regular expression matching a time of day.") |
|---|
| | 1855 | |
|---|
| | 1856 | (defface diary-anniversary '((t :inherit font-lock-keyword-face)) |
|---|
| | 1857 | "Face used for anniversaries in the diary." |
|---|
| | 1858 | :version "22.1" |
|---|
| | 1859 | :group 'diary) |
|---|
| | 1860 | |
|---|
| | 1861 | (defface diary-time '((t :inherit font-lock-variable-name-face)) |
|---|
| | 1862 | "Face used for times of day in the diary." |
|---|
| | 1863 | :version "22.1" |
|---|
| | 1864 | :group 'diary) |
|---|
| | 1865 | |
|---|
| | 1866 | (defvar fancy-diary-font-lock-keywords |
|---|
| | 1867 | (list |
|---|
| | 1868 | (list |
|---|
| | 1869 | ;; Any number of " other holiday name" lines, followed by "==" line. |
|---|
| | 1870 | (concat diary-fancy-date-pattern "\\(\n +.*\\)*\n=+$") |
|---|
| | 1871 | '(0 (progn (put-text-property (match-beginning 0) (match-end 0) |
|---|
| | 1872 | 'font-lock-multiline t) |
|---|
| | 1873 | diary-face))) |
|---|
| | 1874 | '("^.*\\([aA]nniversary\\|[bB]irthday\\).*$" . 'diary-anniversary) |
|---|
| | 1875 | '("^.*Yahrzeit.*$" . font-lock-reference-face) |
|---|
| | 1876 | '("^\\(Erev \\)?Rosh Hodesh.*" . font-lock-function-name-face) |
|---|
| | 1877 | '("^Day.*omer.*$" . font-lock-builtin-face) |
|---|
| | 1878 | '("^Parashat.*$" . font-lock-comment-face) |
|---|
| | 1879 | `(,(format "\\(^\\|\\s-\\)%s\\(-%s\\)?" diary-time-regexp |
|---|
| | 1880 | diary-time-regexp) . 'diary-time)) |
|---|
| | 1881 | "Keywords to highlight in fancy diary display") |
|---|
| | 1882 | |
|---|
| | 1883 | ;; If region looks like it might start or end in the middle of a |
|---|
| | 1884 | ;; multiline pattern, extend the region to encompass the whole pattern. |
|---|
| | 1885 | (defun diary-fancy-font-lock-fontify-region-function (beg end &optional verbose) |
|---|
| | 1886 | "Function to use for `font-lock-fontify-region-function' in Fancy Diary. |
|---|
| | 1887 | Needed to handle multiline keyword in `fancy-diary-font-lock-keywords'." |
|---|
| | 1888 | (goto-char beg) |
|---|
| | 1889 | (forward-line 0) |
|---|
| | 1890 | (if (looking-at "=+$") (forward-line -1)) |
|---|
| | 1891 | (while (and (looking-at " +[^ ]") |
|---|
| | 1892 | (zerop (forward-line -1)))) |
|---|
| | 1893 | ;; This check not essential. |
|---|
| | 1894 | (if (looking-at diary-fancy-date-pattern) |
|---|
| | 1895 | (setq beg (line-beginning-position))) |
|---|
| | 1896 | (goto-char end) |
|---|
| | 1897 | (forward-line 0) |
|---|
| | 1898 | (while (and (looking-at " +[^ ]") |
|---|
| | 1899 | (zerop (forward-line 1)))) |
|---|
| | 1900 | (if (looking-at "=+$") |
|---|
| | 1901 | (setq end (line-beginning-position 2))) |
|---|
| | 1902 | (font-lock-default-fontify-region beg end verbose)) |
|---|
| | 1903 | |
|---|
| 1805 | | |
|---|
| 1806 | | |
|---|
| 1807 | | (defvar fancy-diary-font-lock-keywords |
|---|
| 1808 | | (list |
|---|
| 1809 | | (cons |
|---|
| 1810 | | (concat |
|---|
| 1811 | | (let ((dayname (diary-name-pattern calendar-day-name-array nil t)) |
|---|
| 1812 | | (monthname (diary-name-pattern calendar-month-name-array nil t)) |
|---|
| 1813 | | (day "[0-9]+") |
|---|
| 1814 | | (month "[0-9]+") |
|---|
| 1815 | | (year "-?[0-9]+")) |
|---|
| 1816 | | (mapconcat 'eval calendar-date-display-form "")) |
|---|
| 1817 | | "\\(\\(: .*\\)\\|\\(\n +.*\\)\\)*\n=+$") |
|---|
| 1818 | | 'diary-face) |
|---|
| 1819 | | '("^.*anniversary.*$" . font-lock-keyword-face) |
|---|
| 1820 | | '("^.*birthday.*$" . font-lock-keyword-face) |
|---|
| 1821 | | '("^.*Yahrzeit.*$" . font-lock-reference-face) |
|---|
| 1822 | | '("^\\(Erev \\)?Rosh Hodesh.*" . font-lock-function-name-face) |
|---|
| 1823 | | '("^Day.*omer.*$" . font-lock-builtin-face) |
|---|
| 1824 | | '("^Parashat.*$" . font-lock-comment-face) |
|---|
| 1825 | | '("^[ \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\\)?\\)?" |
|---|
| 1826 | | . font-lock-variable-name-face)) |
|---|
| 1827 | | "Keywords to highlight in fancy diary display") |
|---|