Saturday, March 10, 2012

Beginning StumpWM configuration

StumWM stores its configuration in a .stumpwmrc file in the home directory. The number one thing I need in this file is Swank. Here's the code I used.
(load "/home/mostafa/slime/swank-loader.lisp")
(swank-loader:init)
(defcommand swank () ()
  (setf stumpwm:*top-level-error-action* :break)
  (swank:create-server :port 4005
                       :style swank:*communication-style*
                       :dont-close t)
  (echo-string
   (current-screen)
   "Starting swank. M-x slime-connect RET RET, then (in-package stumpwm)."))
(swank)
For some reason, this does not always start swank though. When that happens, I just hit C-t ; and run "swank." I can then connect to the Lisp image by invoking slime-connect in emacs.

I've been using this sample as the base for my own .stumpwmrc. What I've learned? First, I learned how I can declare a command that can be run interactively run through StumpWM's semi-colon prompt. The macro is defcommand. It's similar to defun, only with an additional set of "interactive" parameters which will be prompted for at run time.

I also learned that I can define my own key-bindings using define-key. Here's an example:
(define-key *root-map* (kbd "x") "firefox")
This tells StumpWM to run the command "firefox" previously declared by defcommand when I hit C-t x. C-t is StumpWM's prefix key (can be changed of course). Any key-binding added to *root-map* is should be used after pressing this prefix. If wan't to make a key-binding without the prefix key, I can add it to *top-map*. This is how the "firefox" command is defined:
;; launch web browser
(defcommand firefox () ()
  "start firefox or switch to it if already running."
  (run-or-raise "firefox" '(:class "Firefox")))
Remember that the value after :class should be Firefox with a capital F. If it's not written like that, rerunning the command will not raise the current window, but will open a new one. On Debian, :class should be Iceweasel instead of Firefox. (For a short explanation of class and other window attributes in X see here. In short, class name is, by convention, the instance name with the first letter capitalized.)

One of the most frequent things I do throughout my day is jumping to Wikipedia to look up something, or to search for it in Google. These two commands help me do that easier:
;; ask the user for a search string and search for it in Wikipedia
(defcommand wikipedia (search)
  ((:string "Search in Wikipedia for: "))
  "prompt the user for a search term and look it up in the English Wikipedia"
  (check-type search string)
  (let ((uri (format nil "http://en.wikipedia.org/wiki/Special:Search?search=~a" search)))
    (run-shell-command
     (cat "firefox \"" uri "\""))))

;; ask the user for a search string and search for it in Google
(defcommand google (search)
  ((:string "Search in Google for: "))
  "prompt the user for a search term and look it up in Google "
  (check-type search string)
  (let ((uri (format nil "http://www.google.com/search?q=~a" search)))
    (run-shell-command
     (cat "firefox \"" uri "\""))))
Finally, I need to more things. First, Network Manager seems essential. I'm going to use it's Tray icon at the moment, so since StumpWM doesn't have a tray, I'll use trayer which launches a tray in a floating window. In Debian, trayer can be installed by running apt-get install trayer. This launches trayer properly and then runs the Network Manager applet.
;; system tray
(run-shell-command
 "/usr/bin/trayer --SetDockType false --transparent true --expand false")

;; start network manager applet
(run-shell-command "nm-applet --sm-disable")
And then I need to load my own customized keymap (I swap the ctrl and alt keys and make Caps Lock an additional alt).
;; load keyboard map
(run-shell-command "xmodmap ~/.xmodmap")
That's it for now.

No comments:

Post a Comment

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 ...