How to maximize Emacs on Windows at startup?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 17:11:49

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

This is the simplest fix that worked for me:

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

Dudes, what's wrong with

emacs -mm ?

This starts Emacs fully maximized. Put it in your shortcut, it really depends on the window manager you use ; I myself just alias it in my .*shrc.

On a different but not unrelated note, I in fact start Emacs in a way that if it's already started, the selected file is just opened as a new buffer in my existing Emacs session :

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

This I put in a ~/bin/e and I just launch Emacs with "e". I right-clicked a text file in the file manager, selected "open with another program" and entered "e", and now I just double click files and they all open neatly in the same session.

And everything is peachy and lispy :)

On X.org the system call is (since you asked originally 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)))

First, thanks for the tip on the bug with (tool-bar-mode -1); saved me a lot of trouble! I'd rather keep everything within the .emacs file (no registry mods for me), so if you turn on the toolbar before maximizing, and then turn it off again, you'll can maximize nicely:

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

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

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

Another way to resolve such problem is put delay between

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

and set-frame-* functions. 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 essential to put delay between set-frame-* functions also!

tariqk

I encountered one command that seems to work (toggle-frame-maximized), which works on both Linux & Windows.

I just put that near the end of my init file after setting up everything, making the assumption that by the end of the setup everything won't be maximized, and voila, it works.

Hey - nice function! Thanks for posting

I think it may not be working for you because you have code that looks like the following somewhere else in your init file. The default-frame-alist is being applied after the frame is created. I removed the size and position elements and you function works great on bootup of emacs.

   (setq default-frame-alist
     (list
      (cons 'left                 350)
      (cons 'top                  0)
      (cons 'width                80)
      (cons 'height               45)
     ......

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

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

every one. emacs 23.3.1,blow code is invalid. because (menu-bar-mode -1) can cause windows not full-screen too.

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

I search Eamcs wiki,find a useable method.

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

MS Windows

If you’re using MS Windows, and want to use “real fullscreen”, i.e, getting rid of the top titlebar and all, see w32-fullscreen at the site for darkroom-mode

Alternatively, a patch is available here that makes the fullscreen frame parameter really fullscreen on Windows.

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

Attention! If you want that emacs starts maximized, you have to put this code into 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)
(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))

following is the last function called in my .emacs files it sets the height and width of the screen it does work on both emacs 22 and emacs 23 on debian and mac os x. set the height and width numbers according to your screen.

To disable the toolbar, add the line

(tool-bar-mode nil)

to your customization file (usually .emacs in your root directory).

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

The following snippet from emacswiki worked fine from me: (add to your 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)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!