Show
Ignore:
Timestamp:
05/27/06 10:35:24 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/calendar/diary-lib.el

    r4085 r4091  
    122122 
    123123(autoload 'diary-bahai-date "cal-bahai" 
    124   "Baha'i calendar equivalent of date diary entry." 
    125   t) 
     124  "Baha'i calendar equivalent of date diary entry.") 
    126125 
    127126(autoload 'list-bahai-diary-entries "cal-bahai" 
    128   "Add any Baha'i date entries from the diary file to `diary-entries-list'." 
    129   t) 
     127  "Add any Baha'i date entries from the diary file to `diary-entries-list'.") 
    130128 
    131129(autoload 'mark-bahai-diary-entries "cal-bahai" 
    132   "Mark days in the calendar window that have Baha'i date diary entries." 
    133   t) 
     130  "Mark days in the calendar window that have Baha'i date diary entries.") 
    134131 
    135132(autoload 'mark-bahai-calendar-date-pattern "cal-bahai" 
    136    "Mark dates in calendar window that conform to Baha'i date MONTH/DAY/YEAR." 
    137   t) 
     133   "Mark dates in calendar window that conform to Baha'i date MONTH/DAY/YEAR.") 
    138134 
    139135(autoload 'diary-hebrew-date "cal-hebrew" 
     
    323319                         (integer :tag "Saturday"))) 
    324320  :group 'diary) 
     321 
     322 
     323(defvar diary-modify-entry-list-string-function nil 
     324  "Function applied to entry string before putting it into the entries list. 
     325Can be used by programs integrating a diary list into other buffers (e.g. 
     326org.el and planner.el) to modify the string or add properties to it. 
     327The 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'. 
     332Do nothing if DATE or STRING is nil.  DATE is the (MONTH DAY 
     333YEAR) for which the entry applies; STRING is the text of the 
     334entry as it will appear in the diary (i.e. with any format 
     335strings such as \"%d\" expanded); SPECIFIER is the date part of 
     336the entry as it appears in the diary-file; LITERAL is the entry 
     337as it appears in the diary-file (i.e. before expansion).  If 
     338LITERAL is nil, it is taken to be the same as STRING. 
     339 
     340The entry is added to the list as (DATE STRING SPECIFIER LOCATOR 
     341GLOBCOLOR), where LOCATOR has the form (MARKER FILENAME LITERAL), 
     342FILENAME 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)))))) 
    325357 
    326358(define-obsolete-function-alias 'list-diary-entries 'diary-list-entries) 
     
    469501                   (or entry-found 
    470502                       (not diary-list-include-blanks) 
    471                        (setq diary-entries-list 
    472                              (append diary-entries-list 
    473                                      (list (list date "" "" "" ""))))) 
     503                       (add-to-diary-list date "" "" "" "")) 
    474504                   (setq date 
    475505                         (calendar-gregorian-from-absolute 
     
    578608 
    579609(defun diary-goto-entry (button) 
    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"))))) 
    584631 
    585632(defun fancy-diary-display () 
     
    667714          (setq entry (car (cdr (car entry-list)))) 
    668715          (if (< 0 (length entry)) 
    669               (progn 
    670                 (if (nth 3 (car entry-list)) 
     716              (let ((this-entry (car entry-list)) 
     717                    this-loc) 
     718                (if (setq this-loc (nth 3 this-entry)) 
    671719                    (insert-button (concat entry "\n") 
    672                                    'marker (nth 3 (car entry-list)) 
     720                                   ;; (MARKER FILENAME SPECIFIER LITERAL) 
     721                                   'locator (list (car this-loc) 
     722                                                  (cadr this-loc) 
     723                                                  (nth 2 this-entry) 
     724                                                  (or (nth 2 this-loc) 
     725                                                      (nth 1 this-entry))) 
    673726                                   :type 'diary-entry) 
    674727                  (insert entry ?\n)) 
    675728                (save-excursion 
    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)))))) 
    700755          (setq entry-list (cdr entry-list)))) 
    701756      (set-buffer-modified-p nil) 
     
    13511406        (setq specifier 
    13521407              (buffer-substring-no-properties (1+ line-start) (point)) 
    1353              entry-start (1+ line-start)) 
     1408              entry-start (1+ line-start)) 
    13541409        (forward-char 1) 
    13551410        (if (and (or (char-equal (preceding-char) ?\^M) 
     
    13681423            (aset entry (match-beginning 0) ?\n ))) 
    13691424        (let ((diary-entry (diary-sexp-entry sexp entry date)) 
    1370               temp) 
    1371           (setq entry (if (consp diary-entry) 
    1372                           (cdr diary-entry) 
    1373                         diary-entry)) 
     1425              temp literal) 
     1426          (setq literal entry           ; before evaluation 
     1427                entry (if (consp diary-entry) 
     1428                          (cdr diary-entry) 
     1429                        diary-entry)) 
    13741430          (if diary-entry 
    1375              (progn 
     1431              (progn 
    13761432                (remove-overlays line-start (point) 'invisible 'diary) 
    1377                 (if (< 0 (length entry)) 
    1378                     (setq temp (diary-pull-attrs entry file-glob-attrs) 
    1379                           entry (nth 0 temp) 
    1380                           marks (nth 1 temp))))) 
    1381           (add-to-diary-list date 
    1382                              entry 
    1383                              specifier 
    1384                              (if entry-start (copy-marker entry-start) 
    1385                                nil) 
    1386                              marks) 
    1387           (setq entry-found (or entry-found diary-entry))))) 
     1433                (if (< 0 (length entry)) 
     1434                    (setq temp (diary-pull-attrs entry file-glob-attrs) 
     1435                          entry (nth 0 temp) 
     1436                          marks (nth 1 temp))))) 
     1437          (add-to-diary-list date 
     1438                             entry 
     1439                             specifier 
     1440                             (if entry-start (copy-marker entry-start) 
     1441                               nil) 
     1442                             marks 
     1443                             literal) 
     1444          (setq entry-found (or entry-found diary-entry))))) 
    13881445    entry-found)) 
    13891446 
     
    16371694          (diary-remind sexp (cdr days) marking)))))) 
    16381695 
    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  
    16611696(defun diary-redraw-calendar () 
    16621697  "If `calendar-buffer' is live and diary entries are marked, redraw it." 
     
    17971832      (setq header-line-format diary-header-line-format))) 
    17981833 
     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. 
     1887Needed 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 
    17991904(define-derived-mode fancy-diary-display-mode fundamental-mode 
    18001905  "Diary" 
    18011906  "Major mode used while displaying diary entries using Fancy Display." 
    18021907  (set (make-local-variable 'font-lock-defaults) 
    1803        '(fancy-diary-font-lock-keywords t)) 
     1908       '(fancy-diary-font-lock-keywords 
     1909         t nil nil nil 
     1910         (font-lock-fontify-region-function 
     1911          . diary-fancy-font-lock-fontify-region-function))) 
    18041912  (local-set-key "q" 'quit-window)) 
    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") 
    18281913 
    18291914 
     
    18771962(eval-when-compile (require 'cal-hebrew) 
    18781963                   (require 'cal-islam)) 
    1879  
    1880 (defconst diary-time-regexp 
    1881   ;; Formats that should be accepted: 
    1882   ;;   10:00 10.00 10h00 10h 10am 10:00am 10.00am 
    1883   (concat "[0-9]?[0-9]\\([AaPp][mM]\\|\\(" 
    1884           "[Hh]\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]" 
    1885           "\\)\\([AaPp][Mm]\\)?\\)")) 
    18861964 
    18871965(defvar diary-font-lock-keywords 
     
    19252003         '(1 font-lock-reference-face)) 
    19262004        '(diary-font-lock-sexps . font-lock-keyword-face) 
    1927         (cons 
    1928          (concat ;; "^[ \t]+" 
    1929                  diary-time-regexp "\\(-" diary-time-regexp "\\)?") 
    1930          'font-lock-function-name-face))) 
     2005        `(,(concat "\\(^\\|\\s-\\)" 
     2006                   diary-time-regexp "\\(-" diary-time-regexp "\\)?") 
     2007          . 'diary-time))) 
    19312008      "Forms to highlight in `diary-mode'.") 
    19322009