1 ;;; gnus-win.el --- window configuration functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; 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 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl
))
33 (defgroup gnus-windows nil
34 "Window configuration."
37 (defcustom gnus-use-full-window t
38 "*If non-nil, use the entire Emacs screen."
42 (defvar gnus-window-configuration nil
43 "Obsolete variable. See `gnus-buffer-configuration'.")
45 (defcustom gnus-window-min-width
2
46 "*Minimum width of Gnus buffers."
50 (defcustom gnus-window-min-height
1
51 "*Minimum height of Gnus buffers."
55 (defcustom gnus-always-force-window-configuration nil
56 "*If non-nil, always force the Gnus window configurations."
60 (defvar gnus-buffer-configuration
64 (if gnus-carpal
'(group-carpal 4))))
68 (if gnus-carpal
'(summary-carpal 4))))
72 (eq gnus-picons-display-where
'picons
))
76 (if gnus-carpal
'(summary-carpal 4))
78 (vertical ((height .
5) (width .
15)
80 (left . -
1) (top .
1))
90 (if gnus-carpal
'(summary-carpal 4))
95 (if gnus-carpal
'(server-carpal 2))))
99 (if gnus-carpal
'(browse-carpal 2))))
102 (message 1.0 point
)))
105 (article 1.0 point
)))
115 (article 1.0 point
)))
119 (edit-form 1.0 point
)))
123 (edit-score 1.0 point
)))
130 (message 1.0 point
)))
133 (message 1.0 point
)))
136 (message 1.0 point
)))
140 (message 1.0 point
)))
144 (if gnus-carpal
'(summary-carpal 4))
145 ("*Shell Command Output*" 1.0)))
148 (if gnus-bug-create-help-buffer
'("*Gnus Help Bug*" 0.5))
149 ("*Gnus Bug*" 1.0 point
)))
153 ("*Score Trace*" 1.0)))
157 ("*Score Words*" 1.0)))
161 ("*Split Trace*" 1.0)))
168 (message 1.0 point
))))
169 "Window configuration for all possible Gnus buffers.
170 See the Gnus manual for an explanation of the syntax used.")
172 (defvar gnus-window-to-buffer
173 '((group . gnus-group-buffer
)
174 (summary . gnus-summary-buffer
)
175 (article . gnus-article-buffer
)
176 (server . gnus-server-buffer
)
177 (browse .
"*Gnus Browse Server*")
178 (edit-group . gnus-group-edit-buffer
)
179 (edit-form . gnus-edit-form-buffer
)
180 (edit-server . gnus-server-edit-buffer
)
181 (group-carpal . gnus-carpal-group-buffer
)
182 (summary-carpal . gnus-carpal-summary-buffer
)
183 (server-carpal . gnus-carpal-server-buffer
)
184 (browse-carpal . gnus-carpal-browse-buffer
)
185 (edit-score . gnus-score-edit-buffer
)
186 (message . gnus-message-buffer
)
187 (mail . gnus-message-buffer
)
188 (post-news . gnus-message-buffer
)
189 (faq . gnus-faq-buffer
)
190 (picons . gnus-picons-buffer-name
)
191 (tree . gnus-tree-buffer
)
192 (score-trace .
"*Score Trace*")
193 (split-trace .
"*Split Trace*")
194 (info . gnus-info-buffer
)
195 (category . gnus-category-buffer
)
196 (article-copy . gnus-article-copy
)
197 (draft . gnus-draft-buffer
))
198 "Mapping from short symbols to buffer names or buffer variables.")
200 ;;; Internal variables.
202 (defvar gnus-current-window-configuration nil
203 "The most recently set window configuration.")
205 (defvar gnus-created-frames nil
)
206 (defvar gnus-window-frame-focus nil
)
208 (defun gnus-kill-gnus-frames ()
209 "Kill all frames Gnus has created."
210 (while gnus-created-frames
211 (when (frame-live-p (car gnus-created-frames
))
212 ;; We slap a condition-case around this `delete-frame' to ensure
213 ;; against errors if we try do delete the single frame that's left.
215 (delete-frame (car gnus-created-frames
))))
216 (pop gnus-created-frames
)))
218 (defun gnus-window-configuration-element (list)
220 (not (assq (car list
) gnus-window-configuration
)))
222 (cadr (assq (car list
) gnus-window-configuration
)))
224 (defun gnus-windows-old-to-new (setting)
225 ;; First we take care of the really, really old Gnus 3 actions.
226 (when (symbolp setting
)
228 ;; Take care of ooold GNUS 3.x values.
229 (cond ((eq setting
'SelectArticle
) 'article
)
230 ((memq setting
'(SelectNewsgroup SelectSubject ExpandSubject
))
232 ((memq setting
'(ExitNewsgroup)) 'group
)
234 (if (or (listp setting
)
235 (not (and gnus-window-configuration
236 (memq setting
'(group summary article
)))))
241 (gnus-window-configuration-element
242 '(group newsgroups ExitNewsgroup
)))
243 ((eq setting
'summary
)
244 (gnus-window-configuration-element
245 '(summary SelectNewsgroup SelectSubject ExpandSubject
)))
246 ((eq setting
'article
)
247 (gnus-window-configuration-element
248 '(article SelectArticle
)))))
249 (total (apply '+ elem
))
250 (types '(group summary article
))
251 (pbuf (if (eq setting
'newsgroups
) 'group
'summary
))
255 (or (not (numberp (nth i elem
)))
258 (setq perc
(if (= i
2)
260 (/ (float (nth i elem
)) total
)))
261 (push (if (eq pbuf
(nth i types
))
262 (list (nth i types
) perc
'point
)
263 (list (nth i types
) perc
))
266 `(vertical 1.0 ,@(nreverse out
)))))
269 (defun gnus-add-configuration (conf)
270 "Add the window configuration CONF to `gnus-buffer-configuration'."
271 (setq gnus-buffer-configuration
272 (cons conf
(delq (assq (car conf
) gnus-buffer-configuration
)
273 gnus-buffer-configuration
))))
275 (defvar gnus-frame-list nil
)
277 (defun gnus-window-to-buffer-helper (obj)
278 (cond ((not (symbolp obj
))
287 (defun gnus-configure-frame (split &optional window
)
288 "Split WINDOW according to SPLIT."
289 (let ((current-window
290 (or (get-buffer-window (current-buffer)) (selected-window))))
292 (setq window current-window
))
293 (select-window window
)
294 ;; This might be an old-stylee buffer config.
295 (when (vectorp split
)
296 (setq split
(append split nil
)))
297 (when (or (consp (car split
))
298 (vectorp (car split
)))
300 (push 'vertical split
))
301 ;; The SPLIT might be something that is to be evaled to
302 ;; return a new SPLIT.
303 (while (and (not (assq (car split
) gnus-window-to-buffer
))
304 (gnus-functionp (car split
)))
305 (setq split
(eval split
)))
306 (let* ((type (car split
))
308 (len (if (eq type
'horizontal
) (window-width) (window-height)))
310 (window-min-width (or gnus-window-min-width window-min-width
))
311 (window-min-height (or gnus-window-min-height window-min-height
))
312 s result new-win rest comp-subs size sub
)
314 ;; Nothing to do here.
316 ;; Don't switch buffers.
318 (and (memq 'point split
) window
))
319 ;; This is a buffer to be selected.
320 ((not (memq type
'(frame horizontal vertical
)))
321 (let ((buffer (cond ((stringp type
) type
)
322 (t (cdr (assq type gnus-window-to-buffer
))))))
324 (error "Invalid buffer type: %s" type
))
325 (let ((buf (gnus-get-buffer-create
326 (gnus-window-to-buffer-helper buffer
))))
327 (if (eq buf
(window-buffer (selected-window))) (set-buffer buf
)
328 (switch-to-buffer buf
)))
329 (when (memq 'frame-focus split
)
330 (setq gnus-window-frame-focus window
))
331 ;; We return the window if it has the `point' spec.
332 (and (memq 'point split
) window
)))
333 ;; This is a frame split.
335 (unless gnus-frame-list
336 (setq gnus-frame-list
(list (window-frame current-window
))))
338 params frame fresult
)
339 (while (< i
(length subs
))
340 ;; Frame parameter is gotten from the sub-split.
341 (setq params
(cadr (elt subs i
)))
342 ;; It should be a list.
343 (unless (listp params
)
345 ;; Create a new frame?
346 (unless (setq frame
(elt gnus-frame-list i
))
347 (nconc gnus-frame-list
(list (setq frame
(make-frame params
))))
348 (push frame gnus-created-frames
))
349 ;; Is the old frame still alive?
350 (unless (frame-live-p frame
)
351 (setcar (nthcdr i gnus-frame-list
)
352 (setq frame
(make-frame params
))))
353 ;; Select the frame in question and do more splits there.
355 (setq fresult
(or (gnus-configure-frame (elt subs i
)) fresult
))
357 ;; Select the frame that has the selected buffer.
359 (select-frame (window-frame fresult
)))))
360 ;; This is a normal split.
362 (when (> (length subs
) 0)
363 ;; First we have to compute the sizes of all new windows.
365 (setq sub
(append (pop subs
) nil
))
366 (while (and (not (assq (car sub
) gnus-window-to-buffer
))
367 (gnus-functionp (car sub
)))
368 (setq sub
(eval sub
)))
371 (setq size
(cadar comp-subs
))
372 (cond ((equal size
1.0)
373 (setq rest
(car comp-subs
))
376 (setq s
(floor (* size len
))))
380 (error "Invalid size: %s" size
)))
381 ;; Try to make sure that we are inside the safe limits.
383 ((eq type
'horizontal
)
384 (setq s
(max s window-min-width
)))
386 (setq s
(max s window-min-height
))))
387 (setcar (cdar comp-subs
) s
)
389 ;; Take care of the "1.0" spec.
391 (setcar (cdr rest
) (- len total
))
392 (error "No 1.0 specs in %s" split
))
393 ;; The we do the actual splitting in a nice recursive
395 (setq comp-subs
(nreverse comp-subs
))
397 (if (null (cdr comp-subs
))
398 (setq new-win window
)
400 (split-window window
(cadar comp-subs
)
401 (eq type
'horizontal
))))
402 (setq result
(or (gnus-configure-frame
403 (car comp-subs
) window
)
405 (select-window new-win
)
406 (setq window new-win
)
407 (setq comp-subs
(cdr comp-subs
))))
408 ;; Return the proper window, if any.
410 (select-window result
)))))))
412 (defvar gnus-frame-split-p nil
)
414 (defun gnus-configure-windows (setting &optional force
)
415 (if (window-configuration-p setting
)
416 (set-window-configuration setting
)
417 (setq gnus-current-window-configuration setting
)
418 (setq force
(or force gnus-always-force-window-configuration
))
419 (setq setting
(gnus-windows-old-to-new setting
))
420 (let ((split (if (symbolp setting
)
421 (cadr (assq setting gnus-buffer-configuration
))
425 (setq gnus-frame-split-p nil
)
428 (error "No such setting in `gnus-buffer-configuration': %s" setting
))
430 (if (and (setq all-visible
(gnus-all-windows-visible-p split
))
432 ;; All the windows mentioned are already visible, so we just
433 ;; put point in the assigned buffer, and do not touch the
435 (select-window all-visible
)
437 ;; Make sure "the other" buffer, nntp-server-buffer, is live.
438 (unless (gnus-buffer-live-p nntp-server-buffer
)
439 (nnheader-init-server-buffer))
441 ;; Either remove all windows or just remove all Gnus windows.
442 (let ((frame (selected-frame)))
444 (if gnus-use-full-window
445 ;; We want to remove all other windows.
446 (if (not gnus-frame-split-p
)
447 ;; This is not a `frame' split, so we ignore the
449 (delete-other-windows)
450 ;; This is a `frame' split, so we delete all windows
452 (gnus-delete-windows-in-gnusey-frames))
453 ;; Just remove some windows.
454 (gnus-remove-some-windows)
455 (if (featurep 'xemacs
)
456 (switch-to-buffer nntp-server-buffer
)
457 (set-buffer nntp-server-buffer
)))
458 (select-frame frame
)))
460 (let (gnus-window-frame-focus)
461 (if (featurep 'xemacs
)
462 (switch-to-buffer nntp-server-buffer
)
463 (set-buffer nntp-server-buffer
))
464 (gnus-configure-frame split
)
465 (when gnus-window-frame-focus
466 (select-frame (window-frame gnus-window-frame-focus
))))))))
468 (defun gnus-delete-windows-in-gnusey-frames ()
469 "Do a `delete-other-windows' in all frames that have Gnus windows."
470 (let ((buffers (gnus-buffers)))
473 (unless (eq (cdr (assq 'minibuffer
474 (frame-parameters frame
)))
480 (when (memq (window-buffer window
) buffers
)
481 (setq do-delete t
))))
483 (delete-other-windows)))))
486 (defun gnus-all-windows-visible-p (split)
487 "Say whether all buffers in SPLIT are currently visible.
488 In particular, the value returned will be the window that
490 (let ((stack (list split
))
493 (while (and (setq split
(pop stack
))
495 ;; Be backwards compatible.
496 (when (vectorp split
)
497 (setq split
(append split nil
)))
498 (when (or (consp (car split
))
499 (vectorp (car split
)))
501 (push 'vertical split
))
502 ;; The SPLIT might be something that is to be evaled to
503 ;; return a new SPLIT.
504 (while (and (not (assq (car split
) gnus-window-to-buffer
))
505 (gnus-functionp (car split
)))
506 (setq split
(eval split
)))
508 (setq type
(elt split
0))
513 ((not (memq type
'(horizontal vertical frame
)))
514 (setq buffer
(cond ((stringp type
) type
)
515 (t (cdr (assq type gnus-window-to-buffer
)))))
517 (error "Invalid buffer type: %s" type
))
518 (if (and (setq buf
(get-buffer (gnus-window-to-buffer-helper buffer
)))
519 (setq win
(get-buffer-window buf t
)))
520 (if (memq 'point split
)
521 (setq all-visible win
))
522 (setq all-visible nil
)))
524 (when (eq type
'frame
)
525 (setq gnus-frame-split-p t
))
526 (setq stack
(append (cddr split
) stack
)))))
527 (unless (eq all-visible t
)
530 (defun gnus-window-top-edge (&optional window
)
531 (nth 1 (window-edges window
)))
533 (defun gnus-remove-some-windows ()
534 (let ((buffers (gnus-buffers))
535 buf bufs lowest-buf lowest
)
537 ;; Remove windows on all known Gnus buffers.
538 (while (setq buf
(pop buffers
))
539 (when (get-buffer-window buf
)
542 (when (or (not lowest
)
543 (< (gnus-window-top-edge) lowest
))
544 (setq lowest
(gnus-window-top-edge)
547 (pop-to-buffer lowest-buf
)
548 (if (featurep 'xemacs
)
549 (switch-to-buffer nntp-server-buffer
)
550 (set-buffer nntp-server-buffer
)))
551 (mapcar (lambda (b) (delete-windows-on b t
)) bufs
))))
555 ;;; gnus-win.el ends here