Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maximize Emacs on Windows at startup?

Tags:

emacs

elisp

This is driving me crazy: I simply want Emacs to maximize to whatever screen resolution I have at startup. Ideally I like a cross-platform (Windows & Linux) solution that works on any screen resolution, but I can't even get it to work on just Window XP with even hard-coded sizes.

Here are what I tried:

  1. Setting the initial-frame-alist with appropriate height/width
  2. Setting the default-frame-alist
  3. (Windows specific stuff) Sending message to the emacs windows telling it to maximize via (w32-send-sys-command 61488)
  4. 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)))))) 
  5. Tried the above methods in both beginning and end of my init file to try to eliminate interference from other init things.

Unfortunately, none of the above works!! For some of the above, I can see my emacs windows resizes correctly for a split second before reverting back to the smallish default size. And if I run the methods above after the initialization, the emacs windows DOES resize correctly. What in the world is going on here?

[p.s. there are other SO questions on this but none of the answers work]


Update:

The answers make me think that something else in my init file is causing the problem. And indeed it is! After some try-and-error, I found the culprit. If I commented out the following line, everything works perfectly:

(tool-bar-mode -1) 

What in the world does the toolbar have to do with maximizing windows?

So the question now is: how can I disable toolbar (after all, emacs's toolbar is ugly and takes up precious screen real-estate) AND maximize the windows both in my init file? It is possibly a bug that toolbar interferes with the windows size?

Clarification: (tool-bar-mode -1) turns the toolbar off, but this line interferes with maximizing the Emacs windows. So if I try put functions to maximize windows and turn off the toolbar, the maximize part will fail; if the toolbar part is commented out, then the maximize part will work ok. It does not even matter what solutions I use (among the 4 that I listed).


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

This is probably a bug in Emacs. The workaround is to disable the toolbar through the Registry, not in .emacs. Save the following as a .reg file, and execute that 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 OtherMichael suggested).

like image 489
polyglot Avatar asked May 02 '09 17:05

polyglot


People also ask

How do I get Emacs to open full screen?

Now run Emacs and press F11 to switch into full-screen mode. Press F11 again to switch to windowed mode.

What is a window in Emacs?

A window is an area of the screen that can be used to display a buffer (see Buffers). Windows are grouped into frames (see Frames). Each frame contains at least one window; the user can subdivide a frame into multiple, non-overlapping windows to view several buffers at once.


2 Answers

I found an answer a year-or-so back that explains you have to manipulate the registry to do things right:

To start Emacs maximized put this line at the end of your ~/.emacs file:

(w32-send-sys-command 61488) 

If you don't want the Emacs tool bar you can add the line (tool-bar-mode -1) [NOTE: value is 0 on original page] to your ~/.emacs file but Emacs won't fully maximize in this case - the real estate occupied by the tool bar is lost. You have to disable the tool bar in the registry to get it back:

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

If you look in the EmacsWiki under W32SendSys command-codes you'll find that 61488 is maximize current frame

like image 125
Michael Paulukonis Avatar answered Sep 19 '22 19:09

Michael Paulukonis


This is the simplest fix that worked for me:

(w32-send-sys-command #xf030) (add-hook 'window-setup-hook (lambda () (tool-bar-mode -1))) 
like image 24
Kenny Jensen Avatar answered Sep 19 '22 19:09

Kenny Jensen