viper -- Update and prettify package-info.in provides.
[packages] / xemacs-packages / ecb / ecb-winman-support.el
1 ;; ecb-winman-support.el - support of several window managers
2
3 ;; Copyright (C) 2000 - 2003 Klaus Berndl,
4 ;;                           Free Software Foundation, Inc.
5
6 ;; Author: Klaus Berndl <klaus.berndl@sdm.de>
7 ;; Maintainer: Klaus Berndl <klaus.berndl@sdm.de>
8 ;; Keywords: browser, code, programming, tools, escreen, winring
9 ;; Created: 2003
10
11 ;; This program is free software; you can redistribute it and/or modify it under
12 ;; the terms of the GNU General Public License as published by the Free Software
13 ;; Foundation; either version 2, or (at your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but WITHOUT
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 ;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18 ;; details.
19
20 ;; You should have received a copy of the GNU General Public License along with
21 ;; GNU Emacs; see the file COPYING.  If not, write to the Free Software
22 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 ;; $Id: ecb-winman-support.el,v 1.10 2004-12-10 16:34:16 berndl Exp $
25
26 ;;; Commentary
27 ;;
28 ;; This library contains support for several window-managers so they interact
29 ;; well with ECB. Currently the following window-managers are supported by ECB:
30 ;; - winring.el: Written by Barry A. Warsaw <bwarsaw@python.org>, get it from
31 ;;   http://www.python.org/emacs/
32 ;; - escreen.el: Written by Noah Friedman <friedman@splode.com>, get it from
33 ;;   http://www.splode.com/~friedman/software/emacs-lisp/
34 ;;
35 ;; Note: With one of these window-managers installed and active you can run
36 ;; applications like Gnus, VM or BBDB in the same frame as ECB! Just use
37 ;; different window-configurations (winring.el) or escreens (escreen.el) for
38 ;; ECB and the other applications. Especially with winring.el you can give
39 ;; every configuration a descriptive name like "ECB" or "Gnus" ; afterwards
40 ;; you can jump to a window-configuration by name!
41
42
43 ;;; Installation and enabling
44 ;;
45 ;; This library is installed autom. with ECB. But every support must be
46 ;; enabled explicitly:
47 ;; - winring: Call `ecb-winman-winring-enable-support'. This *must* be done
48 ;;   *before* the first call to any winring-command, so also before calling
49 ;;   `winring-initialize'!
50 ;; - escreen: Call `ecb-winman-escreen-enable-support'. This *must* be done
51 ;;   *before* the first call to any escreen-command, so also before calling
52 ;;   `escreen-install'!
53 ;;
54 ;; You can also put into your .emacs:
55 ;; (ecb-winman-winring-enable-support) or/and
56 ;; (ecb-winman-escreen-enable-support)
57
58 ;;; Deinstallation
59 ;;
60 ;; Just run `ecb-winman-escreen-disable-support' rsp.
61 ;; `ecb-winman-winring-disable-support'.
62
63
64 ;;; Usage
65 ;;
66 ;; After enabling the support of one of the supported window-managers just go
67 ;; on as described in the commentary or introduction of the respective
68 ;; library-file(s) of the window-manager. Here is a short description:
69
70 ;; - winring: Run `winring-initialize'. If ECB is active then the resulting
71 ;;   window-configuration is the ECB-window-configuration. Otherwise you can
72 ;;   create the ECB-window-configuration when you first time call
73 ;;   `winring-new-configuration' with name equal to `ecb-winman-winring-name'.
74 ;;   In general you can run all commands of the winring-library. If you jump
75 ;;   to the ECB-window-configuration then ECB will be autom. activated and if
76 ;;   you leave the ECB-window-configuration then ECB will autom. deactivated.
77
78 ;; - escreen: Run `escreen-install' (deactivates ECB if currently
79 ;;   running), `escreen-create-screen', `escreen-goto-screen' etc. The latter
80 ;;   ones activate autom. ECB if creating or selecting the escreen with number
81 ;;   `ecb-escreen-number' (default = 1) and deactivate ECB autom. if leaving
82 ;;   the ECB-escreen.
83
84
85 ;;; BUGS
86 ;;
87 ;; Currently not known
88
89
90 ;; Thanks to Johann "Myrkraverk" Oskarsson <myrkraverk@users.sourceforge.net>
91 ;; for the first trigger for this support-library. He has suggested to
92 ;; integrate ECB with escreen.
93
94
95 ;;; Code
96
97 (eval-when-compile
98   (require 'silentcomp))
99
100 (require 'ecb-util)
101
102 (silentcomp-defvar escreen-current-screen-number)
103
104
105 (defgroup ecb-winman-support nil
106   "Settings for supporting several window-managers.
107 Currently winring and escreen are supported."
108   :group 'ecb
109   :prefix "ecb-winman-")
110
111 (defcustom ecb-winman-escreen-number 1
112   "*Number of the escreen which is reserved for ECB.
113 If you go to the escreen with this number you go always to the escreen with
114 activated ECB. All other escreen-numbers are escreens with deactivated ECB!"
115   :group 'ecb-winman-support
116   :group 'ecb-most-important
117   :type 'integer)
118
119 (defcustom ecb-winman-winring-name "ECB"
120   "*Name of the winring-window-configuration reserved for ECB.
121 If you go to the window-configuration with this name you go always to the
122 window-configuration with activated ECB. All other window-configuration are
123 configurations with deactivated ECB!"
124   :group 'ecb-winman-support
125   :group 'ecb-most-important
126   :type 'string)
127
128 ;; support for the library escreen.el ----------------------------------------
129
130 (defconst ecb-winman-escreen-adviced-functions
131   '((escreen-save-current-screen-configuration . before))
132   "These functions of escreen are adviced if escreen is active during ECB is
133 active. Each element of the list is a cons-cell where the car is the
134 function-symbol and the cdr the advice-class \(before, around or after). If a
135 function should be adviced with more than one class \(e.g. with a before and
136 an after-advice) then for every class a cons must be added to this list.")
137
138
139 (defun ecb-winman-escreen-enable-support ()
140   "Load the escreen-library and enable the ECB-support for it.
141 This does not install or activate escreen! For this you have still to call
142 `escreen-install'! For further documentation about escreen see the file
143 escreen.el!"
144   (interactive)
145   (if (locate-library "escreen")
146       (condition-case nil
147           (progn
148             (require 'escreen)
149             (ecb-enable-advices ecb-winman-escreen-adviced-functions)
150             (add-hook 'escreen-goto-screen-hook
151                       'ecb-winman-escreen-goto-escreen-hook)
152             (ecb-info-message "Support for escreen enabled."))
153         (error
154          (ecb-winman-escreen-disable-support)
155          (ecb-error "The escreen-support can not be properly installed!")))
156     (ecb-error "The library escreen.el can not be found!")))
157
158
159 (defun ecb-winman-escreen-disable-support ()
160   "Disable the escreen-support of ECB."
161   (interactive)
162   (ecb-disable-advices ecb-winman-escreen-adviced-functions)
163   (when (featurep 'escreen)
164     (remove-hook 'escreen-goto-screen-hook
165                  'ecb-winman-escreen-goto-escreen-hook)))
166     
167
168 (defun ecb-winman-escreen-goto-escreen-hook ()
169   "Activate ECB if we go to the escreen with number `ecb-escreen-number'."
170   (if (and (boundp 'ecb-minor-mode)
171            (not ecb-minor-mode)
172            (= escreen-current-screen-number
173               ecb-winman-escreen-number))
174       (let ((ecb-split-edit-window-after-start 'before-deactivation))
175         (ecb-activate))))
176
177 (defadvice escreen-save-current-screen-configuration (before ecb)
178   "escreen can only handle screen-configurations if ECB is deactivated. This
179 is because ECB handles its window-creation completely by itself and because it
180 uses dedicated windows. So we deactivate ECB before running this function."
181   (if (and (boundp 'ecb-minor-mode)
182            ecb-minor-mode
183            (equal ecb-frame (selected-frame)))
184       (let ((ecb-split-edit-window-after-start 'before-deactivation))
185         (ecb-deactivate))))
186
187 ;; support for the library winring.el ---------------------------------------
188
189 (defconst ecb-winman-winring-adviced-functions
190   '((winring-save-current-configuration . before)
191     (winring-initialize . after)
192     (winring-duplicate-configuration . before)
193     (winring-restore-configuration . before)
194     (winring-set-name . after))
195      "These functions of winring are adviced if winring is active during ECB is
196 active. Each element of the list is a cons-cell where the car is the
197 function-symbol and the cdr the advice-class \(before, around or after). If a
198 function should be adviced with more than one class \(e.g. with a before and
199 an after-advice) then for every class a cons must be added to this list.")
200
201 (defun ecb-winman-winring-enable-support ()
202   "Load the winring-library and enable the ECB-support for it.
203 This does not install or activate winring! For this you have still to call
204 `winring-initialize'! For further documentation about winring see the file
205 winring.el!"
206   (interactive)
207   (if (locate-library "winring")
208       (condition-case nil
209           (progn
210             (require 'winring)
211             (ecb-enable-advices ecb-winman-winring-adviced-functions)
212             (ecb-info-message "Support for winring enabled."))
213         (error
214          (ecb-winman-winring-disable-support)
215          (ecb-error "The winring-support can not be properly installed!")))
216     (ecb-error "The library winring.el can not be found!")))
217
218 (defun ecb-winman-winring-disable-support ()
219   "Disable the winring-support of ECB."
220   (interactive)
221   (ecb-disable-advices ecb-winman-winring-adviced-functions))
222
223
224 (defvar ecb-winman-winring-ecb-frame nil
225   "Frame for which the ECB-window-configuration was set first time.")
226
227 (defadvice winring-set-name (after ecb)
228   "Store frame if name is equal with `ecb-winman-winring-name' and activate
229 ECB if we set the name `ecb-winman-winring-name'."
230   ;; Because this is an after advice of winring-name-of-current returns here
231   ;; already the new name!
232   (when (ecb-string= (winring-name-of-current) ecb-winman-winring-name)
233     ;; we do this only the first time
234     (when (null ecb-winman-winring-ecb-frame)
235       (setq ecb-winman-winring-ecb-frame
236             (or (ad-get-arg 1) (selected-frame))))
237     ;; now we activate ECB if necessary
238     (when (and (boundp 'ecb-minor-mode)
239                (not ecb-minor-mode)
240                (equal (or (ad-get-arg 1)
241                           (selected-frame)) ecb-winman-winring-ecb-frame))
242       (let ((ecb-split-edit-window-after-start 'before-deactivation))
243         (ecb-activate)))))
244
245 (defadvice winring-duplicate-configuration (before ecb)
246   "Prevent the ECB-window-configuration from being duplicated."
247   (if (ecb-string= (winring-name-of-current) ecb-winman-winring-name)
248       (ecb-error "The ECB-window-configuration can not be duplicated!")))
249
250 (defadvice winring-restore-configuration (before ecb)
251   "Deactivates ECB if the ECB-window-configuration is active."
252   (if (and (ecb-string= (winring-name-of-current) ecb-winman-winring-name)
253            (boundp 'ecb-minor-mode)
254            ecb-minor-mode)
255       (let ((ecb-split-edit-window-after-start 'before-deactivation))
256         (ecb-deactivate))))
257   
258
259 (defadvice winring-save-current-configuration (before ecb)
260   "winring can only handle window-configurations if ECB is deactivated. This
261 is because ECB handles its window-creation completely by itself and because it
262 uses dedicated windows. So we deactivate ECB before running this function."
263   (if (and (boundp 'ecb-minor-mode)
264            ecb-minor-mode
265            (equal ecb-frame (selected-frame)))
266       (let ((ecb-split-edit-window-after-start 'before-deactivation))
267         (ecb-deactivate))))
268
269   
270 (defadvice winring-initialize (after ecb)
271   "If ECB is active when winring is initialized then this initial
272 window-configuration gets always the name `ecb-winman-winring-name'."
273   (if (and (boundp 'ecb-minor-mode)
274            ecb-minor-mode
275            (equal ecb-frame (selected-frame)))
276       (winring-set-name ecb-winman-winring-name)))
277
278
279 ;; not supported window-managing functions------------------------------------
280
281 (defconst ecb-winman-not-supported-function-advices
282   (if ecb-running-xemacs
283       '((winner-mode . before)
284         (winner-redo . before)
285         (winner-undo . before)
286         (push-window-configuration . before)
287         (pop-window-configuration . before)
288         (unpop-window-configuration . before))
289     '((winner-mode . before)
290       (winner-redo . before)
291       (winner-undo . before))))
292
293 (defadvice winner-mode (before ecb)
294   "Prevents `winner-mode' from being activated for the ECB-frame."
295   (if (equal (selected-frame) ecb-frame)
296       (ecb-error "Can't use winner-mode functions in the ecb-frame.")))
297
298 (defadvice winner-redo (before ecb)
299   "Prevents `winner-redo' from being used within the ECB-frame."
300   (if (equal (selected-frame) ecb-frame)
301       (ecb-error "Can't use winner-mode functions in the ecb-frame.")))
302
303 (defadvice winner-undo (before ecb)
304   "Prevents `winner-undo' from being used within the ECB-frame."
305   (if (equal (selected-frame) ecb-frame)
306       (ecb-error "Can't use winner-mode functions in the ecb-frame.")))
307
308 (when ecb-running-xemacs
309   (defadvice push-window-configuration (before ecb)
310     (if (and (equal (selected-frame) ecb-frame)
311              (interactive-p))
312         (ecb-error "Can't use interactive push-window-configuration in the ecb-frame.")))
313
314   (defadvice pop-window-configuration (before ecb)
315     (if (and (equal (selected-frame) ecb-frame)
316              (interactive-p))
317         (ecb-error "Can't use interactive pop-window-configuration in the ecb-frame.")))
318   
319   (defadvice unpop-window-configuration (before ecb)
320     (if (and (equal (selected-frame) ecb-frame)
321              (interactive-p))
322         (ecb-error "Can't use interactive unpop-window-configuration in the ecb-frame.")))
323   )
324
325 ;; we disable all advices per default.
326
327 (ecb-disable-advices ecb-winman-winring-adviced-functions)
328 (ecb-disable-advices ecb-winman-escreen-adviced-functions)
329 (ecb-disable-advices ecb-winman-not-supported-function-advices)
330
331 (silentcomp-provide 'ecb-winman-support)
332
333 ;;; ecb-winman-support.el ends here