Created
December 10, 2008 20:09
-
-
Save wilkes/34464 to your computer and use it in GitHub Desktop.
emacs window layout hacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'cl) | |
(defun twm-make-full-screen () | |
(when (and (featurep 'aquamacs) (not (frame-parameter nil 'fullscreen))) | |
(aquamacs-toggle-full-frame))) | |
(defun twm-focus-window () | |
"assumes the largest window is the focus window" | |
(get-largest-window)) | |
(defun twm-select-focus-window () | |
(interactive) | |
(select-window (twm-focus-window))) | |
(defun twm-buffer-list () | |
(remove-if (lambda (b) | |
(let ((name (buffer-name b))) | |
(or (string-match "\*Minibuf-*" name) | |
(string-match "\*Echo-*" name) | |
(string-match "\*code-conversion-work*" name)))) | |
(buffer-list (selected-frame)))) | |
(defun twm-select-next-window () | |
(other-window 1)) | |
(defun twm-next-window (show-func sel-buffer-func) | |
(twm-select-next-window) | |
(funcall show-func sel-buffer-func)) | |
(defmacro deflayout (fname &rest body) | |
`(defun ,fname () | |
(interactive) | |
(delete-other-windows) | |
(set-frame-font "-apple-monaco-medium-r-normal--12-120-72-72-m-120-mac-roman") | |
(let* ((blist (twm-buffer-list)) | |
(show (lambda (f) | |
(set-window-buffer (selected-window) | |
(or (funcall f blist) | |
(first blist)))))) | |
(progn ,@body) | |
(when (> (length (window-list)) 1) | |
(enlarge-window-horizontally 10))))) | |
(deflayout twm-1-layout | |
(twm-make-full-screen)) | |
(deflayout twm-1-1-layout | |
(split-window-horizontally) | |
(twm-next-window show #'second) | |
(twm-select-next-window)) | |
(deflayout twm-1-2-layout | |
(split-window-horizontally) | |
(twm-next-window show #'second) | |
(split-window-vertically) | |
(twm-next-window show #'third) | |
(twm-select-next-window)) | |
(deflayout twm-2-2-layout | |
(split-window-vertically) | |
(split-window-horizontally) | |
(twm-next-window show #'second) | |
(twm-next-window show #'third) | |
(split-window-horizontally) | |
(twm-next-window show #'fourth) | |
(twm-select-next-window) | |
(enlarge-window 10)) | |
(defun twm-cycle-layouts () | |
(interactive) | |
(let* ((twm-layouts (list #'twm-1-layout #'twm-1-1-layout #'twm-1-2-layout #'twm-2-2-layout)) | |
(n (length (window-list nil 0)))) | |
(if (>= n (length twm-layouts)) | |
(funcall (first twm-layouts)) | |
(funcall (nth n twm-layouts))))) | |
(defun twm-zoom () | |
(interactive) | |
(twm-1-layout) | |
(set-frame-font "-apple-monaco-medium-r-normal--14-120-72-72-m-120-mac-roman")) | |
(defun twm-focus-current-buffer () | |
(interactive) | |
(let* ((focus-buffer (window-buffer (twm-focus-window)))) | |
(set-window-buffer (twm-focus-window) (window-buffer)) | |
(set-window-buffer (selected-window) focus-buffer) | |
(twm-select-focus-window))) | |
(defun map-buffers->windows (buffers windows) | |
(if (or (null windows) (null buffers)) | |
nil | |
(set-window-buffer (first windows) (first buffers)) | |
(map-buffers->windows (rest buffers) (rest windows)))) | |
(defun twm-cycle-windows () | |
(interactive) | |
(let* ((windows (window-list nil 0)) | |
(visible-buffers (reverse (mapcar (lambda (w) | |
(window-buffer w)) | |
windows))) | |
(rotated-buffers (cons (first visible-buffers) | |
(reverse (rest visible-buffers))))) | |
(map-buffers->windows rotated-buffers windows) | |
(twm-select-focus-window))) | |
(global-set-key [(meta shift return)] 'aquamacs-toggle-full-frame) | |
(global-set-key "\C-x\M-f" 'twm-select-focus-window) | |
(global-set-key [f3] 'twm-cycle-windows) | |
(global-set-key [f4] 'twm-focus-current-buffer) | |
(global-set-key [f5] 'twm-cycle-layouts) | |
(global-set-key [f6] 'twm-zoom) | |
(provide 'my-twm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment