cal-x.el 5.65 KB
Newer Older
1
;;; cal-x.el --- calendar windows in dedicated frames
Edward M. Reingold's avatar
Edward M. Reingold committed
2

3
;; Copyright (C) 1994-1995, 2001-2014 Free Software Foundation, Inc.
Edward M. Reingold's avatar
Edward M. Reingold committed
4 5

;; Author: Michael Kifer <kifer@cs.sunysb.edu>
Glenn Morris's avatar
Glenn Morris committed
6
;;         Edward M. Reingold <reingold@cs.uiuc.edu>
7
;; Maintainer: Glenn Morris <rgm@gnu.org>
Edward M. Reingold's avatar
Edward M. Reingold committed
8
;; Keywords: calendar
9
;; Human-Keywords: calendar, dedicated frames
10
;; Package: calendar
Edward M. Reingold's avatar
Edward M. Reingold committed
11 12 13

;; This file is part of GNU Emacs.

14
;; GNU Emacs is free software: you can redistribute it and/or modify
Edward M. Reingold's avatar
Edward M. Reingold committed
15
;; it under the terms of the GNU General Public License as published by
16 17
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Edward M. Reingold's avatar
Edward M. Reingold committed
18 19 20 21 22 23 24

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
25
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Edward M. Reingold's avatar
Edward M. Reingold committed
26 27 28

;;; Commentary:

29
;; See calendar.el.
Edward M. Reingold's avatar
Edward M. Reingold committed
30 31 32

;;; Code:

Richard M. Stallman's avatar
Richard M. Stallman committed
33 34
(require 'calendar)

35
(defcustom diary-frame-parameters
36 37
  '((name . "Diary") (title . "Diary") (height . 10) (width . 80)
    (unsplittable . t) (minibuffer . nil))
Edward M. Reingold's avatar
Edward M. Reingold committed
38
  "Parameters of the diary frame, if the diary is in its own frame.
39
Relevant if `calendar-setup' has the value `two-frames'."
40 41 42 43
  :type 'alist
  :options '((name string) (title string) (height integer) (width integer)
             (unsplittable boolean) (minibuffer boolean)
             (vertical-scroll-bars boolean))
44
  :group 'calendar)
45

46
(defcustom calendar-frame-parameters
47 48
  '((name . "Calendar") (title . "Calendar") (height . 10) (width . 80)
    (unsplittable . t) (minibuffer . nil) (vertical-scroll-bars . nil))
Edward M. Reingold's avatar
Edward M. Reingold committed
49
  "Parameters of the calendar frame, if the calendar is in a separate frame.
50
Relevant if `calendar-setup' has the value `calendar-only' or `two-frames'."
51 52 53 54
  :type 'alist
  :options '((name string) (title string) (height integer) (width integer)
             (unsplittable boolean) (minibuffer boolean)
             (vertical-scroll-bars boolean))
55
  :group 'calendar)
Edward M. Reingold's avatar
Edward M. Reingold committed
56

57
(defcustom calendar-and-diary-frame-parameters
58 59
  '((name . "Calendar") (title . "Calendar") (height . 28) (width . 80)
    (minibuffer . nil))
Edward M. Reingold's avatar
Edward M. Reingold committed
60
  "Parameters of the frame that displays both the calendar and the diary.
61
Relevant if `calendar-setup' has the value `one-frame'."
62 63 64 65
  :type 'alist
  :options '((name string) (title string) (height integer) (width integer)
             (unsplittable boolean) (minibuffer boolean)
             (vertical-scroll-bars boolean))
66
  :group 'calendar)
67

68 69
(defcustom calendar-after-frame-setup-hook nil
  "List of functions to be run after creating a calendar and/or diary frame."
70 71 72 73 74 75
  :type 'hook
  :group 'calendar-hooks)

;;; End of user options.

(defvar calendar-frame nil
76
  "Frame in which the calendar was last displayed.")
77 78

(defvar diary-frame nil
79 80 81
  "Frame in which the diary was last displayed.")

(defun calendar-frame-1 (frame)
82 83 84
  "Subroutine used by `calendar-frame-setup'.
Runs `calendar-after-frame-setup-hook', selects frame, iconifies if needed."
  (run-hooks 'calendar-after-frame-setup-hook)
85 86 87
  (select-frame frame)
  (if (eq 'icon (cdr (assoc 'visibility (frame-parameters frame))))
      (iconify-or-deiconify-frame)))
88

89
;; c-d-d is only called after (diary) has been run.
90
(defvar diary-display-function)
91

92
(defun calendar-dedicate-diary ()
93
  "Display and dedicate the window associated with the diary buffer."
94 95
  (set-window-dedicated-p
   (display-buffer
96
    (if (eq diary-display-function 'diary-fancy-display)
97
        (progn
98
          ;; If there are no diary entries, there won't be a buffer
99 100 101 102 103 104
          ;; to dedicate, so make a basic one.
          (or (get-buffer diary-fancy-buffer)
              (calendar-in-read-only-buffer diary-fancy-buffer
                (calendar-set-mode-line "Diary Entries")))
          diary-fancy-buffer)
      (get-file-buffer diary-file)))
105 106
   t))

107
;;;###cal-autoload
108 109 110 111 112 113 114 115 116 117 118 119 120 121
(defun calendar-frame-setup (config &optional prompt)
  "Display the calendar, and optionally the diary, in a separate frame.
CONFIG should be one of:
`calendar-only' - just the calendar, no diary
`one-frame'     - calendar and diary in a single frame
`two-frames'    - calendar and diary each in a separate frame

If CONFIG has any other value, or if the display is not capable of
multiple frames, then `calendar-basic-setup' is called.

If PROMPT is non-nil, prompt for the month and year to use."
  (if (not (and (display-multi-frame-p)
                (memq config '(calendar-only one-frame two-frames))))
      (calendar-basic-setup prompt)
Edward M. Reingold's avatar
Edward M. Reingold committed
122
    (if (frame-live-p calendar-frame) (delete-frame calendar-frame))
123
    (unless (eq config 'calendar-only)
124
      (if (frame-live-p diary-frame) (delete-frame diary-frame)))
125
    (let ((calendar-view-diary-initially-flag (eq config 'one-frame))
Glenn Morris's avatar
Glenn Morris committed
126
          ;; For calendar-dedicate-diary in two-frames case.
127
          (pop-up-windows nil))
Edward M. Reingold's avatar
Edward M. Reingold committed
128
      (save-window-excursion
129 130
        ;; Do diary first so that calendar is always left current.
        (when (eq config 'two-frames)
131
          (calendar-frame-1
132 133 134 135 136 137 138 139 140 141 142 143 144 145
           (setq diary-frame (make-frame diary-frame-parameters)))
          (diary)
          (calendar-dedicate-diary))
        (calendar-frame-1
         (setq calendar-frame
               (make-frame (if (eq config 'one-frame)
                               calendar-and-diary-frame-parameters
                             calendar-frame-parameters))))
        (calendar-basic-setup prompt (not (eq config 'one-frame)))
        (set-window-buffer (selected-window) calendar-buffer)
        (set-window-dedicated-p (selected-window) t)
        (if (eq config 'one-frame)
            (calendar-dedicate-diary))))))

Edward M. Reingold's avatar
Edward M. Reingold committed
146 147 148
(provide 'cal-x)

;;; cal-x.el ends here