From: unknown Date: Fri, 2 Mar 2012 09:56:23 +0000 (+0100) Subject: New stuff in setup: bindings.el, flyspell.el, mywin.el X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=e89ef96db54aeeb2550403dbd6edee51ceab053e;p=emacs-init.git New stuff in setup: bindings.el, flyspell.el, mywin.el --- diff --git a/setup/bindings.el b/setup/bindings.el new file mode 100644 index 0000000..c06b502 --- /dev/null +++ b/setup/bindings.el @@ -0,0 +1 @@ +(global-set-key "\M-/" 'hippie-expand) diff --git a/setup/flyspell.el b/setup/flyspell.el new file mode 100644 index 0000000..1352979 --- /dev/null +++ b/setup/flyspell.el @@ -0,0 +1,6 @@ +(require 'advice) + +; Speed up interactivity in flyspell (it's unusable on windows otherwise) + +(defadvice flyspell-check-pre-word-p (around flyspell-delay-all activate) + (setq ad-return-value nil)) diff --git a/setup/mywin.el b/setup/mywin.el new file mode 100644 index 0000000..2d36460 --- /dev/null +++ b/setup/mywin.el @@ -0,0 +1,114 @@ +(defun split-window-3-horizontally () + "Split window horizontally into three equal sized windows" + (interactive) + (let ((w (window-width))) + (split-window-horizontally (- w (/ w 3) -2)) + (split-window-horizontally))) + +(defun split-window-n-horizontally (width &optional min) + "Split window horizontally into WIDTH wide windows making the last +window no smaller than MIN. MIN defaults to WIDTH and WIDTH defaults +to 80." + (interactive "P") + (if (not width) (setq width 80)) + (if (not min) (setq min width)) + (save-selected-window + (while (> (window-width) (+ width 3 min 3)) + (select-window (split-window-horizontally (+ width 3))) + (switch-to-buffer (get-buffer-create "*scratch*"))))) + +(defun maximize-window(&optional min-height) + "Enlarge the current window by as many lines as is possible without making any other +window smaller than MIN-HEIGHT lines." + (interactive) + ;; this algorithm is copied from window.el / balance-windows() + (let ((min-height (or min-height i(+ window-min-height 0))) + (count -1) + size) + ;; Don't count the lines that are above the uppermost windows. + ;; (These are the menu bar lines, if any.) + ;; Find all the different vpos's at which windows start, + ;; then count them. But ignore levels that differ by only 1. + (save-window-excursion + (let (tops (prev-top -2)) + (walk-windows (function (lambda (w) + (setq tops (cons (nth 1 (window-edges w)) + tops)))) + 'nomini) + (setq tops (sort tops '<)) + (while tops + (if (> (car tops) (1+ prev-top)) + (setq prev-top (car tops) + count (1+ count))) + (setq tops (cdr tops))) + (setq count (1+ count)))) + (setq size (- (frame-height) (* (1- count) min-height))) + (enlarge-window (- size (window-height))))) + +(defun safe-shrink-window(&optional n min-height) + "Like shrink-window but will not remove a window" + (interactive) + (let* ((min-height (or min-height window-min-height)) + (n (or n 1))) + (if (< (- (window-height) n) min-height) + (shrink-window (- (window-height) min-height)) + (shrink-window n)))) + +(defun setup-my-windows () + (interactive) + (let ((width 100) (min 100) (distribute t) + (currentwindow (selected-window)) topwindows newwindow newtopwindows) + (walk-windows (function (lambda (w) + (let ((e (window-edges w))) + (if (< (nth 1 e) window-min-height) + (setq topwindows (cons (list (nth 0 e) + w + (window-buffer w) + (window-point w) + (window-start w) + (equal w currentwindow)) + topwindows)))))) + 'nomini) + (setq topwindows (sort topwindows (function (lambda (a b) (< (car a) (car b)))))) + (delete-other-windows (nth 1 (car topwindows))) + (setq topwindows (cdr topwindows)) + (save-selected-window + (select-window (split-window-vertically + (- (window-height) (max 5 (/ (* (frame-height) 15) 100)) -1))) + (switch-to-buffer (get-buffer-create "*compilation*"))) + (setq newwindow (selected-window)) + (setq newtopwindows (list (selected-window))) + (while (> (window-width) (+ width 3 min 3)) + (select-window (split-window-horizontally (+ width 3))) + (setq newtopwindows (cons (selected-window) newtopwindows)) + (if topwindows + (progn + (switch-to-buffer (nth 2 (car topwindows))) + (set-window-start (selected-window) (nth 4 (car topwindows))) + (goto-char (nth 3 (car topwindows))) + (if (nth 5 (car topwindows)) + (setq newwindow (selected-window))) + (setq topwindows (cdr topwindows))) + (switch-to-buffer (get-buffer-create "*scratch*")))) + (select-window newwindow) + (if (and distribute (> (length newtopwindows) 1)) + (balance-windows newwindow)))) + +(defun my-split-window-sensibly (window) + (if (and (> (window-height window) (- (frame-height (window-frame window)) window-min-height)) + (> (window-height window) (max 5 (/ (* (frame-height) 15) 100)))) + (split-window-sensibly window))) + +(setq split-window-preferred-function 'my-split-window-sensibly) + +(global-set-key "\C-x7" 'split-window-3-horizontally) +(global-set-key "\C-x8" (lambda () (interactive) (split-window-n-horizontally 100 50))) +(global-set-key "\C-x9" 'setup-my-windows) +(global-set-key "\C-xp" 'other-window-reverse) +(global-set-key "\C-\M-_" (lambda () (interactive) (safe-shrink-window 5))) + +(defun maximize-window-15 () + (interactive) + (maximize-window (max 5 (/ (* (frame-height) 15) 100)))) + +(global-set-key [(ctrl meta ?+)] 'maximize-window-15)