2

In my init.el file, I have some code to hide the Emacs toolbar:

;;; Hide the toolbar
(tool-bar-mode -1)

But when I load Emacs, it first enables the toolbar, and then quickly hides it, after it reads through my init.el file. This alone is a small annoyance. But my init.el file is getting pretty long. And now Emacs must go through a whole series of spastic corrections, every time it loads...

Is there a way to make Emacs process init.el before it launches the first frame?

I am on a Mac, running MacPorts Emacs, version 24.5.4.

0

3 Answers 3

3

Yes, run emacs --daemon and then open a frame via emacsclient

Check the command-line options for each executable.

e.g. You can use emacsclient -a '' -c to start the server (if necessary) and open a GUI frame, in a single command.

6
  • Thanks phils. Sorry, I probably should have specified that I am on a Mac, running the aqua version of Emacs from mac-ports (I just added this to the post). I tried running emacs --daemon from terminal but got an Unknown option --daemon message? Running emacsclient -a '' -c" from Terminal failed...
    – Adam
    Jul 20, 2016 at 9:03
  • I don't know anything about Aqua, but it's surprising to me if it doesn't support the normal command line options. What does emacs --version tell you? The --daemon option was added in GNU Emacs 23.1.
    – phils
    Jul 20, 2016 at 12:10
  • Okay, the version available from Terminal is 22.1.1. But this is what comes with OS X Yosemite. I installed the macports version separately, which launches like any other Mac app, with its own GUI...
    – Adam
    Jul 20, 2016 at 12:27
  • 1
    Do some searching for how to ensure you always use the right version of Emacs in OSX -- I think this is a common problem.
    – phils
    Jul 20, 2016 at 12:32
  • Assuming aquamacs is named Emacs.app and is installed in /Applications, the binary is in /Applications/Emacs.app/Contents/MacOS/Emacs. Adjust for your circumstances if necessary. Jul 20, 2016 at 14:48
1

By placing (tool-bar-mode -1) at the very top of .emacs or init.el, the toolbar will be removed before processing other user-configurations.

This solution/workaround was tested with Emacs version 24.5.1 (built --with-ns) from https://emacsformacosx.com/

[My eyes are unable to detect the presence of a toolbar while starting Emacs GUI using this method.]

15
  • Thanks. I tried this but could still see the jump. And this only gets compounded as the user add further customizations. What I was hoping for is some way to hide the GUI until after init.el is processed. I think of other apps that use a spash screen popup, which lets the user know that "it's working on it" but hides all the setup until it's ready...
    – Adam
    Jul 20, 2016 at 15:34
  • Do you have the function ns-hide-emacs in the MacPorts version of Emacs on your computer? If so, you may wish to try hiding/minimizing Emacs at the outset (top) of your .emacs / init.el and then unhide/activate the app at the very end of your .emacs / init.el. Here is the doc-string: "ns-hide-emacs is a built-in function in 'C source code'. (ns-hide-emacs ON) If ON is non-nil, the entire Emacs application is hidden. Otherwise if Emacs is hidden, it is unhidden. If ON is equal to ‘activate’, Emacs is unhidden and becomes the active application."
    – lawlist
    Jul 20, 2016 at 15:47
  • Actually, I just tried that and the frame is visible for a split second before hiding it. I'm going to leave that comment, so we have a record of what has been tried.
    – lawlist
    Jul 20, 2016 at 15:54
  • Brilliant! I couldn't get this to work though... tried (ns-hide-emacs) and (ns-hide-emacs t). Sorry - eLisp is not my forte. Hey, what about tying this to the emacs-startup-hook?
    – Adam
    Jul 20, 2016 at 15:59
  • The before-init-hook is too soon. The after-init-hook is too late. And the emacs-startup-hook is way way too late. :) I am curious as to why I cannot duplicate your issue with a bare-bones .emacs file that only contains (tool-bar-mode -1) using the version of Emacs from emacsformacosx.com I see the frame-title changing, and I see the buffers changing (with a scoll-bar being added) -- but I do not see the tool-bar.
    – lawlist
    Jul 20, 2016 at 16:04
1

Under X11 (i.e. mainstream Unix), you can set GUI-related parameters via X resources. To disable toolbars:

Emacs.toolBar: 0

This does not apply to a native Mac program. You can set some GUI parameters through user defaults (see examples of defaults write org.gnu.Emacs … in the Emacs Wiki), but I don't know if there's one about the toolbar.

Looking at the Emacs startup process, if you want to execute code before the initial frame is opened, you have a few choices. None of them are really intended to do what you want to do but it should work nonetheless. All of them involve changing a file in the directory which is on the load path before your init file runs. You can add load path directories by setting the environment variable EMACSLOADPATH. In one of those directories, edit or create subdirs.el and add the line

(setq tool-bar-mode 0)

This does not affect existing frames, but we're doing this before any frames are started, so I think it will work (but I haven't tested). It may help to also have

(setq default-frame-alist (cons '(tool-bar-lines . 0) default-frame-alist))
(setq initial-frame-alist (cons '(tool-bar-lines . 0) initial-frame-alist))

But rather than seek this, I would just start the Emacs daemon at session startup and then open windows in the existing session as needed.

4
  • Thanks Gilles! I was able to get this done by adding the following code to my /Applications/Emacs/MacOS/Resources/lisp/subdirs.el file: (add-to-list 'initial-frame-alist '(visibility . nil)) followed by (add-hook 'after-init-hook (lambda () (make-frame-visible))) . The one drawback to this is that, if emacs is ever updated, this code will be lost. I tried creating a subdirs.el file in /usr/local/share/emacs/site-lisp but this was not read... no idea why?
    – Adam
    Aug 1, 2016 at 17:05
  • @Adam Is this directory on the default load path? Run emacs -Q and check load-path Aug 1, 2016 at 17:16
  • Ah! No, it's not. Do you know if it's possible to add a directory to the load-path that will stick the next time Emacs loads? Thanks again!
    – Adam
    Aug 1, 2016 at 18:19
  • @Adam Normally you set load-path… but you have to modify a file that's already on the load path to do that! There may be some other path that's set up by the system files, check load-path in emacs -q (as opposed to emacs -Q). If you can't find a suitable location, you can set the environment variable EMACSLOADPATH. Aug 1, 2016 at 18:26

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.