1 ;;; xwem-clswi.el --- Simple clients switching.
3 ;; Copyright (C) 2003-2005 by XWEM Org.
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Steve Youngs <steve@youngs.au.com>
8 ;; X-CVS: $Id: xwem-clswi.el,v 1.8 2005-04-04 19:54:10 lg Exp $
10 ;; This file is NOT part of XEmacs.
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)
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.
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
27 ;;; Synched up with: Not in FSF
31 ;; Included as default bindings, `H-[', `H-]', `H-{', `H-}'.
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
40 (require 'xwem-clients)
42 (defgroup xwem-clswi nil
43 "Group to customize clients switcher."
47 (defcustom xwem-clswi-beep-on-error t
48 "*Non-nil mean beep on any error."
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))
59 ;;; Internal variables
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))
68 (error 'xwem-error "No client to switch"))
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))
74 (xwem-win-set-cl window scl)
75 (if (xwem-win-selected-p window)
76 (xwem-select-client scl)
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
87 (eq (xwem-cl-manage-type ccl) mtype))
90 (setq ncls (nreverse ncls))
94 (setq cl (xwem-cl-other cl :clients ncls))
97 (unless (xwem-cl-p cl)
98 (error 'xwem-error (format "No other %s client"
99 (upcase (symbol-name mtype)))))
101 (xwem-select-client cl)
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)))
111 (let ((window (xwem-cl-win cl)))
113 (xwem-clswi-windowing window arg)
114 (xwem-clswi-non-windowing cl arg)))
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))))
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)))
129 (xwem-clswi-next cl (- arg)))
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")
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))))
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)))
148 (provide 'xwem-clswi)
150 ;;; xwem-clswi.el ends here