Mercurial > emacs
comparison lisp/calendar/diary-lib.el @ 92664:e7052a7b4ab1
(diary-list-entries, include-other-diary-files, mark-diary-entries)
(mark-sexp-diary-entries, mark-included-diary-files)
(diary-entry-time, list-sexp-diary-entries): Remove the special
handling of ^M that dates back to the use of selective-display.
(simple-diary-display): Obey setting of pop-up-frames.
(body, entry): Remove unnecessary declarations.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 08 Mar 2008 22:43:09 +0000 |
parents | 946554ed4fec |
children | 6f28457f84ac |
comparison
equal
deleted
inserted
replaced
92663:b3b2c224528e | 92664:e7052a7b4ab1 |
---|---|
116 as part of the list-diary-entries-hook, you will probably also want to use the | 116 as part of the list-diary-entries-hook, you will probably also want to use the |
117 function `mark-included-diary-files' as part of `mark-diary-entries-hook'. | 117 function `mark-included-diary-files' as part of `mark-diary-entries-hook'. |
118 | 118 |
119 For example, you could use | 119 For example, you could use |
120 | 120 |
121 (setq list-diary-entries-hook | 121 (add-hook 'list-diary-entries-hook 'include-other-diary-files) |
122 '(include-other-diary-files sort-diary-entries)) | 122 (add-hook 'list-diary-entries-hook 'sort-diary-entries) |
123 (setq diary-display-hook 'fancy-diary-display) | 123 (add-hook 'diary-display-hook 'fancy-diary-display) |
124 | 124 |
125 in your `.emacs' file to cause the fancy diary buffer to be displayed with | 125 in your `.emacs' file to cause the fancy diary buffer to be displayed with |
126 diary entries from various included files, each day's entries sorted into | 126 diary entries from various included files, each day's entries sorted into |
127 lexicographic order." | 127 lexicographic order." |
128 :type 'hook | 128 :type 'hook |
411 syntax of `*' and `:' changed to be word constituents.") | 411 syntax of `*' and `:' changed to be word constituents.") |
412 | 412 |
413 (defvar diary-entries-list) | 413 (defvar diary-entries-list) |
414 (defvar displayed-year) | 414 (defvar displayed-year) |
415 (defvar displayed-month) | 415 (defvar displayed-month) |
416 (defvar entry) | |
417 (defvar date) | 416 (defvar date) |
418 (defvar number) | 417 (defvar number) |
419 (defvar date-string) | 418 (defvar date-string) |
420 (defvar original-date) | 419 (defvar original-date) |
421 | 420 |
720 (if abbreviated-calendar-year | 719 (if abbreviated-calendar-year |
721 (concat "\\|" (format "%02d" (% year 100))) | 720 (concat "\\|" (format "%02d" (% year 100))) |
722 ""))) | 721 ""))) |
723 (regexp | 722 (regexp |
724 (concat | 723 (concat |
725 "\\(\\`\\|\^M\\|\n\\)" mark "?\\(" | 724 "^" mark "?\\(" |
726 (mapconcat 'eval date-form "\\)\\(?:") | 725 (mapconcat 'eval date-form "\\)\\(?:") |
727 "\\)")) | 726 "\\)")) |
728 (case-fold-search t)) | 727 (case-fold-search t)) |
729 (goto-char (point-min)) | 728 (goto-char (point-min)) |
730 (while (re-search-forward regexp nil t) | 729 (while (re-search-forward regexp nil t) |
731 (if backup (re-search-backward "\\<" nil t)) | 730 (if backup (re-search-backward "\\<" nil t)) |
732 (if (and (or (char-equal (preceding-char) ?\^M) | 731 (if (and (bolp) (not (looking-at "[ \t]"))) |
733 (char-equal (preceding-char) ?\n)) | |
734 (not (looking-at " \\|\^I"))) | |
735 ;; Diary entry that consists only of date. | 732 ;; Diary entry that consists only of date. |
736 (backward-char 1) | 733 (backward-char 1) |
737 ;; Found a nonempty diary entry--make it | 734 ;; Found a nonempty diary entry--make it |
738 ;; visible and add it to the list. | 735 ;; visible and add it to the list. |
739 (setq entry-found t) | 736 (setq entry-found t) |
737 (if (looking-at "[ \t]*\n[ \t]") (forward-line 1)) | |
740 (let ((entry-start (point)) | 738 (let ((entry-start (point)) |
741 date-start temp) | 739 date-start temp) |
742 (re-search-backward "\^M\\|\n\\|\\`") | 740 (setq date-start |
743 (setq date-start (point)) | 741 (line-end-position |
744 ;; When selective display (rather than | 742 (if (and (bolp) (> number 1)) -1 0))) |
745 ;; overlays) was used, diary file used to | 743 (forward-line 1) |
746 ;; start in a blank line and end in a | 744 (while (looking-at "[ \t]") |
747 ;; newline. Now that neither of these | 745 (forward-line 1)) |
748 ;; need be true, 'move handles the latter | |
749 ;; and 1/2 kludge the former. | |
750 (re-search-forward | |
751 "\^M\\|\n" nil 'move | |
752 (if (and (bobp) (not (looking-at "\^M\\|\n"))) | |
753 1 | |
754 2)) | |
755 (while (looking-at " \\|\^I") | |
756 (re-search-forward "\^M\\|\n" nil 'move)) | |
757 (unless (and (eobp) (not (bolp))) | 746 (unless (and (eobp) (not (bolp))) |
758 (backward-char 1)) | 747 (backward-char 1)) |
759 (unless list-only | 748 (unless list-only |
760 (remove-overlays date-start (point) | 749 (remove-overlays date-start (point) |
761 'invisible 'diary)) | 750 'invisible 'diary)) |
800 are obeyed. You can change the `#include' to some other string by | 789 are obeyed. You can change the `#include' to some other string by |
801 changing the variable `diary-include-string'." | 790 changing the variable `diary-include-string'." |
802 (goto-char (point-min)) | 791 (goto-char (point-min)) |
803 (while (re-search-forward | 792 (while (re-search-forward |
804 (concat | 793 (concat |
805 "\\(?:\\`\\|\^M\\|\n\\)" | 794 "^" |
806 (regexp-quote diary-include-string) | 795 (regexp-quote diary-include-string) |
807 " \"\\([^\"]*\\)\"") | 796 " \"\\([^\"]*\\)\"") |
808 nil t) | 797 nil t) |
809 (let* ((diary-file (substitute-in-file-name | 798 (let* ((diary-file (substitute-in-file-name |
810 (match-string-no-properties 1))) | 799 (match-string-no-properties 1))) |
837 (if holiday-list ": " "") | 826 (if holiday-list ": " "") |
838 (mapconcat 'identity holiday-list "; "))) | 827 (mapconcat 'identity holiday-list "; "))) |
839 (msg (format "No diary entries for %s" hol-string)) | 828 (msg (format "No diary entries for %s" hol-string)) |
840 ;; If selected window is dedicated (to the calendar), | 829 ;; If selected window is dedicated (to the calendar), |
841 ;; need a new one to display the diary. | 830 ;; need a new one to display the diary. |
842 (pop-up-frames (window-dedicated-p (selected-window)))) | 831 (pop-up-frames (or pop-up-frames |
832 (window-dedicated-p (selected-window))))) | |
843 (calendar-set-mode-line (format "Diary for %s" hol-string)) | 833 (calendar-set-mode-line (format "Diary for %s" hol-string)) |
844 (if (or (not diary-entries-list) | 834 (if (or (not diary-entries-list) |
845 (and (not (cdr diary-entries-list)) | 835 (and (not (cdr diary-entries-list)) |
846 (string-equal (car (cdr (car diary-entries-list))) ""))) | 836 (string-equal (car (cdr (car diary-entries-list))) ""))) |
847 (if (< (length msg) (frame-width)) | 837 (if (< (length msg) (frame-width)) |
1207 (month "[0-9]+\\|\\*") | 1197 (month "[0-9]+\\|\\*") |
1208 (day "[0-9]+\\|\\*") | 1198 (day "[0-9]+\\|\\*") |
1209 (year "[0-9]+\\|\\*") | 1199 (year "[0-9]+\\|\\*") |
1210 (l (length date-form)) | 1200 (l (length date-form)) |
1211 (d-name-pos (- l (length (memq 'dayname date-form)))) | 1201 (d-name-pos (- l (length (memq 'dayname date-form)))) |
1212 (d-name-pos (if (/= l d-name-pos) (+ 2 d-name-pos))) | 1202 (d-name-pos (if (/= l d-name-pos) (+ 1 d-name-pos))) |
1213 (m-name-pos (- l (length (memq 'monthname date-form)))) | 1203 (m-name-pos (- l (length (memq 'monthname date-form)))) |
1214 (m-name-pos (if (/= l m-name-pos) (+ 2 m-name-pos))) | 1204 (m-name-pos (if (/= l m-name-pos) (+ 1 m-name-pos))) |
1215 (d-pos (- l (length (memq 'day date-form)))) | 1205 (d-pos (- l (length (memq 'day date-form)))) |
1216 (d-pos (if (/= l d-pos) (+ 2 d-pos))) | 1206 (d-pos (if (/= l d-pos) (+ 1 d-pos))) |
1217 (m-pos (- l (length (memq 'month date-form)))) | 1207 (m-pos (- l (length (memq 'month date-form)))) |
1218 (m-pos (if (/= l m-pos) (+ 2 m-pos))) | 1208 (m-pos (if (/= l m-pos) (+ 1 m-pos))) |
1219 (y-pos (- l (length (memq 'year date-form)))) | 1209 (y-pos (- l (length (memq 'year date-form)))) |
1220 (y-pos (if (/= l y-pos) (+ 2 y-pos))) | 1210 (y-pos (if (/= l y-pos) (+ 1 y-pos))) |
1221 (regexp | 1211 (regexp |
1222 (concat | 1212 (concat |
1223 "\\(\\`\\|\^M\\|\n\\)\\(" | 1213 "^\\(" |
1224 (mapconcat 'eval date-form "\\)\\(") | 1214 (mapconcat 'eval date-form "\\)\\(") |
1225 "\\)")) | 1215 "\\)")) |
1226 (case-fold-search t)) | 1216 (case-fold-search t)) |
1227 (goto-char (point-min)) | 1217 (goto-char (point-min)) |
1228 (while (re-search-forward regexp nil t) | 1218 (while (re-search-forward regexp nil t) |
1287 (defun mark-sexp-diary-entries () | 1277 (defun mark-sexp-diary-entries () |
1288 "Mark days in the calendar window that have sexp diary entries. | 1278 "Mark days in the calendar window that have sexp diary entries. |
1289 Each entry in the diary file (or included files) visible in the calendar window | 1279 Each entry in the diary file (or included files) visible in the calendar window |
1290 is marked. See the documentation for the function `list-sexp-diary-entries'." | 1280 is marked. See the documentation for the function `list-sexp-diary-entries'." |
1291 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol)) | 1281 (let* ((sexp-mark (regexp-quote sexp-diary-entry-symbol)) |
1292 (s-entry (concat "\\(\\`\\|\^M\\|\n\\)\\(" | 1282 (s-entry (concat "^\\(" |
1293 sexp-mark "(\\)\\|\\(" | 1283 sexp-mark "(\\)\\|\\(" |
1294 (regexp-quote diary-nonmarking-symbol) | 1284 (regexp-quote diary-nonmarking-symbol) |
1295 sexp-mark "(diary-remind\\)")) | 1285 sexp-mark "(diary-remind\\)")) |
1296 (file-glob-attrs (nth 1 (diary-pull-attrs nil '()))) | 1286 (file-glob-attrs (nth 1 (diary-pull-attrs nil '()))) |
1297 m y first-date last-date mark file-glob-attrs) | 1287 m y first-date last-date mark file-glob-attrs) |
1308 (goto-char (point-min)) | 1298 (goto-char (point-min)) |
1309 (while (re-search-forward s-entry nil t) | 1299 (while (re-search-forward s-entry nil t) |
1310 (setq marking-diary-entry (char-equal (preceding-char) ?\()) | 1300 (setq marking-diary-entry (char-equal (preceding-char) ?\()) |
1311 (re-search-backward "(") | 1301 (re-search-backward "(") |
1312 (let ((sexp-start (point)) | 1302 (let ((sexp-start (point)) |
1313 sexp entry entry-start line-start marks) | 1303 sexp entry entry-start marks) |
1314 (forward-sexp) | 1304 (forward-sexp) |
1315 (setq sexp (buffer-substring-no-properties sexp-start (point))) | 1305 (setq sexp (buffer-substring-no-properties sexp-start (point))) |
1316 (save-excursion | |
1317 (re-search-backward "\^M\\|\n\\|\\`") | |
1318 (setq line-start (point))) | |
1319 (forward-char 1) | 1306 (forward-char 1) |
1320 (if (and (or (char-equal (preceding-char) ?\^M) | 1307 (if (and (bolp) (not (looking-at "[ \t]"))) |
1321 (char-equal (preceding-char) ?\n)) | |
1322 (not (looking-at " \\|\^I"))) | |
1323 (progn;; Diary entry consists only of the sexp | 1308 (progn;; Diary entry consists only of the sexp |
1324 (backward-char 1) | 1309 (backward-char 1) |
1325 (setq entry "")) | 1310 (setq entry "")) |
1326 (setq entry-start (point)) | 1311 (setq entry-start (point)) |
1327 ;; Find end of entry | 1312 ;; Find end of entry |
1328 (re-search-forward "\^M\\|\n" nil t) | 1313 (forward-line 1) |
1329 (while (looking-at " \\|\^I") | 1314 (while (looking-at "[ \t]") |
1330 (or (re-search-forward "\^M\\|\n" nil t) | 1315 (forward-line 1)) |
1331 (re-search-forward "$" nil t))) | 1316 (if (bolp) (backward-char 1)) |
1332 (if (or (char-equal (preceding-char) ?\^M) | 1317 (setq entry (buffer-substring-no-properties entry-start (point)))) |
1333 (char-equal (preceding-char) ?\n)) | |
1334 (backward-char 1)) | |
1335 (setq entry (buffer-substring-no-properties entry-start (point))) | |
1336 (while (string-match "[\^M]" entry) | |
1337 (aset entry (match-beginning 0) ?\n ))) | |
1338 (calendar-for-loop date from first-date to last-date do | 1318 (calendar-for-loop date from first-date to last-date do |
1339 (if (setq mark (diary-sexp-entry sexp entry | 1319 (if (setq mark (diary-sexp-entry sexp entry |
1340 (calendar-gregorian-from-absolute date))) | 1320 (calendar-gregorian-from-absolute date))) |
1341 (progn | 1321 (progn |
1342 (setq marks (diary-pull-attrs entry file-glob-attrs) | 1322 (setq marks (diary-pull-attrs entry file-glob-attrs) |
1358 are obeyed. You can change the `#include' to some other string by | 1338 are obeyed. You can change the `#include' to some other string by |
1359 changing the variable `diary-include-string'." | 1339 changing the variable `diary-include-string'." |
1360 (goto-char (point-min)) | 1340 (goto-char (point-min)) |
1361 (while (re-search-forward | 1341 (while (re-search-forward |
1362 (concat | 1342 (concat |
1363 "\\(?:\\`\\|\^M\\|\n\\)" | 1343 "^" |
1364 (regexp-quote diary-include-string) | 1344 (regexp-quote diary-include-string) |
1365 " \"\\([^\"]*\\)\"") | 1345 " \"\\([^\"]*\\)\"") |
1366 nil t) | 1346 nil t) |
1367 (let* ((diary-file (substitute-in-file-name | 1347 (let* ((diary-file (substitute-in-file-name |
1368 (match-string-no-properties 1))) | 1348 (match-string-no-properties 1))) |
1448 The recognized forms are XXXX, X:XX, or XX:XX (military time), and XXam, | 1428 The recognized forms are XXXX, X:XX, or XX:XX (military time), and XXam, |
1449 XXAM, XXpm, XXPM, XX:XXam, XX:XXAM XX:XXpm, or XX:XXPM. A period (.) can | 1429 XXAM, XXpm, XXPM, XX:XXam, XX:XXAM XX:XXpm, or XX:XXPM. A period (.) can |
1450 be used instead of a colon (:) to separate the hour and minute parts." | 1430 be used instead of a colon (:) to separate the hour and minute parts." |
1451 (let ((case-fold-search nil)) | 1431 (let ((case-fold-search nil)) |
1452 (cond ((string-match ; Military time | 1432 (cond ((string-match ; Military time |
1453 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)[:.]?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" | 1433 "\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" |
1454 s) | 1434 s) |
1455 (+ (* 100 (string-to-number (match-string 1 s))) | 1435 (+ (* 100 (string-to-number (match-string 1 s))) |
1456 (string-to-number (match-string 2 s)))) | 1436 (string-to-number (match-string 2 s)))) |
1457 ((string-match ; Hour only XXam or XXpm | 1437 ((string-match ; Hour only XXam or XXpm |
1458 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s) | 1438 "\\`[ \t\n]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s) |
1459 (+ (* 100 (% (string-to-number (match-string 1 s)) 12)) | 1439 (+ (* 100 (% (string-to-number (match-string 1 s)) 12)) |
1460 (if (equal ?a (downcase (aref s (match-beginning 2)))) | 1440 (if (equal ?a (downcase (aref s (match-beginning 2)))) |
1461 0 1200))) | 1441 0 1200))) |
1462 ((string-match ; Hour and minute XX:XXam or XX:XXpm | 1442 ((string-match ; Hour and minute XX:XXam or XX:XXpm |
1463 "\\`[ \t\n\\^M]*\\([0-9]?[0-9]\\)[:.]\\([0-9][0-9]\\)\\([ap]\\)m\\>" s) | 1443 "\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]\\([0-9][0-9]\\)\\([ap]\\)m\\>" s) |
1464 (+ (* 100 (% (string-to-number (match-string 1 s)) 12)) | 1444 (+ (* 100 (% (string-to-number (match-string 1 s)) 12)) |
1465 (string-to-number (match-string 2 s)) | 1445 (string-to-number (match-string 2 s)) |
1466 (if (equal ?a (downcase (aref s (match-beginning 3)))) | 1446 (if (equal ?a (downcase (aref s (match-beginning 3)))) |
1467 0 1200))) | 1447 0 1200))) |
1468 (t diary-unknown-time)))) ; Unrecognizable | 1448 (t diary-unknown-time)))) ; Unrecognizable |
1628 from Passover to Shavuot. Note that since there is no text, | 1608 from Passover to Shavuot. Note that since there is no text, |
1629 it makes sense only if the fancy diary display is used. | 1609 it makes sense only if the fancy diary display is used. |
1630 | 1610 |
1631 Marking these entries is *extremely* time consuming, so these entries are | 1611 Marking these entries is *extremely* time consuming, so these entries are |
1632 best if they are nonmarking." | 1612 best if they are nonmarking." |
1633 (let ((s-entry (concat "\\(\\`\\|\^M\\|\n\\)" | 1613 (let ((s-entry (concat "^" |
1634 (regexp-quote diary-nonmarking-symbol) | 1614 (regexp-quote diary-nonmarking-symbol) |
1635 "?" | 1615 "?" |
1636 (regexp-quote sexp-diary-entry-symbol) | 1616 (regexp-quote sexp-diary-entry-symbol) |
1637 "(")) | 1617 "(")) |
1638 entry-found file-glob-attrs marks) | 1618 entry-found file-glob-attrs marks) |
1643 (backward-char 1) | 1623 (backward-char 1) |
1644 (let ((sexp-start (point)) | 1624 (let ((sexp-start (point)) |
1645 sexp entry specifier entry-start line-start) | 1625 sexp entry specifier entry-start line-start) |
1646 (forward-sexp) | 1626 (forward-sexp) |
1647 (setq sexp (buffer-substring-no-properties sexp-start (point))) | 1627 (setq sexp (buffer-substring-no-properties sexp-start (point))) |
1648 (save-excursion | 1628 (setq line-start (line-end-position 0)) |
1649 (re-search-backward "\^M\\|\n\\|\\`") | |
1650 (setq line-start (point))) | |
1651 (setq specifier | 1629 (setq specifier |
1652 (buffer-substring-no-properties (1+ line-start) (point)) | 1630 (buffer-substring-no-properties (1+ line-start) (point)) |
1653 entry-start (1+ line-start)) | 1631 entry-start (1+ line-start)) |
1654 (forward-char 1) | 1632 (forward-char 1) |
1655 (if (and (or (char-equal (preceding-char) ?\^M) | 1633 (if (and (bolp) (not (looking-at "[ \t]"))) |
1656 (char-equal (preceding-char) ?\n)) | |
1657 (not (looking-at " \\|\^I"))) | |
1658 (progn;; Diary entry consists only of the sexp | 1634 (progn;; Diary entry consists only of the sexp |
1659 (backward-char 1) | 1635 (backward-char 1) |
1660 (setq entry "")) | 1636 (setq entry "")) |
1661 (setq entry-start (point)) | 1637 (setq entry-start (point)) |
1662 (re-search-forward "\^M\\|\n" nil t) | 1638 (forward-line 1) |
1663 (while (looking-at " \\|\^I") | 1639 (while (looking-at "[ \t]") |
1664 (re-search-forward "\^M\\|\n" nil t)) | 1640 (forward-line 1)) |
1665 (backward-char 1) | 1641 (backward-char 1) |
1666 (setq entry (buffer-substring-no-properties entry-start (point))) | 1642 (setq entry (buffer-substring-no-properties entry-start (point)))) |
1667 (while (string-match "[\^M]" entry) | |
1668 (aset entry (match-beginning 0) ?\n ))) | |
1669 (let ((diary-entry (diary-sexp-entry sexp entry date)) | 1643 (let ((diary-entry (diary-sexp-entry sexp entry date)) |
1670 temp literal) | 1644 temp literal) |
1671 (setq literal entry ; before evaluation | 1645 (setq literal entry ; before evaluation |
1672 entry (if (consp diary-entry) | 1646 entry (if (consp diary-entry) |
1673 (cdr diary-entry) | 1647 (cdr diary-entry) |
2253 ;; which case they will prompt about adding to the diary). The | 2227 ;; which case they will prompt about adding to the diary). The |
2254 ;; message formats recognized are customizable through | 2228 ;; message formats recognized are customizable through |
2255 ;; `diary-outlook-formats'. | 2229 ;; `diary-outlook-formats'. |
2256 | 2230 |
2257 ;; Dynamically bound. | 2231 ;; Dynamically bound. |
2258 (defvar body) | |
2259 (defvar subject) | 2232 (defvar subject) |
2260 | 2233 |
2261 (defun diary-from-outlook-internal (&optional test-only) | 2234 (defun diary-from-outlook-internal (&optional test-only) |
2262 "Snarf a diary entry from a message assumed to be from MS Outlook. | 2235 "Snarf a diary entry from a message assumed to be from MS Outlook. |
2263 Assumes `body' is bound to a string comprising the body of the message and | 2236 Assumes `body' is bound to a string comprising the body of the message and |