0

I've noticed some people use this to disable the menu bar in the GUI:

(push '(menu-bar-lines . 0) default-frame-alist)

and some people use this:

(menu-bar-mode -1)

Both achieve the same. The first seems to append a list '(menu-bar-lines . 0) to the default-frame-alist variable.

I was wondering which approach is better to use. The first or the second one? or it doesn't matter.

1
  • The main problem with push is that it doesn't check that whatever it pushes is not already on the list (or whether it conflicts with something on the list). If you are sure that that's not the case, go ahead and push. OTOH, calling menu-bar-mode is safer precisely because it checks such things. And it may be the case that even if you push a duplicate (or conflicting) entry, nothing bad happens. The question is: how comfortable are you taking that risk - and that's a question only you can answer. What @lawlist's answer provides is a best practice: you can follow it - or not.
    – NickD
    Mar 12 at 18:54

1 Answer 1

1

push prepends, rather than appends. push should not be used in this context because it does not remove or replace an existing element of the default-frame-alist with the parameter menu-bar-lines. Type M-x find-function RET menu-bar-mode RET to see how menu-bar-mode works when activated and deactivated. Use (menu-bar-mode -1) to deactivate.

7
  • Thank you. What if I decide to maximize the Emacs frame during startup with (push '(fullscreen . maximized) default-frame-alist) can the push be used in that situation?
    – Zoli
    Mar 12 at 14:43
  • I have these in early-init.el. I can set it with (set-frame-parameter nil 'fullscreen 'maximized) but I still don't know if it's the proper way of doing it.
    – Zoli
    Mar 12 at 16:56
  • Thank you. You helped me a lot. I set the frame value to nil in (set-frame-parameter nil 'fullscreen 'maximized) and I'm not sure if it's good or not. Even though it seems to me that all new frames are in full-screen which is what I want.
    – Zoli
    Mar 12 at 17:07
  • I created the early-init-file at ~/.emacs.d/early-init.el and placed the following snippet at the top of the file: (message "%s | %s" (selected-frame) default-frame-alist). Then, I launched Emacs 28.2 and checked the *Messages* buffer and saw that the default-frame-alist has a nil value at this particular stage of the startup process. Because there is no pre-existing element containing the fullscreen parameter, I determined that it is now safe to use push. E.g., (push '(fullscreen . maximized) default-frame-alist). set-frame-parameter is used for a particular frame.
    – lawlist
    Mar 12 at 17:32
  • then push is okay with menu-bar-lines as well when inside early-init.el. Right?
    – Zoli
    Mar 12 at 17:40

Your Answer

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

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