]> code.delx.au - gnu-emacs/blobdiff - lisp/diary-lib.el
(lisp-mode-shared-map): Bind `backspace' to `backward-delete-char-untabify'.
[gnu-emacs] / lisp / diary-lib.el
index f10f22e78c18982411eba66ea45f5903b37a53a2..a78475bc9164bb96ec992a85636d497a22cadc05 100644 (file)
@@ -1,4 +1,4 @@
-;;; diary.el --- diary functions.
+;;; diary-lib.el --- diary functions.
 
 ;; Copyright (C) 1989, 1990, 1992, 1993, 1994 Free Software Foundation, Inc.
 
@@ -67,16 +67,28 @@ in the displayed three-month calendar."
     (if (and d-file (file-exists-p d-file))
         (if (file-readable-p d-file)
             (list-diary-entries (calendar-cursor-to-date t) arg)
-          (error "Your diary file is not readable!"))
+          (error "Diary file is not readable!"))
       (error "You don't have a diary file!"))))
 
+(defun view-other-diary-entries (arg diary-file)
+  "Prepare and display buffer of diary entries from an alternative diary file.
+Prompts for a file name and searches that file for entries that match ARG
+days starting with the date indicated by the cursor position in the displayed
+three-month calendar."
+  (interactive
+   (list (cond ((null current-prefix-arg) 1)
+               ((listp current-prefix-arg) (car current-prefix-arg))
+               (t current-prefix-arg))
+         (setq diary-file (read-file-name "Enter diary file name: "
+                                          default-directory nil t))))
+  (view-diary-entries arg))
+
 (autoload 'check-calendar-holidays "holidays"
   "Check the list of holidays for any that occur on DATE.
 The value returned is a list of strings of relevant holiday descriptions.
 The holidays are those in the list `calendar-holidays'."
   t)
 
-
 (autoload 'calendar-holiday-list "holidays"
   "Form the list of holidays that occur on dates in the calendar window.
 The holidays are those in the list `calendar-holidays'."
@@ -317,6 +329,13 @@ changing the variable `diary-include-string'."
 (defun fancy-diary-display ()
   "Prepare a diary buffer with relevant entries in a fancy, noneditable form.
 This function is provided for optional use as the `diary-display-hook'."
+  (save-excursion;; Turn off selective-display in the diary file's buffer.
+    (set-buffer (get-file-buffer (substitute-in-file-name diary-file)))
+    (let ((diary-modified (buffer-modified-p)))
+      (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)
+      (setq selective-display nil)
+      (kill-local-variable 'mode-line-format)
+      (set-buffer-modified-p diary-modified)))
   (if (or (not diary-entries-list)
           (and (not (cdr diary-entries-list))
                (string-equal (car (cdr (car diary-entries-list))) "")))
@@ -337,19 +356,9 @@ This function is provided for optional use as the `diary-display-hook'."
           (setq buffer-read-only t)
           (display-buffer holiday-buffer)
           (message  "No diary entries for %s" date-string)))
-    (save-excursion;; Turn off selective-display in the diary file's buffer.
-      (set-buffer (get-file-buffer (substitute-in-file-name diary-file)))
-      (let ((diary-modified (buffer-modified-p)))
-        (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)
-        (setq selective-display nil)
-        (kill-local-variable 'mode-line-format)
-        (set-buffer-modified-p diary-modified)))
     (save-excursion;; Prepare the fancy diary buffer.
-      (set-buffer (get-buffer-create fancy-diary-buffer))
+      (set-buffer (make-fancy-diary-buffer))
       (setq buffer-read-only nil)
-      (make-local-variable 'mode-line-format)
-      (calendar-set-mode-line "Diary Entries")
-      (erase-buffer)
       (let ((entry-list diary-entries-list)
             (holiday-list)
             (holiday-list-last-month 1)
@@ -406,6 +415,18 @@ This function is provided for optional use as the `diary-display-hook'."
       (display-buffer fancy-diary-buffer)
       (message "Preparing diary...done"))))
 
+(defun make-fancy-diary-buffer ()
+  "Create and return the initial fancy diary buffer."
+  (save-excursion
+    (set-buffer (get-buffer-create fancy-diary-buffer))
+    (setq buffer-read-only nil)
+    (make-local-variable 'mode-line-format)
+    (calendar-set-mode-line "Diary Entries")
+    (erase-buffer)
+    (set-buffer-modified-p nil)
+    (setq buffer-read-only t)
+    (get-buffer fancy-diary-buffer)))
+
 (defun print-diary-entries ()
   "Print a hard copy of the diary display.
 
@@ -761,12 +782,12 @@ For example, returns 1325 for 1:25pm.  Returns -9999 if no time is recognized.
 The recognized forms are XXXX or X:XX or XX:XX (military time), XXam or XXpm,
 and XX:XXam or XX:XXpm."
   (cond ((string-match;; Military time  
-          "^ *\\([0-9]?[0-9]\\):?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" s)
+          "^[ \t]*\\([0-9]?[0-9]\\):?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)" s)
          (+ (* 100 (string-to-int
                     (substring s (match-beginning 1) (match-end 1))))
             (string-to-int (substring s (match-beginning 2) (match-end 2)))))
         ((string-match;; Hour only  XXam or XXpm
-          "^ *\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s)
+          "^[ \t]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s)
          (+ (* 100 (% (string-to-int
                          (substring s (match-beginning 1) (match-end 1)))
                         12))
@@ -774,7 +795,7 @@ and XX:XXam or XX:XXpm."
                               (substring s (match-beginning 2) (match-end 2)))
                 0 1200)))
         ((string-match;; Hour and minute  XX:XXam or XX:XXpm
-          "^ *\\([0-9]?[0-9]\\):\\([0-9][0-9]\\)\\([ap]\\)m\\>" s)
+          "^[ \t]*\\([0-9]?[0-9]\\):\\([0-9][0-9]\\)\\([ap]\\)m\\>" s)
          (+ (* 100 (% (string-to-int
                          (substring s (match-beginning 1) (match-end 1)))
                         12))
@@ -787,7 +808,7 @@ and XX:XXam or XX:XXpm."
 (defun list-hebrew-diary-entries ()
   "Add any Hebrew date entries from the diary file to `diary-entries-list'.
 Hebrew date diary entries must be prefaced by `hebrew-diary-entry-symbol'
-(normally an `H').  The same diary date forms govern the style of the Hebrew
+\(normally an `H').  The same diary date forms govern the style of the Hebrew
 calendar entries, except that the Hebrew month names must be spelled in full.
 The Hebrew months are numbered from 1 to 13 with Nisan being 1, 12 being
 Adar I and 13 being Adar II; you must use `Adar I' if you want Adar of a
@@ -871,7 +892,7 @@ not be marked in the calendar.  This function is provided for use with the
   "Mark days in the calendar window that have Hebrew date diary entries.
 Each entry in diary-file (or included files) visible in the calendar window
 is marked.  Hebrew date entries are prefaced by a hebrew-diary-entry-symbol
-(normally an `H').  The same diary-date-forms govern the style of the Hebrew
+\(normally an `H').  The same diary-date-forms govern the style of the Hebrew
 calendar entries, except that the Hebrew month names must be spelled in full.
 The Hebrew months are numbered from 1 to 13 with Nisan being 1, 12 being
 Adar I and 13 being Adar II; you must use `Adar I' if you want Adar of a
@@ -1322,7 +1343,7 @@ ending of that number (that is, `st', `nd', `rd' or `th', as appropriate."
 (defun diary-ordinal-suffix (n)
   "Ordinal suffix for N. (That is, `st', `nd', `rd', or `th', as appropriate.)"
   (if (or (memq (% n 100) '(11 12 13))
-         (< 3 (% n 10)))
+          (< 3 (% n 10)))
       "th"
     (aref ["th" "st" "nd" "rd"] (% n 10))))
 
@@ -1650,7 +1671,7 @@ have 30 days), and has Passover start on Tuesday.")
 (defun list-islamic-diary-entries ()
   "Add any Islamic date entries from the diary file to `diary-entries-list'.
 Islamic date diary entries must be prefaced by an `islamic-diary-entry-symbol'
-(normally an `I').  The same diary date forms govern the style of the Islamic
+\(normally an `I').  The same diary date forms govern the style of the Islamic
 calendar entries, except that the Islamic month names must be spelled in full.
 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
 Dhu al-Hijjah.  If an Islamic date diary entry begins with a
@@ -1733,7 +1754,7 @@ not be marked in the calendar.  This function is provided for use with the
   "Mark days in the calendar window that have Islamic date diary entries.
 Each entry in diary-file (or included files) visible in the calendar window
 is marked.  Islamic date entries are prefaced by a islamic-diary-entry-symbol
-(normally an `I').  The same diary-date-forms govern the style of the Islamic
+\(normally an `I').  The same diary-date-forms govern the style of the Islamic
 calendar entries, except that the Islamic month names must be spelled in full.
 The Islamic months are numbered from 1 to 12 with Muharram being 1 and 12 being
 Dhu al-Hijjah.  Islamic date diary entries that begin with a
@@ -1893,6 +1914,6 @@ A value of 0 in any position is a wildcard."
                  (mark-visible-calendar-date
                   (calendar-gregorian-from-absolute date)))))))))
 
-(provide 'diary)
+(provide 'diary-lib)
 
-;;; diary.el ends here
+;;; diary-lib.el ends here