Home

Wed, Apr. 2nd, 2008, 02:17 pm
Emacs tip: resize the window or frame to 80 columns wide.

I wrote fix-horizontal-size, an Emacs Lisp function that resizes either the frame or the window to 80 columns wide.

If the window can be sized to 80 columns wide, without resizing the frame itself, it will resize the window. Otherwise, it will resize the frame.

You can use a prefix argument to specify a different column width.

(defun fix-frame-horizontal-size (width)
  "Set the frame's size to 80 (or prefix arg WIDTH) columns wide."
  (interactive "P")
  (if window-system
      (set-frame-width (selected-frame) (or width 80))
    (error "Cannot resize frame horizontally: is a text terminal")))

(defun fix-window-horizontal-size (width)
  "Set the window's size to 80 (or prefix arg WIDTH) columns wide."
  (interactive "P")
  (enlarge-window (- (or width 80) (window-width)) 'horizontal))

(defun fix-horizontal-size (width)
  "Set the window's or frame's width to 80 (or prefix arg WIDTH)."
  (interactive "P")
  (condition-case nil
      (fix-window-horizontal-size width)
    (error 
     (condition-case nil
	 (fix-frame-horizontal-size width)
       (error
	(error "Cannot resize window or frame horizontally"))))))

(global-set-key (kbd "C-x W") 'fix-horizontal-size)

There are separate functions fix-window-horizontal-size and fix-frame-horizontal-size if you want to only resize the window or only resize the frame instead of resizing either.

Tue, Feb. 5th, 2008, 01:41 am
More emacs lisp fun: save face customizations into a different file.

I just wrote custom-faces-file.el so that I can split variable customizations and face customizations into different files.

It's only guaranteed to work with GNU Emacs 22.

Fri, Feb. 1st, 2008, 12:09 am
hide-mode-line.el: it's like WriteRoom in Emacs.

You know that flash-in-the-pan text editor WriteRoom?

Some advocates of Emacs will say "just run emacs in a full-screen" or something along those lines, but I find sometimes that the mode-line is still a distraction.

So I'm working on an implementation of distraction removal in Emacs for two reasons: (1) I think the concept has merit and (2) I don't like the idea of someone writing a whole new text editor just so they can have a certain feature. :)

My rough implementation is available for download.

Incase you want to know what emacs looks like without a modeline:

Holy crap, emacs without a modeline!

Basically, this implementation automatically hides the modeline when all of the following conditions apply:
- hide-mode-line is turned on
- there is only one frame
- there is only one window in that frame
- there is no minibuffer
and automatically shows all buffers' modelines otherwise.

This implementation does have bugs, you know: I intermittently have problems with text disappearing. Those problems might be related to the more frequent ones I have when I do (setq mode-line-format nil) (or use hide-mode-line) in conjunction with linum.

Thu, Mar. 8th, 2007, 01:46 pm
.emacs tip

First, a little background. I have accounts on many Unix boxes. In order to maintain one set of configuration files instead of many, I keep the configuration files in a Subversion repository and use a hacked version of GNU Stow to "install" them into my home directory.

Due to how GNU Stow works, all my configuration files are actually symbolic links that point to their real locations. One such file:

$ ls -ld .emacs
*SNIP* .emacs -> svn/dse/config-files/trunk/nox/.emacs

End background.

Unfortunately, The M-x customize feature of GNU Emacs works by removing that symlink and recreating /home/dse/.emacs as a regular file when you save configuration changes. Subversion never catches this and I wind up with slightly different versions of .emacs all over the place.

In order to solve this problem, place this in the beginning of your .emacs file:

; If .emacs is a symlink, M-x customize will delete it
; and replace it with a regular file.  So we point it
; to the actual file it points to.
(cond ((file-symlink-p user-init-file)
       (setq user-init-file
             (concat (file-name-directory user-init-file)
                     (file-symlink-p user-init-file)))))