use monospace font for comments
[srid.dotfiles.git] / dot-sawfish / lisp / jump-or-exec.jl
blob4178c2b4b95d13b3c0f1747f2fe68004a665977e
1 ;;; jump-or-exec.jl --- flexible application shortcut keys (v0.1)
2 ;; -*- lisp-mode -*-
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)
11 ;; any later version.
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.
23 ;;; Commentary:
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,
27 ;; for example:
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)
37 ;;            (system
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))))
45 ;;; Code:
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
50 ;; sawfish.
51 (defun jump-or-exec (re prog #!optional onfocused)
52   "jump to a window matched by re, or start program otherwise."
53   (catch 'return
54     (let ((wind (get-window-by-name-re re)))
55       (if (functionp onfocused) ; check if already focused
56           (let ((curwin (input-focus)))
57             (if curwin
58                 (if (string-match re (window-name curwin))
59                     (progn
60                       (funcall onfocused wind)
61                       (throw 'return))))))
62       (if (windowp wind)
63           (display-window wind)
64         (if (functionp prog)
65             (funcall prog)
66           (system (concat prog "&")))))))
68 (provide 'jump-or-exec)
69 ;;; jump-or-exec.jl ends here