Toggle between Vertical and Horizontal Windows Splitting


Requested: Function that toggles between vertical and horizontal split layout of currently defined windows preferrably preserving splitting ratio.

(defun my-toggle-window-split ()
  "Vertical split shows more of each line, horizontal split shows
more lines. This code toggles between them. It only works for
frames with exactly two windows."
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
             (next-win-buffer (window-buffer (next-window)))
             (this-win-edges (window-edges (selected-window)))
             (next-win-edges (window-edges (next-window)))
             (this-win-2nd (not (and (<= (car this-win-edges)
                                         (car next-win-edges))
                                     (<= (cadr this-win-edges)
                                         (cadr next-win-edges)))))
              (if (= (car this-win-edges)
                     (car (window-edges (next-window))))
        (let ((first-win (selected-window)))
          (funcall splitter)
          (if this-win-2nd (other-window 1))
          (set-window-buffer (selected-window) this-win-buffer)
          (set-window-buffer (next-window) next-win-buffer)
          (select-window first-win)
          (if this-win-2nd (other-window 1))))))

Thanks Fabrice.

GNU Emacs on Cygwin

While it is possible to run Emacs on Windows, I suspect that Emacs “expects” to be running on UNIX. As such, I’ve decided to perform an experiment and try to do most of my work in Cygwin, including running Emacs. The following is how I did it:

  1. Create a Windows environment variable named ‘CYGWIN’ with the value ‘tty’
  2. Install Cygwin
  3. Install Cygwin/X
  4. Download-and-install Emacs using the setup.exe (as explained in the documentation linked above), choose the packages ’emacs’ and ’emacs-X11′, and be sure to check the “Bin?” checkbox. If you don’t check “Bin?” it will look like the installer is doing something, but in reality it does nothing (guess how I know that?).
  5. Add this to your .bashrc (see steps below if you want to use Emacs): export DISPLAY=:0.0
  6. Run: source .bashrc
  7. Run: XWin -multiwindow &
  8. Run: xeyes &
  9. Xeyes should pop up. Now try emacs
  10. Run: emacs &
  11. The Emacs welcome screen should appear.

Updating your .bashrc

  1. Open a terminal
  2. Type: emacs -nw .bashrc
  3. Emacs gives you a welcome message. Hit C-l to continue editing.
  4. Go to the bottom of the page
  5. Insert an empty line at the end and type in the text listed above
  6. Hit C-x C-s to save the file
  7. Hit C-x C-c to exit Emacs


Addendum: 16/10/08
I removed the unnecessarily complex step re-starting the shell when source’ing would have done just fine.
I wasn’t happy with my explanation for doing this, so I revised it.

Choosing a font in Emacs on Windows

The truth is that I haven’t read the Emacs documentation yet. I will read it, it is on the list. Until then, I’ve relied on other kinds folks to provide answers for my questions. Tommy was kind enough to provide an answer for this one.

Evaluate the following in the scratch buffer:

(insert (w32-select-font))

For more information on Fonts in Emacs on Windows, go here.

(via Tommy)

Lucida Console Font on Emacs

Folks running Emacs on Windows (like me) might like to set their font to Lucida Console.
Until I find a tool or documentation on how to write X style font lines, I’ve copied some font-lines from other folks websites.

; (set-default-font "-outline-Lucida Console-normal-r-normal-normal-11-82-96-96-c-*-iso8859-1")
; (set-default-font "-*-Lucida Console-normal-r-*-*-11-82-*-*-c-*-*-ansi-")
; (set-default-font "-*-Lucida Console-normal-r-*-*-11-82-*-*-c-*-*-#204-")
; (set-default-font "-outline-Lucida Console-normal-r-normal-normal-12-90-96-96-c-*-iso8859-1")
; (set-default-font "-*-Lucida Console-normal-r-*-*-12-90-*-*-c-*-*-ansi-	")
; (set-default-font "-outline-Lucida Console-normal-r-normal-normal-13-78-120-120-c-*-iso10646-1")
; (set-default-font "-*-Lucida Console-normal-r-*-*-13-97-*-*-c-*-*-ansi-")
; (set-default-font "-*-Lucida Console-normal-r-*-*-14-*-96-96-c-*-iso8859-1")
; (set-default-font "*-Lucida Console-normal-r-*-*-15-*-96-96-c-*-iso8859-1")
; (set-default-font "-*-Lucida Console-normal-r-*-*-16-120-96-96-c-*-iso8859-1")

On Windows XP Pro, the difference in the font-line settings between font-sizes doesn’t seem to make any difference.
Addendum 05/30/08:
Here is the answer.