21

It's common for me to press alt-f10 (in GNU/Linux) after Emacs start up for maximizing window (in the Emacs terminology, it's actually a frame). Most of the time I press thrice because I was too early to press first alt-f10 which makes some garbage appear around the minibuffer (Emacs display bug?)

How can I automate this one? (Maybe with Gnome settings or with elisp?)

I am using emacs24 (from bzr repo).

Note that it's not the regular fullscreen I want which you would get by pressing f11.

tripleee
  • 175,061
  • 34
  • 275
  • 318
kindahero
  • 5,817
  • 3
  • 25
  • 32
  • Why don't you set `initial-frame-alist` or the corresponding `xrdb` resources to the geometry you want instead? See http://stackoverflow.com/questions/92971/how-do-i-set-the-size-of-emacs-window for code and pointers. – tripleee Oct 14 '11 at 16:23
  • I want to have full screen, the accepted answer meets my need. thanks for the link BTW. – kindahero Oct 14 '11 at 16:55

5 Answers5

14
(defun fullscreen (&optional f)
       (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)))

might work. (Taken from here.)

phimuemue
  • 34,669
  • 9
  • 84
  • 115
10
;; Next code works with Emacs 21.4, 22.3, 23.1, 24.3.
(when window-system
  (let (
        (px (display-pixel-width))
        (py (display-pixel-height))
        (fx (frame-char-width))
        (fy (frame-char-height))
        tx ty
        )
    ;; Next formulas discovered empiric on Windows host with default font.
    (setq tx (- (/ px fx) 7))
    (setq ty (- (/ py fy) 4))
    (setq initial-frame-alist '((top . 2) (left . 2)))
    (add-to-list 'initial-frame-alist (cons 'width tx))
    (add-to-list 'initial-frame-alist (cons 'height ty))
    ) )

This code preserv some place for task bar on the bottom under Windows/Gnome/KDE

But instead of asking try read: http://www.emacswiki.org/emacs/FullScreen

Lenar Hoyt
  • 5,971
  • 6
  • 49
  • 59
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • 1
    thanks.. did n't worked this one. yes I should have gone to the emacswiki first. its just I have been reading a lot on SO lately. – kindahero Oct 14 '11 at 16:47
  • I forget add that this code work only on Emacs loading so you need place it to .emacs file... Hope this help... – gavenkoa Oct 14 '11 at 19:33
  • yes. I understood that.. but it seems its not that I wanted. since I use monitors with different resolutions, I wanted to get is maximization of window rather than specific size. – kindahero Oct 14 '11 at 20:28
  • @kindahero. My solution is adaptive rather than specific size )) – gavenkoa Oct 15 '11 at 18:50
  • 1
    That works great. Can I somehow set the default frame size too? Something like `(setq default-frame-alist '((width . 190) (height . 50) ))`? I’m new to LISP, so… – Lenar Hoyt Mar 11 '14 at 03:25
  • You are right: `(add-to-list 'default-frame-alist '(height . 24))` and `(add-to-list 'default-frame-alist '(width . 80))`. See http://www.emacswiki.org/emacs/FrameSize – gavenkoa Mar 11 '14 at 06:27
9

OSX:

The developer build of Emacs Trunk has a function called toggle-frame-maximized, which is included within .../lisp/frame.el. That function can be added to the after-init-hook or emacs-startup-hook, or simply included in the .emacs file that gets loaded on startup. On OSX, it increases both width and height in one-fell-swoop.


Windows XP:

The following command can be used after a make-frame command, or after Emacs generates the initial frame.

(w32-send-sys-command 61488)

OSX and Windows

Here is an example for setting the initial frame size and location -- I have it near the beginning of my .emacs file:

(let ((frame (selected-frame)))
  (cond
    ((eq system-type 'darwin)
      (setq ns-auto-hide-menu-bar t)
      (set-frame-position frame 0 0) ;; must come after `ns-auto-hide-menu-bar`
      (cond
        ((and
            (= 1920 (display-pixel-width))
            (= 1080 (display-pixel-height)))
          (set-frame-size frame 1895 1054 t))
        ((and
            (= 1920 (display-pixel-width))
            (= 1200 (display-pixel-height)))
          (set-frame-size frame 1895 1174 t))
        ((and
            (= 1280 (display-pixel-width))
            (= 800 (display-pixel-height)))
          (set-frame-size frame 1265 774 t))) )
    ((and
        (eq system-type 'windows-nt)
        (equal (w32-version) '(5 1 2600)))
      ;; (w32-send-sys-command #xf030)
      (set-frame-position frame 0 0)
      (cond
        ((and
            (= 1920 (display-pixel-width))
            (= 1003 (display-pixel-height)))
          (set-frame-size frame 1898 924 t))
        ((and
            (= 1920 (display-pixel-width))
            (= 1123 (display-pixel-height)))
          (set-frame-size frame 1876 1052 t))
        ((and
            (= 1280 (display-pixel-width))
            (= 723 (display-pixel-height)))
          (set-frame-size frame 1250 670 t))))
      ((and
          (eq system-type 'windows-nt)
          (equal (w32-version) '(6 1 7601)))
        (set-frame-position frame 0 0)
        (cond
          ((and
              (= 1920 (display-pixel-width))
              (= 1080 (display-pixel-height)))
            (set-frame-size frame 1890 1003 t))
          (t
            (message "Not yet contemplated.")))) ))

Here is an example of what I use to create new frames -- controling the exact size and location:

(defun lawlist-make-frame (&optional alist)
  (let ((frame (make-frame alist)))
    (set-frame-position frame 0 0)
    (cond
      ((eq system-type 'darwin)
        (cond
          ((and
              (= 1920 (display-pixel-width))
              (= 1080 (display-pixel-height)))
            (set-frame-size frame 1895 1054 t))
          ((and
              (= 1920 (display-pixel-width))
              (= 1200 (display-pixel-height)))
            (set-frame-size frame 1895 1174 t))
          ((and
              (= 1280 (display-pixel-width))
              (= 800 (display-pixel-height)))
            (set-frame-size frame 1265 774 t))))
      ((and
          (eq system-type 'windows-nt)
          (equal (w32-version) '(5 1 2600)))
        (select-frame frame)
        (cond
          ((and
              (= 1920 (display-pixel-width))
              (= 1003 (display-pixel-height)))
            (set-frame-size frame 1898 924 t))
          ((and
              (= 1920 (display-pixel-width))
              (= 1123 (display-pixel-height)))
            (set-frame-size frame 1876 1052 t))
          ((and
              (= 1280 (display-pixel-width))
              (= 723 (display-pixel-height)))
            (set-frame-size frame 1250 670 t))))
      ((and
          (eq system-type 'windows-nt)
          (equal (w32-version) '(6 1 7601)))
        (select-frame frame)
        (cond
          ((and
              (= 1920 (display-pixel-width))
              (= 1080 (display-pixel-height)))
            (set-frame-size frame 1890 1003 t))
          (t
            (message "Not yet contemplated.")))) )))
lawlist
  • 13,099
  • 3
  • 49
  • 158
5

Putting this into my ~/.emacs works for me (Emacs 24.5.1 on Debian GNU/Linux):

(toggle-frame-maximized)

To find that, I checked the name of the command called by the M-F10 shortcut with: C-h M-F10: it returned "toggle-frame-maximized", which I just call in my ~/.emacs.

Another solution, probably even better, found here:

(add-to-list 'initial-frame-alist '(fullscreen . maximized))

Community
  • 1
  • 1
user1735594
  • 437
  • 1
  • 6
  • 9
2

For some reason x-send-client-message was not working for me at some point (or not reliably, anyway). For that reason I use this:

(defun set-maximized ()
  (interactive)
  (shell-command "wmctrl -r :ACTIVE: -badd,maximized_vert,maximized_horz"))

To do that at startup:

(add-hook 'window-setup-hook 'set-maximized t)
Croad Langshan
  • 2,646
  • 3
  • 24
  • 37