1 ;;; jump-or-exec.jl --- flexible application shortcut keys (v0.1)
4 ;; Copyright (C) 2002 Free Software Foundation, Inc.
6 ;; Author: Damien Elmes <resolve@repose.cx>
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
25 ;; To use this file, put (require 'jump-or-exec) somewhere in your local config
26 ;; files (like ~/.sawfishrc), and then define shortcuts using it like this one,
29 ;; ;; load a multi gnome terminal,
30 ;; ;; or switch to it if it's already running,
31 ;; ;; and load a new tab if it's currently focused
33 ;; (bind-keys global-keymap
34 ;; "W-o" `(jump-or-exec "MGT" ; window title to jump to
35 ;; ,(lambda () ; if the window doesn't exist
36 ;; (select-workspace 0)
38 ;; "multi-gnome-terminal --start-factory-server --use-factory &"))
39 ;; ,(lambda (wind) ; if the window is focused already
40 ;; (display-window wind)
41 ;; (synthesize-event "C-F1" wind)
42 ;; (synthesize-event "n" wind))))
47 ;; this function is used a bit further in, in my local config. i use it to blur
48 ;; the line between what's running and what needs to be started, so i can hit a
49 ;; key to load something, or jump to it if it was already running. i love
51 (defun jump-or-exec (re prog #!optional onfocused)
52 "jump to a window matched by re, or start program otherwise."
54 (let ((wind (get-window-by-name-re re)))
55 (if (functionp onfocused) ; check if already focused
56 (let ((curwin (input-focus)))
58 (if (string-match re (window-name curwin))
60 (funcall onfocused wind)
66 (system (concat prog "&")))))))
68 (provide 'jump-or-exec)
69 ;;; jump-or-exec.jl ends here