107

私はemacsを起動している画面のサイズを検出し、それに応じてサイズと開始ウィンドウの位置を調整しようとしています(これはemacsで言えばフレームだと思います)。画面の左上隅に近い左上隅にある「適度に大きな」ウィンドウが常に表示されるように、.emacs を設定しようとしています。

これは一般的なケースに対する大きな質問だと思うので、少し絞り込むために、Windows および (Debian) Linux 上の GNU Emacs 22 に最も関心があります。

4

10 に答える 10

89

解像度に応じてサイズを変更したい場合は、次のようにすることができます (特定のニーズに応じて優先幅と解像度を調整します)。

(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がターミナルモードであることを検出する方法は? もう少し背景について。

于 2008-09-18T16:40:11.147 に答える
53

私は私の中に次のものを持っています.emacs

(if (window-system)
  (set-frame-height (selected-frame) 60))

また、関数、、、およびを見ることがset-frame-sizeできset-frame-positionますset-frame-widthC-h f(aka )を使用M-x describe-functionして、詳細なドキュメントを表示します。

現在のウィンドウ環境でフレームの最大の高さ/幅を計算する方法があるかどうかはわかりません。

于 2008-09-18T16:29:29.737 に答える
21

出典: 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 を開始する元のフレームを知っていると便利な場合があるためです。

于 2008-09-18T14:26:48.033 に答える
18

X-Window環境でそれを行うために私が見つけた最も簡単な方法は、Xリソースを使用することです。私の.Xdefaultsの関連部分は次のようになります。

Emacs.geometry: 80x70

+ 0 + 0の位置座標を接尾辞として付けて、ディスプレイの左上隅に強制的に配置できるはずです。(私がそうしない理由は、時々新しいフレームを生成するためです。前のフレームとまったく同じ場所に表示されると、混乱を招きます)

マニュアルによると、この手法はMS Windowsでも機能し、リソースをキーと値のペアとしてレジストリに保存します。私はそれをテストしたことはありません。それは素晴らしいかもしれません、それは単にファイルを編集することに比べてはるかに不便かもしれません。

于 2008-09-18T14:34:04.973 に答える
18

次のコードを追加してみてください.emacs

(add-to-list 'default-frame-alist '(height . 24))

(add-to-list 'default-frame-alist '(width . 80)) 
于 2012-09-08T22:18:15.620 に答える
12

emacs を起動するときに -geometry パラメータを使用することもできます。これによりemacs -geometry 80x60+20+30、幅 80 文字、高さ 60 行、左上隅が右に 20 ピクセル、背景の左上隅から 30 ピクセル下のウィンドウが表示されます。

于 2008-09-18T16:44:39.887 に答える
7

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)
于 2011-10-05T11:32:56.563 に答える
5

Windowsでは、この関数を使用してemacsフレームを最大化できます。

(defun w32-maximize-frame ()
  "Maximize the current frame"
  (interactive)
  (w32-send-sys-command 61488))
于 2010-08-21T20:05:22.447 に答える
1
(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))
于 2008-09-18T14:25:26.133 に答える
0
(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では高さが適切に機能しません。

于 2012-08-11T05:42:07.887 に答える