How to maximize Emacs on Windows at startup?

It drives me crazy: I just want Emacs to maximize to whatever screen resolution I had at startup. Ideally, I like the cross-platform (Windows and Linux) solution that works at any screen resolution, but I can't even get it to work only with Windows XP with even hard-coded sizes.

Here is what I tried:

  • Setting the start-alist frame with the appropriate height / width
  • Setting the default-frame-alist
  • (Windows-specific stuff) Sending a message to emacs windows that tell it to maximize using (w32-send-sys-command 61488)
  • Tried this function, which I found somewhere:

     (defun toggle-fullscreen () "toggles whether the currently selected frame consumes the entire display or is decorated with a window border" (interactive) (let ((f (selected-frame))) (modify-frame-parameters f `((fullscreen . ,(if (eq nil (frame-parameter f 'fullscreen)) 'fullboth nil)))))) 
  • I tried the above methods both at the beginning and at the end of my initialization file, in order to try to eliminate interference from other init things.

Unfortunately, none of this works !! For some of the above, I see that my emacs windows change correctly for a second before returning to the small default size. And if I run the above methods after initialization, then emacs windows correctly resize. What is going on here in the world?

[ps there are other SO questions, but none of the answers work]




Update:

The answers make me think that something else in my initialization file is causing the problem. And really! After some attempts and mistakes, I found the culprit. If I commented on the following line, everything works fine:

 (tool-bar-mode -1) 

What does the toolbar do to maximize windows?

So now the question is: how do I turn off the toolbar (after all, the emacs toolbar is ugly and takes precious screen real estate) And maximize windows like in my initialization file? Perhaps the error is that the toolbar is blocking the size of the window?

Clarification: (tool-bar-mode -1) disables the toolbar, but this line interferes with maximizing Emacs windows. Therefore, if I try to put functions to maximize windows and disable the toolbar, the maximum part will not work; if part of the toolbar is commented out, then the maximization part will work fine. It doesn’t matter which solutions I use (among the 4 that I listed).




Solution: (or at least what works for me now)

This is probably a bug in Emacs. The workaround is to disable the toolbar through the registry, not in .emac. Save the following as a .reg file and execute this file in Windows Explorer:

 Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\GNU\Emacs] "Emacs.Toolbar"="-1" 

(This solution is a working version of what another Michael suggested).

+42
emacs elisp
May 2 '09 at 17:20
source share
15 answers

I found the answer after a year or so , which explains that you have to manipulate the registry in order to do everything right:

To run Emacs maximize, put this line at the end of your ~ / .emacs file:

 (w32-send-sys-command 61488) 

If you do not want the Emacs toolbar you can add the line (tool-bar-mode -1) [NOTE: the value is 0 on the original page] to the ~ / .emacs file, but Emacs will not fully maximize in this case - the real one toolbar real estate lost. You must disable the toolbar in the registry in order to return it:

 [HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs\Emacs.Toolbar] @="0" 

If you look in EmacsWiki under the W32SendSys command codes , you will find that 61488 maximizes the current frame

+25
May 04 '09 at
source share
β€” -

This is the simplest fix that worked for me:

 (w32-send-sys-command #xf030) (add-hook 'window-setup-hook (lambda () (tool-bar-mode -1))) 
+12
Jan 02 2018-10-10T00: 00-01-01 at
source share

Dudes what's wrong with

emacs -mm ?

This allows Emacs to fully maximize. Put it in your shortcut, it really depends on the window manager you are using; I myself am just his pseudonym . * Shrc .

In another, but unrelated note, I actually start Emacs in such a way that if it is already running, the selected file simply opens as a new buffer in my existing Emacs session:

 if [ "$(pidof emacs)" ] ; then emacsclient "$@" else emacs -mm "$@" fi 

I put this in ~ / bin / e, and I just start Emacs with "e". I right-clicked on a text file in the file manager, selecting β€œopen with another program” and entered β€œe”, and now I just double-click the files and they all open neatly in the same session.

And all the peach and lispy :)

+11
Feb 23 '12 at 18:24
source share

On X.org, a system call (since you first asked for a cross-platform solution):

 (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))) 
+10
Jun 22 '09 at 19:44
source share

First, thanks for the error hint with (tool-bar-mode -1); saved me a lot of trouble! I would rather save everything in a .emacs file (there are no registry mods for me), so if you turn on the toolbar before maximizing it and then turn it off again, you can do it most efficiently:

 (defun maximize-current-frame () "Resizes the current frame to fill the screen" (interactive) ;; There is a bug in tool-bar-mode that prevents it from being ;; maximized, so turn it on before maximizing. ;; See http://stackoverflow.com/questions/815239/how-to-maximize-emacs-on-windows-at-startup) (tool-bar-mode 1) (w32-send-sys-command 61488) (tool-bar-mode -1) ) 
+3
Nov 25 '09 at 0:33
source share

Another way to solve this problem is to delay between

 (menu-bar-mode -1) (tool-bar-mode -1) (tooltip-mode -1) (scroll-bar-mode 1) 

and set-frame- *. For example:

  (tool-bar-mode -1) (when window-system (run-at-time (format "%d sec" 1) nil '(lambda () (set-frame-position (selected-frame) 1 1))) (run-at-time (format "%d sec" 2) nil '(lambda () (set-frame-width (selected-frame) 150 t))) (run-at-time (format "%d sec" 3) nil '(lambda () (set-frame-height (selected-frame) 60 t))) ) 

It is also important to set the delay between set-frame- * functions!

+2
Sep 14 '09 at 13:44
source share

This works reliably on Emacs 24.5.1 (i686-pc-mingw32) :

 (add-to-list 'initial-frame-alist '(fullscreen . maximized)) 
+2
05 Oct '15 at 21:29
source share

Hey, nice feature! Thanks for posting.

I think this may not work for you, because you have code that looks like following somewhere else in your initialization file. The default-frame-alist attribute is used after the frame is created. I removed the elements of size and position and you are working fine when loading emacs.

  (setq default-frame-alist (list (cons 'left 350) (cons 'top 0) (cons 'width 80) (cons 'height 45) ...... 
+1
May 02 '09 at 19:48
source share

If you really want to start Emacs full screen mode without a window chronometer (title bar and max / min / close button), try the following mode. This worked for me with Emacs 23.3.1 on XP SP3.

http://www.martyn.se/code/emacs/darkroom-mode/

+1
May 10 '11 at 14:25
source share

everyone. emacs 23.3.1, the error code is invalid. because (menu-bar-mode -1) can cause windows to not be in full screen mode.

 (w32-send-sys-command #xf030) (add-hook 'window-setup-hook (lambda () (tool-bar-mode -1))) 

I am looking for a Wiki Eamcs, I will find a useful method.

http://www.emacswiki.org/emacs/FullScreen#toc3

MS Windows

If you are using MS Windows and want to use "real full-screen mode", i.e. getting rid of the top header and all, see w32-fullscreen on the site for dark room mode

In addition, a patch is available here that makes a full-screen frame truly full-screen on Windows.

To get the maximized window, you can use: (w32-send-sys-command # xf030)

Attention! If you want emacs to run as much as possible, you should put this code in your .emacs file:

 (defun jbr-init () "Called from term-setup-hook after the default terminal setup is done or directly from startup if term-setup-hook not used. The value 0xF030 is the command for maximizing a window." (interactive) (w32-send-sys-command #xf030) (ecb-redraw-layout) (calendar) ) (setq term-setup-hook 'jbr-init) (setq window-setup-hook 'jbr-init) 
+1
May 12 '11 at 2:08
source share

I came across one command that works (toggle-frame-maximized) , which works on both Linux and Windows.

I simply put this at the end of my initialization file after setting everything up, making the assumption that by the end of the setting everything would not be maximized, and voila works.

+1
Sep 10 '15 at 3:22
source share
 (defun resize-frame () "Set size" (interactive) (set-frame-width (selected-frame) 110) (set-frame-height (selected-frame) 33) (set-frame-position (selected-frame) 0 1)) 

the following is the last function, called in my .emacs files, sets the height and width of the screen on which it works on both emacs 22 and emacs 23 on debian and mac os x. Set the height and width to suit your screen.

0
May 2 '09 at 19:48
source share

To disable the toolbar, add the line

 (tool-bar-mode nil) 

to your configuration file (usually .emacs in the root directory).

0
May 04 '09 at 2:40
source share

emacs-full-screen-win32 will help you :)

0
Oct 19 '11 at 9:22
source share

The following snippet from emacswiki worked fine for me: (add to startup config file)

 (defun jbr-init () "Called from term-setup-hook after the default terminal setup is done or directly from startup if term-setup-hook not used. The value 0xF030 is the command for maximizing a window." (interactive) (w32-send-sys-command #xf030) (ecb-redraw-layout) (calendar) ) (setq term-setup-hook 'jbr-init) (setq window-setup-hook 'jbr-init) 
0
Jun 20 '13 at 9:06 on
source share



All Articles