17493
|
1 ;;; gnus-win.el --- window configuration functions for Gnus
|
24357
|
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
|
17493
|
3
|
24357
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
|
17493
|
5 ;; Keywords: news
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
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
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;; Code:
|
|
27
|
19521
|
28 (eval-when-compile (require 'cl))
|
|
29
|
24357
|
30 (eval-when-compile (require 'cl))
|
|
31
|
17493
|
32 (require 'gnus)
|
|
33
|
|
34 (defgroup gnus-windows nil
|
|
35 "Window configuration."
|
|
36 :group 'gnus)
|
|
37
|
|
38 (defcustom gnus-use-full-window t
|
|
39 "*If non-nil, use the entire Emacs screen."
|
|
40 :group 'gnus-windows
|
|
41 :type 'boolean)
|
|
42
|
|
43 (defvar gnus-window-configuration nil
|
|
44 "Obsolete variable. See `gnus-buffer-configuration'.")
|
|
45
|
|
46 (defcustom gnus-window-min-width 2
|
|
47 "*Minimum width of Gnus buffers."
|
|
48 :group 'gnus-windows
|
|
49 :type 'integer)
|
|
50
|
|
51 (defcustom gnus-window-min-height 1
|
|
52 "*Minimum height of Gnus buffers."
|
|
53 :group 'gnus-windows
|
|
54 :type 'integer)
|
|
55
|
|
56 (defcustom gnus-always-force-window-configuration nil
|
|
57 "*If non-nil, always force the Gnus window configurations."
|
|
58 :group 'gnus-windows
|
|
59 :type 'boolean)
|
|
60
|
|
61 (defvar gnus-buffer-configuration
|
|
62 '((group
|
|
63 (vertical 1.0
|
|
64 (group 1.0 point)
|
|
65 (if gnus-carpal '(group-carpal 4))))
|
|
66 (summary
|
|
67 (vertical 1.0
|
|
68 (summary 1.0 point)
|
|
69 (if gnus-carpal '(summary-carpal 4))))
|
|
70 (article
|
|
71 (cond
|
|
72 ((and gnus-use-picons
|
|
73 (eq gnus-picons-display-where 'picons))
|
|
74 '(frame 1.0
|
|
75 (vertical 1.0
|
|
76 (summary 0.25 point)
|
|
77 (if gnus-carpal '(summary-carpal 4))
|
|
78 (article 1.0))
|
|
79 (vertical ((height . 5) (width . 15)
|
|
80 (user-position . t)
|
|
81 (left . -1) (top . 1))
|
|
82 (picons 1.0))))
|
|
83 (gnus-use-trees
|
|
84 '(vertical 1.0
|
|
85 (summary 0.25 point)
|
|
86 (tree 0.25)
|
|
87 (article 1.0)))
|
|
88 (t
|
|
89 '(vertical 1.0
|
|
90 (summary 0.25 point)
|
|
91 (if gnus-carpal '(summary-carpal 4))
|
|
92 (article 1.0)))))
|
|
93 (server
|
|
94 (vertical 1.0
|
|
95 (server 1.0 point)
|
|
96 (if gnus-carpal '(server-carpal 2))))
|
|
97 (browse
|
|
98 (vertical 1.0
|
|
99 (browse 1.0 point)
|
|
100 (if gnus-carpal '(browse-carpal 2))))
|
|
101 (message
|
|
102 (vertical 1.0
|
|
103 (message 1.0 point)))
|
|
104 (pick
|
|
105 (vertical 1.0
|
|
106 (article 1.0 point)))
|
|
107 (info
|
|
108 (vertical 1.0
|
|
109 (info 1.0 point)))
|
|
110 (summary-faq
|
|
111 (vertical 1.0
|
|
112 (summary 0.25)
|
|
113 (faq 1.0 point)))
|
|
114 (edit-article
|
|
115 (vertical 1.0
|
|
116 (article 1.0 point)))
|
|
117 (edit-form
|
|
118 (vertical 1.0
|
|
119 (group 0.5)
|
|
120 (edit-form 1.0 point)))
|
|
121 (edit-score
|
|
122 (vertical 1.0
|
|
123 (summary 0.25)
|
|
124 (edit-score 1.0 point)))
|
|
125 (post
|
|
126 (vertical 1.0
|
|
127 (post 1.0 point)))
|
|
128 (reply
|
|
129 (vertical 1.0
|
|
130 (article-copy 0.5)
|
|
131 (message 1.0 point)))
|
|
132 (forward
|
|
133 (vertical 1.0
|
|
134 (message 1.0 point)))
|
|
135 (reply-yank
|
|
136 (vertical 1.0
|
|
137 (message 1.0 point)))
|
|
138 (mail-bounce
|
|
139 (vertical 1.0
|
|
140 (article 0.5)
|
|
141 (message 1.0 point)))
|
|
142 (pipe
|
|
143 (vertical 1.0
|
|
144 (summary 0.25 point)
|
|
145 (if gnus-carpal '(summary-carpal 4))
|
|
146 ("*Shell Command Output*" 1.0)))
|
|
147 (bug
|
|
148 (vertical 1.0
|
|
149 ("*Gnus Help Bug*" 0.5)
|
|
150 ("*Gnus Bug*" 1.0 point)))
|
|
151 (score-trace
|
|
152 (vertical 1.0
|
|
153 (summary 0.5 point)
|
|
154 ("*Score Trace*" 1.0)))
|
|
155 (score-words
|
|
156 (vertical 1.0
|
|
157 (summary 0.5 point)
|
|
158 ("*Score Words*" 1.0)))
|
24357
|
159 (split-trace
|
|
160 (vertical 1.0
|
|
161 (summary 0.5 point)
|
|
162 ("*Split Trace*" 1.0)))
|
|
163 (category
|
|
164 (vertical 1.0
|
|
165 (category 1.0)))
|
17493
|
166 (compose-bounce
|
|
167 (vertical 1.0
|
|
168 (article 0.5)
|
|
169 (message 1.0 point))))
|
|
170 "Window configuration for all possible Gnus buffers.
|
|
171 See the Gnus manual for an explanation of the syntax used.")
|
|
172
|
|
173 (defvar gnus-window-to-buffer
|
|
174 '((group . gnus-group-buffer)
|
|
175 (summary . gnus-summary-buffer)
|
|
176 (article . gnus-article-buffer)
|
|
177 (server . gnus-server-buffer)
|
|
178 (browse . "*Gnus Browse Server*")
|
|
179 (edit-group . gnus-group-edit-buffer)
|
|
180 (edit-form . gnus-edit-form-buffer)
|
|
181 (edit-server . gnus-server-edit-buffer)
|
|
182 (group-carpal . gnus-carpal-group-buffer)
|
|
183 (summary-carpal . gnus-carpal-summary-buffer)
|
|
184 (server-carpal . gnus-carpal-server-buffer)
|
|
185 (browse-carpal . gnus-carpal-browse-buffer)
|
|
186 (edit-score . gnus-score-edit-buffer)
|
|
187 (message . gnus-message-buffer)
|
|
188 (mail . gnus-message-buffer)
|
|
189 (post-news . gnus-message-buffer)
|
|
190 (faq . gnus-faq-buffer)
|
24357
|
191 (picons . gnus-picons-buffer-name)
|
17493
|
192 (tree . gnus-tree-buffer)
|
19969
|
193 (score-trace . "*Score Trace*")
|
24357
|
194 (split-trace . "*Split Trace*")
|
17493
|
195 (info . gnus-info-buffer)
|
24357
|
196 (category . gnus-category-buffer)
|
17493
|
197 (article-copy . gnus-article-copy)
|
|
198 (draft . gnus-draft-buffer))
|
|
199 "Mapping from short symbols to buffer names or buffer variables.")
|
|
200
|
|
201 ;;; Internal variables.
|
|
202
|
|
203 (defvar gnus-current-window-configuration nil
|
|
204 "The most recently set window configuration.")
|
|
205
|
|
206 (defvar gnus-created-frames nil)
|
24357
|
207 (defvar gnus-window-frame-focus nil)
|
17493
|
208
|
|
209 (defun gnus-kill-gnus-frames ()
|
|
210 "Kill all frames Gnus has created."
|
|
211 (while gnus-created-frames
|
|
212 (when (frame-live-p (car gnus-created-frames))
|
|
213 ;; We slap a condition-case around this `delete-frame' to ensure
|
|
214 ;; against errors if we try do delete the single frame that's left.
|
|
215 (ignore-errors
|
|
216 (delete-frame (car gnus-created-frames))))
|
|
217 (pop gnus-created-frames)))
|
|
218
|
|
219 (defun gnus-window-configuration-element (list)
|
|
220 (while (and list
|
|
221 (not (assq (car list) gnus-window-configuration)))
|
|
222 (pop list))
|
|
223 (cadr (assq (car list) gnus-window-configuration)))
|
|
224
|
|
225 (defun gnus-windows-old-to-new (setting)
|
|
226 ;; First we take care of the really, really old Gnus 3 actions.
|
|
227 (when (symbolp setting)
|
|
228 (setq setting
|
|
229 ;; Take care of ooold GNUS 3.x values.
|
|
230 (cond ((eq setting 'SelectArticle) 'article)
|
|
231 ((memq setting '(SelectNewsgroup SelectSubject ExpandSubject))
|
|
232 'summary)
|
|
233 ((memq setting '(ExitNewsgroup)) 'group)
|
|
234 (t setting))))
|
|
235 (if (or (listp setting)
|
|
236 (not (and gnus-window-configuration
|
|
237 (memq setting '(group summary article)))))
|
|
238 setting
|
|
239 (let* ((elem
|
|
240 (cond
|
|
241 ((eq setting 'group)
|
|
242 (gnus-window-configuration-element
|
|
243 '(group newsgroups ExitNewsgroup)))
|
|
244 ((eq setting 'summary)
|
|
245 (gnus-window-configuration-element
|
|
246 '(summary SelectNewsgroup SelectSubject ExpandSubject)))
|
|
247 ((eq setting 'article)
|
|
248 (gnus-window-configuration-element
|
|
249 '(article SelectArticle)))))
|
|
250 (total (apply '+ elem))
|
|
251 (types '(group summary article))
|
|
252 (pbuf (if (eq setting 'newsgroups) 'group 'summary))
|
|
253 (i 0)
|
|
254 perc out)
|
|
255 (while (< i 3)
|
|
256 (or (not (numberp (nth i elem)))
|
|
257 (zerop (nth i elem))
|
|
258 (progn
|
|
259 (setq perc (if (= i 2)
|
|
260 1.0
|
|
261 (/ (float (nth i elem)) total)))
|
|
262 (push (if (eq pbuf (nth i types))
|
|
263 (list (nth i types) perc 'point)
|
|
264 (list (nth i types) perc))
|
|
265 out)))
|
|
266 (incf i))
|
|
267 `(vertical 1.0 ,@(nreverse out)))))
|
|
268
|
|
269 ;;;###autoload
|
|
270 (defun gnus-add-configuration (conf)
|
|
271 "Add the window configuration CONF to `gnus-buffer-configuration'."
|
|
272 (setq gnus-buffer-configuration
|
|
273 (cons conf (delq (assq (car conf) gnus-buffer-configuration)
|
|
274 gnus-buffer-configuration))))
|
|
275
|
|
276 (defvar gnus-frame-list nil)
|
|
277
|
24357
|
278 (defun gnus-window-to-buffer-helper (obj)
|
|
279 (cond ((not (symbolp obj))
|
|
280 obj)
|
|
281 ((boundp obj)
|
|
282 (symbol-value obj))
|
|
283 ((fboundp obj)
|
|
284 (funcall obj))
|
|
285 (t
|
|
286 nil)))
|
|
287
|
17493
|
288 (defun gnus-configure-frame (split &optional window)
|
|
289 "Split WINDOW according to SPLIT."
|
|
290 (unless window
|
|
291 (setq window (get-buffer-window (current-buffer))))
|
|
292 (select-window window)
|
|
293 ;; This might be an old-stylee buffer config.
|
|
294 (when (vectorp split)
|
|
295 (setq split (append split nil)))
|
|
296 (when (or (consp (car split))
|
|
297 (vectorp (car split)))
|
|
298 (push 1.0 split)
|
|
299 (push 'vertical split))
|
|
300 ;; The SPLIT might be something that is to be evaled to
|
|
301 ;; return a new SPLIT.
|
|
302 (while (and (not (assq (car split) gnus-window-to-buffer))
|
|
303 (gnus-functionp (car split)))
|
|
304 (setq split (eval split)))
|
|
305 (let* ((type (car split))
|
|
306 (subs (cddr split))
|
|
307 (len (if (eq type 'horizontal) (window-width) (window-height)))
|
|
308 (total 0)
|
|
309 (window-min-width (or gnus-window-min-width window-min-width))
|
|
310 (window-min-height (or gnus-window-min-height window-min-height))
|
|
311 s result new-win rest comp-subs size sub)
|
|
312 (cond
|
|
313 ;; Nothing to do here.
|
|
314 ((null split))
|
|
315 ;; Don't switch buffers.
|
|
316 ((null type)
|
|
317 (and (memq 'point split) window))
|
|
318 ;; This is a buffer to be selected.
|
|
319 ((not (memq type '(frame horizontal vertical)))
|
|
320 (let ((buffer (cond ((stringp type) type)
|
24357
|
321 (t (cdr (assq type gnus-window-to-buffer))))))
|
17493
|
322 (unless buffer
|
|
323 (error "Illegal buffer type: %s" type))
|
24357
|
324 (switch-to-buffer (gnus-get-buffer-create
|
|
325 (gnus-window-to-buffer-helper buffer)))
|
|
326 (when (memq 'frame-focus split)
|
|
327 (setq gnus-window-frame-focus window))
|
17493
|
328 ;; We return the window if it has the `point' spec.
|
|
329 (and (memq 'point split) window)))
|
|
330 ;; This is a frame split.
|
|
331 ((eq type 'frame)
|
|
332 (unless gnus-frame-list
|
|
333 (setq gnus-frame-list (list (window-frame
|
|
334 (get-buffer-window (current-buffer))))))
|
|
335 (let ((i 0)
|
|
336 params frame fresult)
|
|
337 (while (< i (length subs))
|
|
338 ;; Frame parameter is gotten from the sub-split.
|
|
339 (setq params (cadr (elt subs i)))
|
|
340 ;; It should be a list.
|
|
341 (unless (listp params)
|
|
342 (setq params nil))
|
|
343 ;; Create a new frame?
|
|
344 (unless (setq frame (elt gnus-frame-list i))
|
|
345 (nconc gnus-frame-list (list (setq frame (make-frame params))))
|
|
346 (push frame gnus-created-frames))
|
|
347 ;; Is the old frame still alive?
|
|
348 (unless (frame-live-p frame)
|
|
349 (setcar (nthcdr i gnus-frame-list)
|
|
350 (setq frame (make-frame params))))
|
|
351 ;; Select the frame in question and do more splits there.
|
|
352 (select-frame frame)
|
|
353 (setq fresult (or (gnus-configure-frame (elt subs i)) fresult))
|
|
354 (incf i))
|
|
355 ;; Select the frame that has the selected buffer.
|
|
356 (when fresult
|
|
357 (select-frame (window-frame fresult)))))
|
|
358 ;; This is a normal split.
|
|
359 (t
|
|
360 (when (> (length subs) 0)
|
|
361 ;; First we have to compute the sizes of all new windows.
|
|
362 (while subs
|
|
363 (setq sub (append (pop subs) nil))
|
|
364 (while (and (not (assq (car sub) gnus-window-to-buffer))
|
|
365 (gnus-functionp (car sub)))
|
|
366 (setq sub (eval sub)))
|
|
367 (when sub
|
|
368 (push sub comp-subs)
|
|
369 (setq size (cadar comp-subs))
|
|
370 (cond ((equal size 1.0)
|
|
371 (setq rest (car comp-subs))
|
|
372 (setq s 0))
|
|
373 ((floatp size)
|
|
374 (setq s (floor (* size len))))
|
|
375 ((integerp size)
|
|
376 (setq s size))
|
|
377 (t
|
|
378 (error "Illegal size: %s" size)))
|
|
379 ;; Try to make sure that we are inside the safe limits.
|
|
380 (cond ((zerop s))
|
|
381 ((eq type 'horizontal)
|
|
382 (setq s (max s window-min-width)))
|
|
383 ((eq type 'vertical)
|
|
384 (setq s (max s window-min-height))))
|
|
385 (setcar (cdar comp-subs) s)
|
|
386 (incf total s)))
|
|
387 ;; Take care of the "1.0" spec.
|
|
388 (if rest
|
|
389 (setcar (cdr rest) (- len total))
|
|
390 (error "No 1.0 specs in %s" split))
|
|
391 ;; The we do the actual splitting in a nice recursive
|
|
392 ;; fashion.
|
|
393 (setq comp-subs (nreverse comp-subs))
|
|
394 (while comp-subs
|
|
395 (if (null (cdr comp-subs))
|
|
396 (setq new-win window)
|
|
397 (setq new-win
|
|
398 (split-window window (cadar comp-subs)
|
|
399 (eq type 'horizontal))))
|
|
400 (setq result (or (gnus-configure-frame
|
|
401 (car comp-subs) window)
|
|
402 result))
|
|
403 (select-window new-win)
|
|
404 (setq window new-win)
|
|
405 (setq comp-subs (cdr comp-subs))))
|
|
406 ;; Return the proper window, if any.
|
|
407 (when result
|
|
408 (select-window result))))))
|
|
409
|
|
410 (defvar gnus-frame-split-p nil)
|
|
411
|
|
412 (defun gnus-configure-windows (setting &optional force)
|
|
413 (setq gnus-current-window-configuration setting)
|
|
414 (setq force (or force gnus-always-force-window-configuration))
|
|
415 (setq setting (gnus-windows-old-to-new setting))
|
|
416 (let ((split (if (symbolp setting)
|
|
417 (cadr (assq setting gnus-buffer-configuration))
|
|
418 setting))
|
|
419 all-visible)
|
|
420
|
|
421 (setq gnus-frame-split-p nil)
|
|
422
|
|
423 (unless split
|
|
424 (error "No such setting: %s" setting))
|
|
425
|
|
426 (if (and (setq all-visible (gnus-all-windows-visible-p split))
|
|
427 (not force))
|
|
428 ;; All the windows mentioned are already visible, so we just
|
|
429 ;; put point in the assigned buffer, and do not touch the
|
|
430 ;; winconf.
|
|
431 (select-window all-visible)
|
|
432
|
|
433 ;; Either remove all windows or just remove all Gnus windows.
|
|
434 (let ((frame (selected-frame)))
|
|
435 (unwind-protect
|
|
436 (if gnus-use-full-window
|
|
437 ;; We want to remove all other windows.
|
|
438 (if (not gnus-frame-split-p)
|
|
439 ;; This is not a `frame' split, so we ignore the
|
|
440 ;; other frames.
|
|
441 (delete-other-windows)
|
|
442 ;; This is a `frame' split, so we delete all windows
|
|
443 ;; on all frames.
|
|
444 (gnus-delete-windows-in-gnusey-frames))
|
|
445 ;; Just remove some windows.
|
|
446 (gnus-remove-some-windows)
|
|
447 (switch-to-buffer nntp-server-buffer))
|
|
448 (select-frame frame)))
|
|
449
|
|
450 (switch-to-buffer nntp-server-buffer)
|
24357
|
451 (let (gnus-window-frame-focus)
|
|
452 (gnus-configure-frame split (get-buffer-window (current-buffer)))
|
|
453 (when gnus-window-frame-focus
|
|
454 (select-frame (window-frame gnus-window-frame-focus)))))))
|
17493
|
455
|
|
456 (defun gnus-delete-windows-in-gnusey-frames ()
|
|
457 "Do a `delete-other-windows' in all frames that have Gnus windows."
|
24357
|
458 (let ((buffers (gnus-buffers)))
|
17493
|
459 (mapcar
|
|
460 (lambda (frame)
|
|
461 (unless (eq (cdr (assq 'minibuffer
|
|
462 (frame-parameters frame)))
|
|
463 'only)
|
|
464 (select-frame frame)
|
|
465 (let (do-delete)
|
|
466 (walk-windows
|
|
467 (lambda (window)
|
|
468 (when (memq (window-buffer window) buffers)
|
|
469 (setq do-delete t))))
|
|
470 (when do-delete
|
|
471 (delete-other-windows)))))
|
|
472 (frame-list))))
|
|
473
|
|
474 (defun gnus-all-windows-visible-p (split)
|
|
475 "Say whether all buffers in SPLIT are currently visible.
|
|
476 In particular, the value returned will be the window that
|
|
477 should have point."
|
|
478 (let ((stack (list split))
|
|
479 (all-visible t)
|
|
480 type buffer win buf)
|
|
481 (while (and (setq split (pop stack))
|
|
482 all-visible)
|
|
483 ;; Be backwards compatible.
|
|
484 (when (vectorp split)
|
|
485 (setq split (append split nil)))
|
|
486 (when (or (consp (car split))
|
|
487 (vectorp (car split)))
|
|
488 (push 1.0 split)
|
|
489 (push 'vertical split))
|
|
490 ;; The SPLIT might be something that is to be evaled to
|
|
491 ;; return a new SPLIT.
|
|
492 (while (and (not (assq (car split) gnus-window-to-buffer))
|
|
493 (gnus-functionp (car split)))
|
|
494 (setq split (eval split)))
|
|
495
|
|
496 (setq type (elt split 0))
|
|
497 (cond
|
|
498 ;; Nothing here.
|
|
499 ((null split) t)
|
|
500 ;; A buffer.
|
|
501 ((not (memq type '(horizontal vertical frame)))
|
|
502 (setq buffer (cond ((stringp type) type)
|
|
503 (t (cdr (assq type gnus-window-to-buffer)))))
|
|
504 (unless buffer
|
|
505 (error "Illegal buffer type: %s" type))
|
24357
|
506 (if (and (setq buf (get-buffer (gnus-window-to-buffer-helper buffer)))
|
|
507 (setq win (get-buffer-window buf t)))
|
|
508 (if (memq 'point split)
|
17493
|
509 (setq all-visible win))
|
|
510 (setq all-visible nil)))
|
|
511 (t
|
|
512 (when (eq type 'frame)
|
|
513 (setq gnus-frame-split-p t))
|
|
514 (setq stack (append (cddr split) stack)))))
|
|
515 (unless (eq all-visible t)
|
|
516 all-visible)))
|
|
517
|
|
518 (defun gnus-window-top-edge (&optional window)
|
|
519 (nth 1 (window-edges window)))
|
|
520
|
|
521 (defun gnus-remove-some-windows ()
|
24357
|
522 (let ((buffers (gnus-buffers))
|
17493
|
523 buf bufs lowest-buf lowest)
|
|
524 (save-excursion
|
|
525 ;; Remove windows on all known Gnus buffers.
|
24357
|
526 (while (setq buf (pop buffers))
|
|
527 (when (get-buffer-window buf)
|
|
528 (push buf bufs)
|
|
529 (pop-to-buffer buf)
|
|
530 (when (or (not lowest)
|
|
531 (< (gnus-window-top-edge) lowest))
|
|
532 (setq lowest (gnus-window-top-edge)
|
|
533 lowest-buf buf))))
|
17493
|
534 (when lowest-buf
|
|
535 (pop-to-buffer lowest-buf)
|
|
536 (switch-to-buffer nntp-server-buffer))
|
24357
|
537 (mapcar (lambda (b) (delete-windows-on b t)) bufs))))
|
17493
|
538
|
|
539 (provide 'gnus-win)
|
|
540
|
|
541 ;;; gnus-win.el ends here
|