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