(appt-check): Use diary-display-function rather than diary-display-hook.
[bpt/emacs.git] / lisp / calendar / cal-x.el
CommitLineData
551c8f1a 1;;; cal-x.el --- calendar windows in dedicated frames
38e3261c 2
734254f9
GM
3;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4;; 2008 Free Software Foundation, Inc.
38e3261c
ER
5
6;; Author: Michael Kifer <kifer@cs.sunysb.edu>
71ea27ee 7;; Edward M. Reingold <reingold@cs.uiuc.edu>
aff88519 8;; Maintainer: Glenn Morris <rgm@gnu.org>
38e3261c 9;; Keywords: calendar
551c8f1a 10;; Human-Keywords: calendar, dedicated frames
38e3261c
ER
11
12;; This file is part of GNU Emacs.
13
2ed66575 14;; GNU Emacs is free software: you can redistribute it and/or modify
38e3261c 15;; it under the terms of the GNU General Public License as published by
2ed66575
GM
16;; the Free Software Foundation, either version 3 of the License, or
17;; (at your option) any later version.
38e3261c
ER
18
19;; GNU Emacs is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details.
23
24;; You should have received a copy of the GNU General Public License
2ed66575 25;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
38e3261c
ER
26
27;;; Commentary:
28
551c8f1a 29;; See calendar.el.
38e3261c 30
38e3261c
ER
31;;; Code:
32
10dbf039
RS
33(require 'calendar)
34
5fc5b6e1 35(defcustom diary-frame-parameters
4a7cd65c
ER
36 '((name . "Diary") (title . "Diary") (height . 10) (width . 80)
37 (unsplittable . t) (minibuffer . nil))
38e3261c 38 "Parameters of the diary frame, if the diary is in its own frame.
4ec69ba5 39Relevant if `calendar-setup' has the value `two-frames'."
2c080040
GM
40 :type 'alist
41 :options '((name string) (title string) (height integer) (width integer)
42 (unsplittable boolean) (minibuffer boolean)
43 (vertical-scroll-bars boolean))
5fc5b6e1 44 :group 'calendar)
a1506d29 45
734254f9 46(defcustom calendar-frame-parameters
2c080040
GM
47 '((name . "Calendar") (title . "Calendar") (height . 10) (width . 80)
48 (unsplittable . t) (minibuffer . nil) (vertical-scroll-bars . nil))
38e3261c 49 "Parameters of the calendar frame, if the calendar is in a separate frame.
4ec69ba5 50Relevant if `calendar-setup' has the value `calendar-only' or `two-frames'."
2c080040
GM
51 :type 'alist
52 :options '((name string) (title string) (height integer) (width integer)
53 (unsplittable boolean) (minibuffer boolean)
54 (vertical-scroll-bars boolean))
5fc5b6e1 55 :group 'calendar)
38e3261c 56
734254f9 57(defcustom calendar-and-diary-frame-parameters
4a7cd65c
ER
58 '((name . "Calendar") (title . "Calendar") (height . 28) (width . 80)
59 (minibuffer . nil))
38e3261c 60 "Parameters of the frame that displays both the calendar and the diary.
4ec69ba5 61Relevant if `calendar-setup' has the value `one-frame'."
2c080040
GM
62 :type 'alist
63 :options '((name string) (title string) (height integer) (width integer)
64 (unsplittable boolean) (minibuffer boolean)
65 (vertical-scroll-bars boolean))
5fc5b6e1 66 :group 'calendar)
a1506d29 67
1a9f2b77
GM
68(define-obsolete-variable-alias 'calendar-after-frame-setup-hooks
69 'calendar-after-frame-setup-hook "23.1")
70
d2e00929
GM
71(defcustom calendar-after-frame-setup-hook nil
72 "List of functions to be run after creating a calendar and/or diary frame."
5fc5b6e1
GM
73 :type 'hook
74 :group 'calendar-hooks)
75
76;;; End of user options.
77
78(defvar calendar-frame nil
2c080040 79 "Frame in which the calendar was last displayed.")
5fc5b6e1
GM
80
81(defvar diary-frame nil
2c080040
GM
82 "Frame in which the diary was last displayed.")
83
84(defun calendar-frame-1 (frame)
d2e00929
GM
85 "Subroutine used by `calendar-frame-setup'.
86Runs `calendar-after-frame-setup-hook', selects frame, iconifies if needed."
87 (run-hooks 'calendar-after-frame-setup-hook)
2c080040
GM
88 (select-frame frame)
89 (if (eq 'icon (cdr (assoc 'visibility (frame-parameters frame))))
90 (iconify-or-deiconify-frame)))
a1506d29 91
724a25b2
GM
92;; c-d-d is only called after (diary) has been run.
93(defvar diary-display-hook)
94
2c080040 95(defun calendar-dedicate-diary ()
4ec69ba5 96 "Display and dedicate the window associated with the diary buffer."
2c080040
GM
97 (set-window-dedicated-p
98 (display-buffer
9ee4e581
GM
99 (if (not (or (memq 'diary-fancy-display diary-display-hook)
100 (memq 'fancy-diary-display diary-display-hook)))
2c080040 101 (get-file-buffer diary-file)
4ec69ba5
GM
102 ;; If there are no diary entries, there won't be a fancy-diary
103 ;; to dedicate, so make a basic one.
e803eab7
GM
104 (or (get-buffer diary-fancy-buffer)
105 (calendar-in-read-only-buffer diary-fancy-buffer
4ec69ba5 106 (calendar-set-mode-line "Diary Entries")))
e803eab7 107 diary-fancy-buffer))
2c080040
GM
108 t))
109
93695e74 110;;;###cal-autoload
4ec69ba5
GM
111(defun calendar-frame-setup (config &optional prompt)
112 "Display the calendar, and optionally the diary, in a separate frame.
113CONFIG should be one of:
114`calendar-only' - just the calendar, no diary
115`one-frame' - calendar and diary in a single frame
116`two-frames' - calendar and diary each in a separate frame
117
118If CONFIG has any other value, or if the display is not capable of
119multiple frames, then `calendar-basic-setup' is called.
120
121If PROMPT is non-nil, prompt for the month and year to use."
122 (if (not (and (display-multi-frame-p)
123 (memq config '(calendar-only one-frame two-frames))))
124 (calendar-basic-setup prompt)
38e3261c 125 (if (frame-live-p calendar-frame) (delete-frame calendar-frame))
4ec69ba5 126 (unless (eq config 'calendar-only)
2c080040 127 (if (frame-live-p diary-frame) (delete-frame diary-frame)))
e803eab7 128 (let ((calendar-view-diary-initially-flag (eq config 'one-frame))
97bef88e 129 ;; For calendar-dedicate-diary in two-frames case.
4ec69ba5 130 (pop-up-windows nil))
38e3261c 131 (save-window-excursion
4ec69ba5
GM
132 ;; Do diary first so that calendar is always left current.
133 (when (eq config 'two-frames)
2c080040 134 (calendar-frame-1
4ec69ba5
GM
135 (setq diary-frame (make-frame diary-frame-parameters)))
136 (diary)
137 (calendar-dedicate-diary))
138 (calendar-frame-1
139 (setq calendar-frame
140 (make-frame (if (eq config 'one-frame)
141 calendar-and-diary-frame-parameters
142 calendar-frame-parameters))))
143 (calendar-basic-setup prompt (not (eq config 'one-frame)))
144 (set-window-buffer (selected-window) calendar-buffer)
145 (set-window-dedicated-p (selected-window) t)
146 (if (eq config 'one-frame)
147 (calendar-dedicate-diary))))))
148
77a7efce 149
93695e74 150;;;###cal-autoload
4ec69ba5
GM
151(defun calendar-one-frame-setup (&optional prompt)
152 "Display calendar and diary in a single dedicated frame.
153See `calendar-frame-setup' for more information."
154 (calendar-frame-setup 'one-frame prompt))
155
156(make-obsolete 'calendar-one-frame-setup 'calendar-frame-setup "23.1")
157
0f12fdab 158
93695e74 159;;;###cal-autoload
4ec69ba5
GM
160(defun calendar-only-one-frame-setup (&optional prompt)
161 "Display calendar in a dedicated frame.
162See `calendar-frame-setup' for more information."
163 (calendar-frame-setup 'calendar-only prompt))
164
4ec69ba5
GM
165(make-obsolete 'calendar-only-one-frame-setup 'calendar-frame-setup "23.1")
166
97bef88e 167
4ec69ba5
GM
168;;;###cal-autoload
169(defun calendar-two-frame-setup (&optional prompt)
170 "Display calendar and diary in separate, dedicated frames.
171See `calendar-frame-setup' for more information."
172 (calendar-frame-setup 'two-frames prompt))
173
174(make-obsolete 'calendar-two-frame-setup 'calendar-frame-setup "23.1")
175
176
177;; Undocumented and probably useless.
178(defvar cal-x-load-hook nil
179 "Hook run on loading of the `cal-x' package.")
180(make-obsolete-variable 'cal-x-load-hook "it will be removed in future." "23.1")
38e3261c
ER
181
182(run-hooks 'cal-x-load-hook)
183
4ec69ba5 184
38e3261c
ER
185(provide 'cal-x)
186
3fbd3d25 187;; arch-tag: c6dbddca-ae84-442d-87fc-244b76e38e17
38e3261c 188;;; cal-x.el ends here