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