14

I am using the mac emacs from http://emacsformacosx.com/, and I need to click the maximized icon when I start my emacs.

How can I set the maximized emacs window as default?

6
  • 1
    Have you tried looking on the Emacs Wiki, e.g. emacswiki.org/emacs/FullScreen#toc18 and emacswiki.org/emacs/EmacsForMacOS#toc27? They may or may not be out of date, I don't have a Mac so I can't test this. Commented Feb 12, 2012 at 13:39
  • I've had considerable trouble with the Emacs distribution available from emacsforosx.com; today I built a fresh Emacs from this version that's been thoroughly patched for OS X, and have found much better results, including proper OS X fullscreen support. Hope this helps! Commented Aug 9, 2013 at 20:06
  • @Eric Fail -- The problem with adding an OSX tag is that those people know nothing about Emacs and tend to down-vote and vote to close because they are the wrong target audience.
    – lawlist
    Commented Aug 22, 2014 at 7:02
  • @lawlist, I'm not sure I fully understand the issue. Could you expand on it?
    – Eric Fail
    Commented Aug 22, 2014 at 7:57
  • @Eric Fail -- I've just had bad experiences with broad topic tags where forum participants quickly down-vote and vote to close. Many people either subscribe to specific tags of interest, or bookmark a favorite tag and monitor the new activity. My own personal belief if that many people who monitor the OSX tag could care less about how to maximize an Emacs frame. Most forum participants with a high reputation will simply remove the tag without saying anything, so I'll leave it up to them if they feel strongly about it. It's not a really big deal to me, I just wanted to let you.
    – lawlist
    Commented Aug 22, 2014 at 16:13

5 Answers 5

9

start emacs like this

emacs -mm
8

Ryan McGeary's maxframe.el works well for me on both Aquamacs and Emacs.app. I found it through EmacsWiki: http://www.emacswiki.org/emacs/FullScreen . That page talks about a patched version which is now a 404 page, but the original one at https://github.com/rmm5t/maxframe.el seems to work fine.

6
  • Do you actually get full maximized coverage as you do for a non-emacs windows. I only get the window expanding up to a multiple of full-character widths and heights of my default mono-space font. On my (Ubuntu/GNU Emacs 23.1.1) system, this leaves an approximately half a character wide border on the RHS and Bottom.. The only way I can fully expand the window is via the window-manager's system menu's maximize option (in top left corner)
    – Peter.O
    Commented Feb 13, 2012 at 4:10
  • PS: I found another SO answer which has a method which works for my Linux X-Windows system: maximize emacs on start up?(not the fullscreen) .... Cancel that!!, it doesn't work.. it maximizes the vertical too much... But, the two methods together do work (strange... maybe one day I'll work out why?.... but it now works (after month's of it bugging me! ... Thanks for the maxframe suggestion Jon O.
    – Peter.O
    Commented Feb 13, 2012 at 4:45
  • 1
    You can get maxframe through the emacs package manager and Melpa as well. Commented Oct 26, 2012 at 17:32
  • @Arkell sorry but you cannot do this on emacs 24 (emacsformacos)...maxframe nor Melpa (whatever that is) do not show up in the emacs package manager
    – thefonso
    Commented Nov 1, 2012 at 5:05
  • @Peter.O Hello, I have the similar problem: superuser.com/questions/584755/… Could you share your working code there?
    – user4035
    Commented Apr 20, 2013 at 6:22
8

Here is a function written and used by me. When you succesivelly press F11, emacs switches in 4 modes:

(defun switch-fullscreen nil
  (interactive)
  (let* ((modes '(nil fullboth fullwidth fullheight))
         (cm (cdr (assoc 'fullscreen (frame-parameters) ) ) )
         (next (cadr (member cm modes) ) ) )
    (modify-frame-parameters
     (selected-frame)
     (list (cons 'fullscreen next)))))

(define-key global-map [f11] 'switch-fullscreen)
5
  • This works fine for me, except for one annoyance. When I reach the fullboth mode, the frame overtakes everything on the screen; that is, the WM window title bar disappears, and the my XFCE panel also disappears behind the window (I'm using Xubuntu). The fullheight mode works correctly: the frame uses only the vertical space that the XFCE panel leaves available for it. I'd like the fullboth mode to work as if I'd maximized the WM window by pressing the + button in the title bar. Any idea how that might be accomplished? Commented Oct 16, 2012 at 9:24
  • this is a bug in gtk , not in emacs . please report it to the gtk developers.
    – alinsoar
    Commented Oct 18, 2012 at 14:43
  • fullboth is a misnomer. It makes Emacs go fullscreen in normal Mac lingo. maximized makes it full-both!
    – trss
    Commented May 1, 2013 at 14:48
  • When I wrote the code in 2006 or 2007 it was fullboth: read here emacswiki.org/emacs/FullScreen#toc16
    – alinsoar
    Commented May 3, 2013 at 11:28
  • In fact, I tested it only on X server.
    – alinsoar
    Commented Jun 17, 2013 at 17:38
6

The short answer is to add the following to your custom-set-variables:-

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 ...
 '(initial-frame-alist (quote ((fullscreen . maximized))))
 ...
 )

Given below is what I wanted as a solution to the same problem. TL;DR.

I face the same problem but in all applications and not just in Emacs. To this end, I have globally bound the shortcut key cmd-m on my Mac to the Zoom menu option which is usually the menu option for the green maximize button. Emacs however doesn't provide the Zoom menu option which is usually under the Window menu item. So I ended up with the following.

I just coded up the following last night.

;; This defines cmd-m to do the same as clicking the green titlebar button
;; usually meant for the "Window -> Zoom" menu option in Mac apps
(defun zoom () "zoom, same as clicking the green titlebar button in Mac app windows"
  (interactive)
  (set-frame-parameter
   nil 'fullscreen
   (pcase (frame-parameter nil 'fullscreen)
     (`nil 'fullheight)
     (`fullheight 'maximized)
     (`fullboth (ding) 'fullboth)
     (`fullscreen (ding) 'fullscreen)
     (_ nil))))
(global-set-key (kbd "s-m") 'zoom)

This keyboard shortcut in the last line of the code goes well with my global to Mac cmd+m key binding that I described initially. You could customize it to whatever suits you. I am used to pressing cmd-m on launching most apps until it fits screen and Emacs is one of them for me. So I don't bother with the initial-frame-alist setting.

I went on to complete the feature-set I wanted by adding the following code tonight.

;; This defines ctrl-cmd-f to do the same as clicking the toggle-fullscreen titlebar
;; icon usually meant for the "View -> Enter/Exit Full Screen" menu option in
;; Mac apps
(defun toggle-fullscreen() "toggle-fullscreen, same as clicking the
 corresponding titlebar icon in the right hand corner of Mac app windows"
  (interactive)
  (set-frame-parameter
   nil 'fullscreen
   (pcase (frame-parameter nil 'fullscreen)
     (`fullboth nil)
     (`fullscreen nil)
     (_ 'fullscreen))))
(global-set-key (kbd "C-s-f") 'toggle-fullscreen)
; For some weird reason C-s-f only means right cmd key!
(global-set-key (kbd "<C-s-268632070>") 'toggle-fullscreen)

A couple of notes:-

  1. If you're just learning to use pcase from this code, be careful not to make the same mistake as I did by misreading the backquote as a quote in the docs.
  2. fullscreen is an alias to fullboth and is not a misnomer like the latter is as a term for what it means and hence I have not only handled that case as a value for (frame-parameter nil 'fullscreen) but use that whenever I want to set-frame-parameter to fullboth

HTH

1

The answer given at https://stackoverflow.com/a/1029065/351716 works for me (with GNU Emacs v24.2.1). To reprise, define the following function in your .emacs file:

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

For convenience, you can bind the command to a key. I use the C-z key, which would otherwise minimize the frame, which I have no need for, but always find annoying when I hit it accidentally:

(global-set-key (kbd "C-z") 'x11-maximize-frame)

As I noted in the comment I added to that answer, using this command repeatedly cycles between the normal frame state and the maximized state, but one little annoyance: in between those two, there's a strange state where the frame is almost but not quite vertically maximized. But that's a minor problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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