I want a keyboard shortcut to open emacs in a maximised window. I tried emacs --fullscreen, but that is full screen rather than maximised window... That is, the emacs window covers ubuntu menu bars. emacs -fw gets a full width window and emacs -fh gets a full height window, but if you put both options, it only reads the second one. At the moment, I just have another keyboard shortcut for maximising a window. Is there a way to get emacs to start maximised?

Ubuntu 9.10, emacs 22, if that makes a difference.

up vote 3 down vote accepted

I have this in my .emacs, which I then bind to a key:

(defun my-frame-toggle ()
  "Maximize/Restore Emacs frame using 'wmctrl'."
  (interactive)
  (shell-command "wmctrl -r :ACTIVE: -btoggle,maximized_vert,maximized_horz"))

(global-set-key [(control f4)] 'my-frame-toggle)

You can then hit CtrlF4 and toggle between regular and full-screen (but not covering the Ubuntu menu bar and bar at the bottom of the screen whose name I'm blanking on at the moment). To start up that way simply invoke it:

$ emacs -e "my-frame-toggle"

I had the same problem. Found the answer in this thread: http://ubuntuforums.org/showthread.php?t=1619533

Basically from the command line start emacs with this parameters:

  • emacs -fs //if you want emacs to cover all your screen (cover the ubuntu bar)
  • emacs -mm //if you want emacs to start like you pressed the maximize button (shows ubuntu bar)

Of course you can bind those starting options to an icon and have emacs always start the way you want.

  • Superb! emacs -fs works perfectly in Ubuntu 12.10 – Chris McCauley Dec 5 '12 at 14:52

I have the following functions in my .emacs, which first defines the codes to send the window manager to maximize the frame on X.org and Win32 respectively, and then add this as a setup hook, if applicable:

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

(defun w32-maximize-frame ()
  "Maximize the current frame (to full screen)"
  (interactive)
  (w32-send-sys-command 61488))

(defun maximize-frame ()
    (if (eq window-system 'w32)
            (w32-maximize-frame)
        (x-maximize-frame)))

(if window-system
    (add-hook 'window-setup-hook 'maximize-frame t))

This might be what you're looking for. You could also hard-code the pixel width/height for your screen, and set that in your .emacs file (the author covers that here).

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.