cal-x.el 7.1 KB

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