Archive for March, 2007

Most of the time I use emacs in fullscreen mode. So it’s a good thing to split the window horizontally, so you have two side-by-side windows. Now it happens sometimes that I split one of those two “main windows” vertically or a pup-up-window does so. So how do I get back to my 2 side-by-side window layout then?

There are several possibilities:

  1. I saved the layout and can quickly restore it. See my blog entry Conveniently save and restore frame configurations
  2. I use winner-mode and so I can switch back to older window configurations step by step. This can be quite annoying if I had several layout changes in between.
  3. I switch into all the windows I want to delete and hit C-x 0 in them.
  4. I use this code which provides a pimped version of the standard emacs function delete-other-windows usually bound to C-x 1. My version th-delete-other-windows acts like the standard function when you don’t provide it a prefix arg. With prefix arg 2 or 3 it deletes the windows below/above or left/right of the current window.
    (require 'windmove)
    (defun th-delete-other-windows-vertically ()
      "Delete all windows above or below the current window."
        (while (condition-case nil (windmove-up) (error nil))
        (while (condition-case nil (windmove-down) (error nil))
    (defun  th-delete-other-windows-horizontally ()
      "Delete all windows left or right of the current window."
        (while (condition-case nil (windmove-left) (error nil))
        (while (condition-case nil (windmove-right) (error nil))
    (defun th-delete-other-windows (&optional arg)
      "If ARG is 2 delete all windows which are above or below the
    current window. If ARG is 3 delete all windows which are left or
    right to the current window. If no prefix arg is given, delete
    all other windows."
      (interactive "p")
       ((= arg 2) (th-delete-other-windows-vertically))
       ((= arg 3) (th-delete-other-windows-horizontally))
       (t (delete-other-windows))))
    (global-set-key (kbd "C-x 1") 'th-delete-other-windows)

UPDATE: There was a line (message "Arg = %d" arg) in
which raises an error when the function is called without a prefix arg. Simply remove the line. In addition it has to be (interactive "p") instead of (interactive "P"). Both defects are removed in the code above, now. I really should start testing all possibilities before posting…

UPDATE 2: In some situation the wrong window is selected after invoking one of the functions above. You can find the fixed versions in the file th-common.el my darcs repository. Have a look at my ElispArea.

Got my own mailing list!

Posted: March 21, 2007 in Applications, Emacs

I created a mailing list or all questions concerning my software and configs at See tsdh-fans. I’m so hip! :-)

I’m a happy user of Stumpwm for about 2 month. Finally I found a window manager which can be configured to do exactly what I want, just like emacs.

Here’s a some hack from my .stumpwmrc.

These functions let me use a different keymap for a given amount of seconds.

I normally use Emacs in fullscreen mode. When I split a window horizontally I get 2 side-by-side windows and each is about 95 columns wide. But by default all pop-up-windows like completion or compilation buffers split the window vertically. mulligan pointed me to the variable display-buffer-function on the #emacs IRC channel. It should be a function symbol which will be called instead of display-buffer. In that function the user can manage the splitting and assigning of buffers to windows on his own.

I came up with this function, which makes a fullscreen emacs much more convenient and behaves like the default if emacs is not wide enough for 2 side-by-side windows that are at least 80 columns wide each.

(defun th-display-buffer (buffer force-other-window)
  "If BUFFER is visible, select it.

If it's not visible and there's only one window, split the
current window and select BUFFER in the new window. If the
current window (before the split) is more than 165 columns wide,
split horizontally, else split vertically.

If the current buffer contains more than one window, select
BUFFER in the least recently used window.

This function returns the window which holds BUFFER.

  (or (get-buffer-window buffer)
      (if (one-window-p)
          (let ((new-win (if (> (window-width) 165)
            (set-window-buffer new-win buffer)
        (let ((new-win (get-lru-window)))
          (set-window-buffer new-win buffer)

(setq display-buffer-function 'th-display-buffer)

For the functions exact behavior see its docstring.

UPDATE: Fredrik Axelsson created a patch which adds a new variable prefer-window-split-horizontally. See his message on gmane.emacs.pretest.bugs. The patch is delayed at least till the release of Emacs 22.

The version I released yesterday had a bug. If the defaulst value of rdictcc-translate-word was taken from a read-only buffer you couldn’t edit it in the mini buffer. This release fixes this problem. See RDictCc.