[emacs][anything] anything-windowの動的縦横再分割とサイズの変更
■動機
狭いwindowにanything-bufferが表示されたときに、項目が見づらい。
横分割になったときは特に。
■経緯
1.(何故か)常に横分割されるwindowを縦分割に変更しようと試みる
pop-to-buffer の挙動を変更しようと色々調べまくるが、解決策は見つからず
何の気なしに ad-deactivate-all した後 anything を実行すると、縦分割になっている
横分割にしてるのは何かのアドバイスの影響だったのかorz
anything-c-source-buffer2で使用している (defadvice anything-mark-current-line(after anything-execute-persistent-action first (&rest ret) activate)
が切っ掛けだと分かった。
anything-c-source-buffer2 の persistent-action で delete-other-window 及び (or (split-window) (split-window-horizontally))を発行している箇所で横分割になっている。
ここで閃く。
このコードを流用すれば、縦/横の動的分割変更が出来るんじゃなかろうか。
"結果"に続く
2.widen-windowを利用して anything-window を広くする
pop-to-bufferの挙動変更で行き詰まっているときに、ふとwiden-windowでanything-windowでanything-windowを広くすればいいんじゃないかと気がつく
苦労しつつも実装完了。
おかげで、buffer と frame と window の関係が分かったような気がする。
しかし、下記の2つの問題点がある
・先の anything-c-source-buffer2の影響を受けてしまう
・anything-c-source-bm-extを自家拡張した anything-sources で起動すると、deactivateしているはずの "widen-window" アドバイスが有効になってしまう。
■結果
1.anything-windowの動的縦/横分割変更
(defun my-anything-resplit-window (direction) (when (anything-window) (save-selected-window (select-window (anything-window)) (delete-other-windows) (switch-to-buffer anything-current-buffer) (if (eq direction 'vertically) (split-window-vertically) (split-window-horizontally)) (select-window (next-window)) (switch-to-buffer anything-buffer)))) (defun my-anything-resplit-horizontally () (interactive) (my-anything-resplit-window 'horizontally)) (defun my-anything-resplit-vertically () (interactive) (my-anything-resplit-window 'vertically)) (define-key anything-map "\C-k" 'my-anything-resplit-horizontally) (define-key anything-map "\C-j" 'my-anything-resplit-vertically)
2009/1/16追記
http://www.bookshelf.jp/soft/meadow_30.html の "30.4 横分割と縦分割を切り替える (2003/07/25)"をちょこっと変更すれば、トグル動作出来ることが発覚。
C-o で縦分割/横分割の切り替えを行うように設定。
(defun my-anything-toggle-resplit-window () (interactive) (when (anything-window) (save-selected-window (select-window (anything-window)) (let ((before-height (window-height))) (delete-other-windows) (switch-to-buffer anything-current-buffer) (if (= (window-height) before-height) (split-window-vertically) (split-window-horizontally))) (select-window (next-window)) (switch-to-buffer anything-buffer)))) (define-key anything-map "\C-o" 'my-anything-toggle-resplit-window)
anything-c-source-buffers2 の persistent-actionが干渉するので、下記に変更(大丈夫…だよね……)
(defun anything-c-buffer-list-preview-buffer (buf) (when (and buf (or (bufferp buf) (bufferp (get-buffer buf)))) (switch-to-buffer buf)))
2.widen-windowを利用して anything-window を広くする
(defun my-anything-wide-window () (interactive) (when (anything-window) (save-selected-window (select-window (anything-window)) (with-current-buffer anything-buffer (save-excursion (widen-current-window) (setq anything-is-widen-window t)))))) (define-key anything-map "\C-w" 'my-anything-wide-window)