Comment.
[emacs.git] / lisp / calendar / cal-x.el
blob653ce0e3caa435a0e94229f95091a88b6d4ed15e
1 ;;; cal-x.el --- calendar windows in dedicated frames in X
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, X Window System
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 ;; This collection of functions implements dedicated frames in X for
32 ;; calendar.el.
34 ;;; Code:
36 (require 'calendar)
38 (defcustom diary-frame-parameters
39 '((name . "Diary") (title . "Diary") (height . 10) (width . 80)
40 (unsplittable . t) (minibuffer . nil))
41 "Parameters of the diary frame, if the diary is in its own frame.
42 Relevant if `calendar-setup' has the value `two-frames'."
43 :type 'alist
44 :options '((name string) (title string) (height integer) (width integer)
45 (unsplittable boolean) (minibuffer boolean)
46 (vertical-scroll-bars boolean))
47 :group 'calendar)
49 (defcustom calendar-frame-parameters
50 '((name . "Calendar") (title . "Calendar") (height . 10) (width . 80)
51 (unsplittable . t) (minibuffer . nil) (vertical-scroll-bars . nil))
52 "Parameters of the calendar frame, if the calendar is in a separate frame.
53 Relevant if `calendar-setup' has the value `calendar-only' or `two-frames'."
54 :type 'alist
55 :options '((name string) (title string) (height integer) (width integer)
56 (unsplittable boolean) (minibuffer boolean)
57 (vertical-scroll-bars boolean))
58 :group 'calendar)
60 (defcustom calendar-and-diary-frame-parameters
61 '((name . "Calendar") (title . "Calendar") (height . 28) (width . 80)
62 (minibuffer . nil))
63 "Parameters of the frame that displays both the calendar and the diary.
64 Relevant if `calendar-setup' has the value `one-frame'."
65 :type 'alist
66 :options '((name string) (title string) (height integer) (width integer)
67 (unsplittable boolean) (minibuffer boolean)
68 (vertical-scroll-bars boolean))
69 :group 'calendar)
71 (defcustom calendar-after-frame-setup-hooks nil
72 "Hooks to be run just after setting up a calendar frame.
73 Can be used to change frame parameters, such as font, color, location, etc."
74 :type 'hook
75 :group 'calendar-hooks)
77 ;;; End of user options.
79 (defvar calendar-frame nil
80 "Frame in which the calendar was last displayed.")
82 (defvar diary-frame nil
83 "Frame in which the diary was last displayed.")
85 (defun calendar-frame-1 (frame)
86 "Subroutine used by `calendar-frame-setup'."
87 (run-hooks 'calendar-after-frame-setup-hooks)
88 (select-frame frame)
89 (if (eq 'icon (cdr (assoc 'visibility (frame-parameters frame))))
90 (iconify-or-deiconify-frame)))
92 (defun calendar-dedicate-diary ()
93 "Display and dedicate the window associated with the diary buffer."
94 (set-window-dedicated-p
95 (display-buffer
96 (if (not (memq 'fancy-diary-display diary-display-hook))
97 (get-file-buffer diary-file)
98 ;; If there are no diary entries, there won't be a fancy-diary
99 ;; to dedicate, so make a basic one.
100 (or (buffer-live-p fancy-diary-buffer)
101 (calendar-in-read-only-buffer fancy-diary-buffer
102 (calendar-set-mode-line "Diary Entries")))
103 fancy-diary-buffer))
106 ;;;###cal-autoload
107 (defun calendar-frame-setup (config &optional prompt)
108 "Display the calendar, and optionally the diary, in a separate frame.
109 CONFIG should be one of:
110 `calendar-only' - just the calendar, no diary
111 `one-frame' - calendar and diary in a single frame
112 `two-frames' - calendar and diary each in a separate frame
114 If CONFIG has any other value, or if the display is not capable of
115 multiple frames, then `calendar-basic-setup' is called.
117 If PROMPT is non-nil, prompt for the month and year to use."
118 (if (not (and (display-multi-frame-p)
119 (memq config '(calendar-only one-frame two-frames))))
120 (calendar-basic-setup prompt)
121 (if (frame-live-p calendar-frame) (delete-frame calendar-frame))
122 (unless (eq config 'calendar-only)
123 (if (frame-live-p diary-frame) (delete-frame diary-frame)))
124 (let ((view-diary-entries-initially (eq config 'one-frame))
125 ;; For calendar-dedicate-diary in two-frames case.
126 (pop-up-windows nil))
127 (save-window-excursion
128 ;; Do diary first so that calendar is always left current.
129 (when (eq config 'two-frames)
130 (calendar-frame-1
131 (setq diary-frame (make-frame diary-frame-parameters)))
132 (diary)
133 (calendar-dedicate-diary))
134 (calendar-frame-1
135 (setq calendar-frame
136 (make-frame (if (eq config 'one-frame)
137 calendar-and-diary-frame-parameters
138 calendar-frame-parameters))))
139 (calendar-basic-setup prompt (not (eq config 'one-frame)))
140 (set-window-buffer (selected-window) calendar-buffer)
141 (set-window-dedicated-p (selected-window) t)
142 (if (eq config 'one-frame)
143 (calendar-dedicate-diary))))))
146 ;;;###cal-autoload
147 (defun calendar-one-frame-setup (&optional prompt)
148 "Display calendar and diary in a single dedicated frame.
149 See `calendar-frame-setup' for more information."
150 (calendar-frame-setup 'one-frame prompt))
152 (make-obsolete 'calendar-one-frame-setup 'calendar-frame-setup "23.1")
155 ;;;###cal-autoload
156 (defun calendar-only-one-frame-setup (&optional prompt)
157 "Display calendar in a dedicated frame.
158 See `calendar-frame-setup' for more information."
159 (calendar-frame-setup 'calendar-only prompt))
161 (make-obsolete 'calendar-only-one-frame-setup 'calendar-frame-setup "23.1")
164 ;;;###cal-autoload
165 (defun calendar-two-frame-setup (&optional prompt)
166 "Display calendar and diary in separate, dedicated frames.
167 See `calendar-frame-setup' for more information."
168 (calendar-frame-setup 'two-frames prompt))
170 (make-obsolete 'calendar-two-frame-setup 'calendar-frame-setup "23.1")
173 ;; Undocumented and probably useless.
174 (defvar cal-x-load-hook nil
175 "Hook run on loading of the `cal-x' package.")
176 (make-obsolete-variable 'cal-x-load-hook "it will be removed in future." "23.1")
178 (run-hooks 'cal-x-load-hook)
181 (provide 'cal-x)
183 ;; arch-tag: c6dbddca-ae84-442d-87fc-244b76e38e17
184 ;;; cal-x.el ends here