私はemacsを起動している画面のサイズを検出し、それに応じてサイズと開始ウィンドウの位置を調整しようとしています(これはemacsで言えばフレームだと思います)。画面の左上隅に近い左上隅にある「適度に大きな」ウィンドウが常に表示されるように、.emacs を設定しようとしています。
これは一般的なケースに対する大きな質問だと思うので、少し絞り込むために、Windows および (Debian) Linux 上の GNU Emacs 22 に最も関心があります。
解像度に応じてサイズを変更したい場合は、次のようにすることができます (特定のニーズに応じて優先幅と解像度を調整します)。
(defun set-frame-size-according-to-resolution ()
(interactive)
(if window-system
(progn
;; use 120 char wide window for largeish displays
;; and smaller 80 column windows for smaller displays
;; pick whatever numbers make sense for you
(if (> (x-display-pixel-width) 1280)
(add-to-list 'default-frame-alist (cons 'width 120))
(add-to-list 'default-frame-alist (cons 'width 80)))
;; for the height, subtract a couple hundred pixels
;; from the screen height (for panels, menubars and
;; whatnot), then divide by the height of a char to
;; get the height we want
(add-to-list 'default-frame-alist
(cons 'height (/ (- (x-display-pixel-height) 200)
(frame-char-height)))))))
(set-frame-size-according-to-resolution)
新しいバージョンの emacs では window-system が非推奨になっていることに注意してください。適切な代替品は(display-graphic-p)
. 質問へのこの回答を参照してください。 emacsがターミナルモードであることを検出する方法は? もう少し背景について。
私は私の中に次のものを持っています.emacs
:
(if (window-system)
(set-frame-height (selected-frame) 60))
また、関数、、、およびを見ることがset-frame-size
できset-frame-position
ますset-frame-width
。C-h f
(aka )を使用M-x describe-function
して、詳細なドキュメントを表示します。
現在のウィンドウ環境でフレームの最大の高さ/幅を計算する方法があるかどうかはわかりません。
出典: http://www.gnu.org/software/emacs/windows/old/faq4.html
(setq default-frame-alist
'((top . 200) (left . 400)
(width . 80) (height . 40)
(cursor-color . "white")
(cursor-type . box)
(foreground-color . "yellow")
(background-color . "black")
(font . "-*-Courier-normal-r-*-*-13-*-*-*-c-*-iso8859-1")))
(setq initial-frame-alist '((top . 10) (left . 30)))
最初の設定は、起動時にポップアップする最初のフレームを含むすべての emacs フレームに適用されます。2 番目の設定は、追加の属性を最初のフレームに追加します。これは、emacs を開始する元のフレームを知っていると便利な場合があるためです。
X-Window環境でそれを行うために私が見つけた最も簡単な方法は、Xリソースを使用することです。私の.Xdefaultsの関連部分は次のようになります。
Emacs.geometry: 80x70
+ 0 + 0の位置座標を接尾辞として付けて、ディスプレイの左上隅に強制的に配置できるはずです。(私がそうしない理由は、時々新しいフレームを生成するためです。前のフレームとまったく同じ場所に表示されると、混乱を招きます)
マニュアルによると、この手法はMS Windowsでも機能し、リソースをキーと値のペアとしてレジストリに保存します。私はそれをテストしたことはありません。それは素晴らしいかもしれません、それは単にファイルを編集することに比べてはるかに不便かもしれません。
次のコードを追加してみてください.emacs
(add-to-list 'default-frame-alist '(height . 24))
(add-to-list 'default-frame-alist '(width . 80))
emacs を起動するときに -geometry パラメータを使用することもできます。これによりemacs -geometry 80x60+20+30
、幅 80 文字、高さ 60 行、左上隅が右に 20 ピクセル、背景の左上隅から 30 ピクセル下のウィンドウが表示されます。
ubuntu では次のようにします。
(defun toggle-fullscreen ()
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
)
(toggle-fullscreen)
Windowsでは、この関数を使用してemacsフレームを最大化できます。
(defun w32-maximize-frame ()
"Maximize the current frame"
(interactive)
(w32-send-sys-command 61488))
(setq initial-frame-alist
(append '((width . 263) (height . 112) (top . -5) (left . 5) (font . "4.System VIO"))
initial-frame-alist))
(setq default-frame-alist
(append '((width . 263) (height . 112) (top . -5) (left . 5) (font . "4.System VIO"))
default-frame-alist))
(defun set-frame-size-according-to-resolution ()
(interactive)
(if window-system
(progn
;; use 120 char wide window for largeish displays
;; and smaller 80 column windows for smaller displays
;; pick whatever numbers make sense for you
(if (> (x-display-pixel-width) 1280)
(add-to-list 'default-frame-alist (cons 'width 120))
(add-to-list 'default-frame-alist (cons 'width 80)))
;; for the height, subtract a couple hundred pixels
;; from the screen height (for panels, menubars and
;; whatnot), then divide by the height of a char to
;; get the height we want
(add-to-list 'default-frame-alist
(cons 'height (/ (- (x-display-pixel-height) 200)
(frame-char-height)))))))
(set-frame-size-according-to-resolution)
Bryan Oakley の設定の方が好きです。ただし、GNU Emacs 24.1.1では高さが適切に機能しません。