Initial Commit
[packages] / xemacs-packages / xwem / lisp / xwem-clswi.el
1 ;;; xwem-clswi.el --- Simple clients switching.
2
3 ;; Copyright (C) 2003-2005 by XWEM Org.
4
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;;         Steve Youngs  <steve@youngs.au.com>
7 ;; Keywords: xwem
8 ;; X-CVS: $Id: xwem-clswi.el,v 1.8 2005-04-04 19:54:10 lg Exp $
9
10 ;; This file is NOT part of XEmacs.
11
12 ;; XWEM is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
20 ;; License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA.
26
27 ;;; Synched up with: Not in FSF
28
29 ;;; Commentary:
30
31 ;; Included as default bindings, `H-[', `H-]', `H-{', `H-}'.
32
33 ;; If current client supports windowing, than next/prev client in its
34 ;; window is selected.  If client does not support windowing (for
35 ;; example fullscreen client) next/prev client of same manage type is
36 ;; selected.
37
38 ;;; Code:
39 \f
40 (require 'xwem-clients)
41
42 (defgroup xwem-clswi nil
43   "Group to customize clients switcher."
44   :prefix "xwem-clswi-"
45   :group 'xwem)
46
47 (defcustom xwem-clswi-beep-on-error t
48   "*Non-nil mean beep on any error."
49   :type 'boolean
50   :group 'xwem-clswi)
51
52 (defcustom xwem-clswi-show-info nil
53   "*Non-nil mean show info about client in xwem minibuffer after switch.
54 It also can be a function which accepts one argument - client and
55 return non-nil to show info."
56   :type '(restricted-sexp :match-alternatives (functionp boolean-p))
57   :group 'xwem-clswi)
58
59 ;;; Internal variables
60
61 (defun xwem-clswi-windowing (window arg)
62   "Switch to ARG's next client in window.
63 Return client that was activated."
64   (let ((ccl (xwem-win-cl window))
65         (cls (xwem-win-clients window))
66         cclinx num scl)
67     (unless cls
68       (error 'xwem-error "No client to switch"))
69
70     (setq cclinx (- (length cls) (length (memq ccl cls))))
71     (setq num (% (+ cclinx arg) (length cls)))
72     (setq scl (nth (if (natnump num) num (+ (length cls) num)) cls))
73
74     (xwem-win-set-cl window scl)
75     (if (xwem-win-selected-p window)
76         (xwem-select-client scl)
77       (xwem-activate scl))
78     scl))
79
80 (defun xwem-clswi-non-windowing (cl arg)
81   "Switch to ARG's other client of same client type as CL.
82 Return client that was activated."
83   (let* ((mtype (xwem-cl-manage-type cl))
84          (ncls (xwem-cl-list-sort-by-recency
85                 (xwem-clients-list
86                  #'(lambda (ccl)
87                      (eq (xwem-cl-manage-type ccl) mtype))
88                  t))))
89     (when (< arg 0)
90       (setq ncls (nreverse ncls))
91       (setq arg (- arg)))
92
93     (while (> arg 0)
94       (setq cl (xwem-cl-other cl :clients ncls))
95       (decf arg))
96
97     (unless (xwem-cl-p cl)
98       (error 'xwem-error (format "No other %s client"
99                                  (upcase (symbol-name mtype)))))
100
101     (xwem-select-client cl)
102     cl))
103   
104 ;;;###autoload(autoload 'xwem-clswi-next "xwem-clswi" nil t)
105 (define-xwem-command xwem-clswi-next (cl &optional arg)
106   "According to CL, switch to ARG's next client.
107 If WIN is ommited then in selected window."
108   (xwem-interactive (list (xwem-cl-selected)
109                           (prefix-numeric-value xwem-prefix-arg)))
110
111   (let ((window (xwem-cl-win cl)))
112     (setq cl (if window
113                  (xwem-clswi-windowing window arg)
114                (xwem-clswi-non-windowing cl arg)))
115
116     (when (or (and (functionp xwem-clswi-show-info)
117                    (funcall xwem-clswi-show-info cl))
118               (and xwem-clswi-show-info
119                    (not (functionp xwem-clswi-show-info))))
120       (xwem-client-info cl))))
121
122 ;;;###autoload(autoload 'xwem-clswi-prev "xwem-clswi" nil t)
123 (define-xwem-command xwem-clswi-prev (cl &optional arg)
124   "According to CL, switch to ARG's previous client.
125 If WIN is ommited then in selected window."
126   (xwem-interactive (list (xwem-cl-selected)
127                           (prefix-numeric-value xwem-prefix-arg)))
128
129   (xwem-clswi-next cl (- arg)))
130
131 ;;;###autoload(autoload 'xwem-clswi-next-other-window "xwem-clswi" nil t)
132 (define-xwem-command xwem-clswi-next-other-window (arg)
133   "Switch next ARG client in other window."
134   (xwem-interactive "p")
135
136   (let ((win (xwem-window-other 1 (xwem-win-selected))))
137     (when (and (xwem-win-p win)
138                (not (eq win (xwem-win-selected))))
139       (xwem-clswi-next (xwem-win-cl win) arg))))
140
141 ;;;###autoload(autoload 'xwem-clswi-prev-other-window "xwem-clswi" nil t)
142 (define-xwem-command xwem-clswi-prev-other-window (arg)
143   "Switch previous ARG client in other window."
144   (xwem-interactive "p")
145   (xwem-clswi-next-other-window (- arg)))
146
147 \f
148 (provide 'xwem-clswi)
149
150 ;;; xwem-clswi.el ends here