93

Is there a way to maximize my window on start-up?

Currently, I hit Control+Windows Key+Up on my keyboard but it is very bothersome to do that every time.

I am using Emacs 24.4 on Ubuntu 12.04.

Dan
  • 32,584
  • 6
  • 98
  • 168
programking
  • 7,064
  • 9
  • 41
  • 62
  • 2
    I did not know the key combination to maximize emacs. Thanks for that and also the answer below worked out! – Prasanna May 10 '16 at 14:17
  • 1
    From where did you find out the combination `![Windows Key][oldwinlogo]` This does not work for me :-( – Prasanna May 10 '16 at 14:19
  • To circumvent the problem, one could use desktop-save-mode, so that you set your favorite frame sizes once and they are reproduced in the next emacs session automatically. – Alsk Jan 12 '22 at 22:36

6 Answers6

115

I have another method, which I have tested with Emacs 24.3 and 24.4, as well as on both Windows and GNU/Linux. I have placed the following in my init file:

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

I believe this was modified slightly from a StackOverflow answer I found a while ago, but I can't seem to find it again now.

Edit: Another bonus of this method is that it also applies to new clients that connect to your Emacs server (with e.g. emacsclient -c).

Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
  • 4
    +1 for the precise answer. If I could accept this as answer again - I really would! – Prasanna May 10 '16 at 14:18
  • 1
    I like this solution using `emacsclient`, but there are some frames that starting them maximized would prevent to use them correctly, like the **ediff control panel**, is there a workaround for this? – marcanuy Jun 19 '17 at 01:03
  • @marcanuy: I don't know of a solution off the top of my head, but it might be worth posting a new question for that. – Scott Weldon Jun 20 '17 at 22:59
  • 3
    @marcanuy You can use `initial-frame-alist`. Like the name implies, this will only maximize the initial frame. – clemera Nov 23 '19 at 13:13
44

Adjust the ...-frame-alist in your init file to tell Emacs how to maximize the frame. You also have multiple options for how, exactly, to maximize it.

alist options

You have two ...-frame-alist options:

  1. default-frame-alist (as in @Scott Weldon's answer)
  2. initial-frame-alist

If you use default-frame-alist, it will maximize all frames: both the first one and any others you create. That may not be what you want (or maybe it is: who am I to judge?).

If you use initial-frame-alist, it will maximize only the frame that Emacs creates at startup, but will not touch any subsequent frames you create.

maximization options

For your maximization options, see this node of the manual for details. The short version is that you can set the fullscreen parameter to:

  • fullwidth (make the frame as wide as possible, don't touch the vertical)
  • fullheight (make the frame as tall as possible, don't touch the horizontal)
  • fullboth (set height and width to to size of the screen)
  • maximized (make it, well, maximized)

The difference between fullboth and maximized is that you can resize the former with the mouse, while with the latter you cannot.

example

So, for example, these lines will 1) create a maximized initial frame, and 2) create fullheight (but not fullwidth) frames on every subsequent frame:

(add-to-list 'initial-frame-alist '(fullscreen . maximized))
(add-to-list 'default-frame-alist '(fullscreen . fullheight))
Dan
  • 32,584
  • 6
  • 98
  • 168
  • 5
    Indeed `initial-frame-alist` is much more useful than `default-frame-alist` when one uses tools like ediff. – giordano Nov 12 '14 at 00:17
  • `(add-to-list 'default-frame-alist '(fullscreen . maximized))` is not the best answer. I confirm what another answer said (Dan): `(add-to-list 'initial-frame-alist '(fullscreen . maximized))` is the way to have this work well. – francogrex Nov 23 '19 at 10:27
35

On Emacs 24.4, (toggle-frame-maximized) toggles the maximized state of the current frame.

See also, the Maximize Emacs on start up question on stackoverflow and the Full Screen page on the EmacsWiki.

Constantine
  • 9,072
  • 1
  • 34
  • 49
16

To startup Emacs maximised, add to your init file:

;; Start maximised (cross-platf)
(add-hook 'window-setup-hook 'toggle-frame-maximized t)

In case you want to go full screen or, as they say now, distraction free mode:

;; Start fullscreen (cross-platf)
(add-hook 'window-setup-hook 'toggle-frame-fullscreen t)

NOTE: This works in Windows too.

tarsius
  • 25,298
  • 4
  • 69
  • 109
antonio
  • 1,762
  • 12
  • 24
  • Finally! The `t` argument to `add-hook` (to make `toggle-frame-fullscreen` run last, not first) was the missing ingredient for me that made it work. – Lassi Mar 29 '20 at 12:18
12

@Constantine's answer already covers how this can be achieved by modifying your init-file (if you use Emacs 24.4).

If you start Emacs from the command line, from the dash, or from a launcher like Synapse or krunner, you can specify the -mm option (short for --maximized) to achieve the same result:

emacs -mm

The -mm option was first introduced in Emacs 23.2, so this solution is not limited to the latest stable release.


What distinguishes this solution from other suggestions posted here (all of which are great) is that it allows you to decide on a case-by-case basis whether you want the Emacs frame maximized at start-up or not.

If you want a more permanent solution, you can set up an alias for the command shown above by adding the following to your .bashrc:

alias emacs='emacs -mm'
itsjeyd
  • 14,586
  • 3
  • 58
  • 87
  • 2
    Another benefit of this solution is that emacs starts already maximized. Init file workarounds make it switch to maximized during the startup, which is kind of annoying. – and Jul 23 '15 at 08:48
  • 1
    To add to this answer: `emacs -fs` starts Emacs maximized to the full screen, or maximally maximized to the max. – Teemu Leisti Jun 08 '18 at 10:54
1

I'm using the following:

(when (eq system-type 'gnu/linux)
  (defun x11-maximize-frame ()
    "Maximize the current frame (to full screen)"
    (interactive)
    (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
    (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
  (run-with-idle-timer 0.01 nil 'x11-maximize-frame)
  )

(when (eq system-type 'windows-nt)
  (w32-send-sys-command 61488)
)
Adobe
  • 1,859
  • 13
  • 27