How do I set the size of Emacs' window?

前端 未结 10 1450
陌清茗
陌清茗 2020-12-04 06:19

I\'m trying to detect the size of the screen I\'m starting emacs on, and adjust the size and position the window it is starting in (I guess that\'s the frame in emacs-speak)

相关标签:
10条回答
  • 2020-12-04 06:37

    On windows, you could make emacs frame maximized using this function :

    (defun w32-maximize-frame ()
      "Maximize the current frame"
      (interactive)
      (w32-send-sys-command 61488))
    
    0 讨论(0)
  • 2020-12-04 06:40
    (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)
    

    I prefer Bryan Oakley's settings. However the 'height not work properly in my GNU Emacs 24.1.1.

    0 讨论(0)
  • 2020-12-04 06:42

    On ubuntu do:

    (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)
    
    0 讨论(0)
  • 2020-12-04 06:46

    If you want to change the size according to resolution you can do something like this (adjusting the preferred width and resolutions according to your specific needs):

    (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)
    

    Note that window-system is deprecated in newer versions of emacs. A suitable replacement is (display-graphic-p). See this answer to the question How to detect that emacs is in terminal-mode? for a little more background.

    0 讨论(0)
提交回复
热议问题