jcs ratpoison hax
1;;; ratpoison.el --- ratpoison support for Emacs
2;;
3;; Copyright (C) 2003 Gergely Nagy, Shawn Betts, Jay Belanger
4;;
5;; Authors: Gergely Nagy <algernon@debian.org>,
6;; Shawn Betts <sabetts@users.sourceforge.net>,
7;; Jay Belanger <belanger@truman.edu>,
8;; Maintainer: Gergely Nagy <algernon@debian.org>
9;; Version: 0.2
10;; Keywords: faces, ratpoison, X
11
12;; This file is NOT part of GNU Emacs.
13
14;; This program is free software; you can redistribute it and/or
15;; modify it under the terms of the GNU General Public License as
16;; published by the Free Software Foundation; either version 2 of
17;; the License, or (at your option) any later version.
18;;
19;; This program is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details.
23;;
24;; You should have received a copy of the GNU General Public
25;; License along with this program; if not, write to the Free
26;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27;; MA 02111-1307 USA
28
29;;; Commentary:
30;;
31;; This file provides a major mode for editing .ratpoisonrc files, and
32;; functions to access ratpoison from within Emacs.
33
34;;; History:
35;; Version 0.2:
36;; - Added command-interpreter (from Shawn and Jay)
37;; - Added info-lookup functions (from Jay)
38;; - renamed to ratpoison.el
39;; - far better font-locking
40;; Version 0.1:
41;; - initial version
42
43;;; Todo:
44;; - auto-completion of commands
45;; - probably a bunch of other things
46
47(require 'font-lock)
48(require 'generic-x)
49
50(defvar ratpoison-commands-0
51 (list
52 "abort"
53 "banish"
54 "clock"
55 "curframe"
56 "delete"
57 "focus"
58 "focusup"
59 "focusdown"
60 "focusleft"
61 "focusright"
62 "meta"
63 "help"
64 "info"
65 "kill"
66 "lastmsg"
67 "redisplay"
68 "restart"
69 "next"
70 "only"
71 "other"
72 "prev"
73 "quit"
74 "remove"
75 "split"
76 "hsplit"
77 "version"
78 "vsplit"
79 ))
80
81(defvar ratpoison-commands-rest
82 (list
83 "bind"
84 "chdir"
85 "colon"
86 "defbarloc"
87 "msgwait"
88 "defborder"
89 "deffont"
90 "definputwidth"
91 "defmaxsizepos"
92 "defpadding"
93 "deftranspos"
94 "defwaitcursor"
95 "defwinfmt"
96 "defwinname"
97 "defwinpos"
98 "deffgcolor"
99 "defbgcolor"
100 "escape"
101 "echo"
102 "exec"
103 "newwm"
104 "number"
105 "pos"
106 "rudeness"
107 "select"
108 "setenv"
109 "source"
110 "startup_message"
111 "title"
112 "unbind"
113 "unsetenv"
114 "windows"
115 ))
116
117;; ratpoisonrc-mode
118(define-generic-mode 'ratpoisonrc-mode
119 ;; comments
120 (list ?#)
121 ;; keywords
122 nil
123 ;; font-lock stuff
124 (list
125 ;; commands without arguments
126 (generic-make-keywords-list
127 ratpoison-commands-0 font-lock-builtin-face "^[ \t]*")
128 ;; commands with arguments
129 (generic-make-keywords-list
130 ratpoison-commands-rest font-lock-builtin-face "^[ \t]*" "[ \t]+")
131 ;; exec <arg>
132 (list "^[ \t]*\\(exec\\)[ \t]+\\(.*\\)"
133 '(1 'font-lock-builtin-face)
134 '(2 'font-lock-string-face))
135 ;; arguments, the first is a keyword, the rest is tring
136 (list (concat
137 (car (generic-make-keywords-list
138 ratpoison-commands-rest font-lock-builtin-face "^[ \t]*" "[ \t]+"))
139 "\\([0-9a-zA-Z\\/\\.\\-]+\\)[ \t]*\\(.*\\)")
140 '(2 'font-lock-keyword-face)
141 '(3 'font-lock-string-face)))
142 ;; auto-mode alist
143 (list "\\.ratpoisonrc\\'")
144 ;; additional setup functions
145 (list 'ratpoisonrc-mode-setup)
146 "Generic mode for ratpoison configuration files.")
147
148(defun ratpoisonrc-mode-setup()
149 (defvar ratpoisonrc-mode-keymap (make-sparse-keymap)
150 "Keymap for ratpoisonrc-mode")
151 (define-key ratpoisonrc-mode-keymap "\C-c\C-e" 'ratpoison-line)
152 (use-local-map ratpoisonrc-mode-keymap))
153
154(provide 'ratpoisonrc-mode)
155
156;; Ratpoison access
157; Groups & Variables
158(defgroup ratpoison nil "Ratpoison access"
159 :group 'languages
160 :prefix "ratpoison-")
161
162(defcustom ratpoison-program "ratpoison"
163 "The command to call the window manager."
164 :group 'ratpoison
165 :type 'string)
166
167; Command stuff
168(defun ratpoison-command (command)
169 (interactive "sRP Command: ")
170 (call-process ratpoison-program nil nil nil "-c" command))
171
172(defun ratpoison-command-on-region (start end)
173 (interactive "r")
174 (mapcar 'ratpoison-command
175 (split-string (buffer-substring start end)
176 "\n")))
177
178(defun ratpoison-line ()
179 "Send the current line to ratpoison."
180 (interactive)
181 (ratpoison-command
182 (buffer-substring-no-properties
183 (line-beginning-position)
184 (line-end-position))))
185
186;; Documentation
187(defun ratpoison-manual ()
188 "Call up the ratpoison info page."
189 (interactive)
190 (info "ratpoison"))
191
192(defun ratpoison-manual-commands ()
193 "Call up the info page listing the ratpoison commands."
194 (interactive)
195 (info "(ratpoison) Commands"))
196
197(provide 'ratpoison)