2010-07-05 [長年日記]
_ [Emacs] one-key-help-window-open の修正
横長ディスプレイで one-key を実行して、縦に画面が分割されると表示が乱れる。one-key-help-window-open でバッファに書き込んでから pop-to-buffer しているので、window-size の取得がうまくいっていない。そこで次のように変更して、これらの順番を逆にする。
(defun one-key-help-window-open (title info-alist) "Open the help window. Argument TITLE is title name for help information. Argument INFO-ALIST is help information as format ((key . describe) . command)." ;; Save current window configuration. (or one-key-help-window-configuration (setq one-key-help-window-configuration (current-window-configuration))) ;; Generate buffer information. (if (get-buffer one-key-buffer-name) (pop-to-buffer one-key-buffer-name) (with-current-buffer (get-buffer-create one-key-buffer-name) (pop-to-buffer one-key-buffer-name) (goto-char (point-min)) (save-excursion (insert (one-key-highlight-help title (one-key-help-format info-alist)))))) ;; Pop `one-key' buffer. (set-buffer one-key-buffer-name) ;; Adjust height of help window ;; to display buffer's contents exactly. (fit-window-to-buffer nil one-key-help-window-max-height))
[ツッコミを入れる]
2010-07-26 [長年日記]
_ [Linux] one-key-help-window-open の修正2
どうも前の修正だと、Emacs のウィンドウを縦に分割していて、ウィンドウの幅が異なる場合にうまく動かない。すでにウィンドウが複数に分割されている場合、一番大きなウィンドウを選択して one-key のバッファを表示するようにした。
(defvar one-key-minimal-window-width 40) (defun one-key-get-suitable-window () "Get window suitable for setting one-key buffer." (let* ((current-win (frame-selected-window)) (win-list (delete current-win (window-list))) (area 0) suitable-win) (when (> (length win-list) 0) (dolist (win win-list) (let* ((wwidth (window-width win)) (wheight (window-height win)) (new-area (* wwidth wheight))) (if (> wwidth one-key-minimal-window-width) (when (> new-area area) (setq area new-area) (setq suitable-win win)))))) (or suitable-win (split-window-sensibly current-win)))) (defun one-key-help-window-open (title info-alist) "Open the help window. Argument TITLE is title name for help information. Argument INFO-ALIST is help information as format ((key . describe) . command)." ;; Save current window configuration. (or one-key-help-window-configuration (setq one-key-help-window-configuration (current-window-configuration))) ;; Generate buffer information. (let ((win (one-key-get-suitable-window))) (with-selected-window win (if (get-buffer one-key-buffer-name) (set-window-buffer win one-key-buffer-name) (with-current-buffer (get-buffer-create one-key-buffer-name) (set-window-buffer win one-key-buffer-name) (goto-char (point-min)) (save-excursion (insert (one-key-highlight-help title (one-key-help-format info-alist)))))) ;; Adjust height of help window ;; to display buffer's contents exactly. (fit-window-to-buffer nil one-key-help-window-max-height))) ;; Pop `one-key' buffer. (set-buffer one-key-buffer-name))
_ [Linux] anything-display-function の変更
同様に anything を表示するウィンドウも変更することにした。必要最低限の横幅を持ち、縦が長いウィンドウに anything のバッファを表示することにする。
(defvar anything-buffer-minimal-window-width 40) (defun anything-get-suitable-window (buf) "Get window suitable for anytihng buffer." (if anything-samewindow (switch-to-buffer buf) (let* ((current-win (frame-selected-window)) (win-list (delete current-win (window-list))) (area 0) (height 0) suitable-win) (when (> (length win-list) 0) (dolist (win win-list) (let* ((wwidth (window-width win)) (wheight (window-height win)) (new-area (* wwidth wheight))) (if (and (> wwidth anything-buffer-minimal-window-width) (or (> wheight height) (and (= wheight height) (> new-area area)))) (progn (setq height wheight) (setq area new-area) (setq suitable-win win)))))) (if suitable-win (progn (select-window suitable-win) (switch-to-buffer buf)) (pop-to-buffer buf))))) (setq anything-display-function 'anything-get-suitable-window)
[ツッコミを入れる]