(diary-display-hook): Declare for compiler.
[emacs.git] / lisp / calendar / cal-x.el
blob76f77315cf19cff3ed66791ae6839f6e3bd6abee
1 ;;; cal-x.el --- calendar windows in dedicated frames
3 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008 Free Software Foundation, Inc.
6 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
9 ;; Keywords: calendar
10 ;; Human-Keywords: calendar, dedicated frames
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; any later version.
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.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
29 ;;; Commentary:
31 ;; See calendar.el.
33 ;;; Code:
35 (require 'calendar)
37 (defcustom diary-frame-parameters
38 '((name . "Diary") (title . "Diary") (height . 10) (width . 80)
39 (unsplittable . t) (minibuffer . nil))
40 "Parameters of the diary frame, if the diary is in its own frame.
41 Relevant if `calendar-setup' has the value `two-frames'."
42 :type 'alist
43 :options '((name string) (title string) (height integer) (width integer)
44 (unsplittable boolean) (minibuffer boolean)
45 (vertical-scroll-bars boolean))
46 :group 'calendar)
48 (defcustom calendar-frame-parameters
49 '((name . "Calendar") (title . "Calendar") (height . 10) (width . 80)
50 (unsplittable . t) (minibuffer . nil) (vertical-scroll-bars . nil))
51 "Parameters of the calendar frame, if the calendar is in a separate frame.
52 Relevant if `calendar-setup' has the value `calendar-only' or `two-frames'."
53 :type 'alist
54 :options '((name string) (title string) (height integer) (width integer)
55 (unsplittable boolean) (minibuffer boolean)
56 (vertical-scroll-bars boolean))
57 :group 'calendar)
59 (defcustom calendar-and-diary-frame-parameters
60 '((name . "Calendar") (title . "Calendar") (height . 28) (width . 80)
61 (minibuffer . nil))
62 "Parameters of the frame that displays both the calendar and the diary.
63 Relevant if `calendar-setup' has the value `one-frame'."
64 :type 'alist
65 :options '((name string) (title string) (height integer) (width integer)
66 (unsplittable boolean) (minibuffer boolean)
67 (vertical-scroll-bars boolean))
68 :group 'calendar)
70 (defcustom calendar-after-frame-setup-hook nil
71 "List of functions to be run after creating a calendar and/or diary frame."
72 :type 'hook
73 :group 'calendar-hooks)
75 (define-obsolete-variable-alias 'calendar-after-frame-setup-hooks
76 'calendar-after-frame-setup-hook "23.1")
78 ;;; End of user options.
80 (defvar calendar-frame nil
81 "Frame in which the calendar was last displayed.")
83 (defvar diary-frame nil
84 "Frame in which the diary was last displayed.")
86 (defun calendar-frame-1 (frame)
87 "Subroutine used by `calendar-frame-setup'.
88 Runs `calendar-after-frame-setup-hook', selects frame, iconifies if needed."
89 (run-hooks 'calendar-after-frame-setup-hook)
90 (select-frame frame)
91 (if (eq 'icon (cdr (assoc 'visibility (frame-parameters frame))))
92 (iconify-or-deiconify-frame)))
94 ;; c-d-d is only called after (diary) has been run.
95 (defvar diary-display-hook)
97 (defun calendar-dedicate-diary ()
98 "Display and dedicate the window associated with the diary buffer."
99 (set-window-dedicated-p
100 (display-buffer
101 (if (not (or (memq 'diary-fancy-display diary-display-hook)
102 (memq 'fancy-diary-display diary-display-hook)))
103 (get-file-buffer diary-file)
104 ;; If there are no diary entries, there won't be a fancy-diary
105 ;; to dedicate, so make a basic one.
106 (or (get-buffer diary-fancy-buffer)
107 (calendar-in-read-only-buffer diary-fancy-buffer
108 (calendar-set-mode-line "Diary Entries")))
109 diary-fancy-buffer))
112 ;;;###cal-autoload
113 (defun calendar-frame-setup (config &optional prompt)
114 "Display the calendar, and optionally the diary, in a separate frame.
115 CONFIG should be one of:
116 `calendar-only' - just the calendar, no diary
117 `one-frame' - calendar and diary in a single frame
118 `two-frames' - calendar and diary each in a separate frame
120 If CONFIG has any other value, or if the display is not capable of
121 multiple frames, then `calendar-basic-setup' is called.
123 If PROMPT is non-nil, prompt for the month and year to use."
124 (if (not (and (display-multi-frame-p)
125 (memq config '(calendar-only one-frame two-frames))))
126 (calendar-basic-setup prompt)
127 (if (frame-live-p calendar-frame) (delete-frame calendar-frame))
128 (unless (eq config 'calendar-only)
129 (if (frame-live-p diary-frame) (delete-frame diary-frame)))
130 (let ((calendar-view-diary-initially-flag (eq config 'one-frame))
131 ;; For calendar-dedicate-diary in two-frames case.
132 (pop-up-windows nil))
133 (save-window-excursion
134 ;; Do diary first so that calendar is always left current.
135 (when (eq config 'two-frames)
136 (calendar-frame-1
137 (setq diary-frame (make-frame diary-frame-parameters)))
138 (diary)
139 (calendar-dedicate-diary))
140 (calendar-frame-1
141 (setq calendar-frame
142 (make-frame (if (eq config 'one-frame)
143 calendar-and-diary-frame-parameters
144 calendar-frame-parameters))))
145 (calendar-basic-setup prompt (not (eq config 'one-frame)))
146 (set-window-buffer (selected-window) calendar-buffer)
147 (set-window-dedicated-p (selected-window) t)
148 (if (eq config 'one-frame)
149 (calendar-dedicate-diary))))))
152 ;;;###cal-autoload
153 (defun calendar-one-frame-setup (&optional prompt)
154 "Display calendar and diary in a single dedicated frame.
155 See `calendar-frame-setup' for more information."
156 (calendar-frame-setup 'one-frame prompt))
158 (make-obsolete 'calendar-one-frame-setup 'calendar-frame-setup "23.1")
161 ;;;###cal-autoload
162 (defun calendar-only-one-frame-setup (&optional prompt)
163 "Display calendar in a dedicated frame.
164 See `calendar-frame-setup' for more information."
165 (calendar-frame-setup 'calendar-only prompt))
167 (make-obsolete 'calendar-only-one-frame-setup 'calendar-frame-setup "23.1")
170 ;;;###cal-autoload
171 (defun calendar-two-frame-setup (&optional prompt)
172 "Display calendar and diary in separate, dedicated frames.
173 See `calendar-frame-setup' for more information."
174 (calendar-frame-setup 'two-frames prompt))
176 (make-obsolete 'calendar-two-frame-setup 'calendar-frame-setup "23.1")
179 ;; Undocumented and probably useless.
180 (defvar cal-x-load-hook nil
181 "Hook run on loading of the `cal-x' package.")
182 (make-obsolete-variable 'cal-x-load-hook "it will be removed in future." "23.1")
184 (run-hooks 'cal-x-load-hook)
187 (provide 'cal-x)
189 ;; arch-tag: c6dbddca-ae84-442d-87fc-244b76e38e17
190 ;;; cal-x.el ends here