some emacs things

Just some little scripts. See also some ruby things and some sawfish things.

Disclaimer: I know little.

kill-orphan-buffers
Kills all orphan buffers - buffers that are visiting a file that no longer exists. Useful if you've just done an svn up and various files were moved or removed.

(defun kill-orphan-buffers ()
  (interactive)
  (dolist (buffer (buffer-list))
    (let ((fname (buffer-file-name buffer)))
      (when (and fname (not (file-exists-p fname)) (not (buffer-modified-p buffer)))
        (message (concat "Killing " fname))
        (kill-buffer buffer)))))
revert-unmodified-buffers
Reverts all unmodified buffers that are visiting files that have changed since they were opened. Useful if you've just done an svn up and want all your unedited buffers to be updated.
(defun revert-unmodified-buffers ()
  (interactive)
  (dolist (buffer (buffer-list))
    (let ((fname (buffer-file-name buffer)))
      (when (and fname (file-exists-p fname) (not (buffer-modified-p buffer))
                 (not (verify-visited-file-modtime buffer)))
        (message (concat "Reverting " fname))
        (with-current-buffer buffer
          (revert-buffer t t))))))
kill-buffers-matching
Kills all buffers matching a regex. Useful to close out buffers associated with a component you're no longer working on.
(defun kill-buffers-matching (pattern)
  (interactive "sPattern: ")
  (dolist (buffer (buffer-list))
    (let ((fname (buffer-file-name buffer)))
      (when (and fname (string-match pattern fname))
        (message (concat "Killing " fname))
        (kill-buffer buffer)))))
split-thrice
Splits the current buffer into three equal columns. Useful on a 24" monitor.
(defun split-thrice ()
  (interactive)
  (let ((cols (/ (window-width) 3)))
    (split-window-horizontally (+ cols cols))
    (split-window-horizontally cols)
    ))

(global-set-key (kbd "C-x 4") 'split-thrice)
tidy-up-imports
Tidies up all imports. Reorders and removes unused import. Requires JDE.
(defun tidy-up-imports ()
  (interactive)
  (jde-import-kill-extra-imports)
  (jde-import-organize))

(global-set-key (kbd "C-c C-v C-i") 'tidy-up-imports)
tidy-all-imports
Tidies all imports in all open Java source files. Requires JDE. Useful after you've done a bunch of refactoring.
(defun tidy-all-imports ()
  (interactive)
  (dolist (buffer (buffer-list))
    (let ((fname (buffer-file-name buffer)))
      (when (and fname (string-match "\.java$" fname))
        (message (concat "Tidying " fname))
        (with-current-buffer buffer
          (tidy-up-imports)
          (save-buffer))))))

yeah

Yeah, nothing will probably work.

merlin.