How to run a new instance of emacs from within emacs

It turns out that ourcomments-util.el, which is bundled with EmacsW32, already contains a command to start a new emacs instance and some variant commands as well. These are the commands:

M-x emacs
M-x emacs--debug-init
M-x emacs-Q
M-x emacs-Q-nxhtml

For those of you who do not use ourcomments-util.el, use this:

(defun emacs-JY (&rest args)
  "Start a new Emacs."
  (interactive (list "-q" "--no-splash"))
  (let ((emacs-full-path (locate-file invocation-name (list invocation-directory) exec-suffixes))
 	(args-text (mapconcat 'identity (cons "" args) " "))
    (setq ret (apply 'call-process emacs-full-path nil 0 nil args))
    (message "Started 'emacs%s' => %s" args-text ret)

Interactively, it just runs emacs -q --no-splash. The following commands are also useful.

(defun emacs-q-load-JY (filename)
  "emacs -q --no-splash --debug-init --load FILENAME"
  (interactive "fFile to Load: ")
  (apply 'emacs-JY "-q" "--no-splash" "--debug-init" "--load" filename nil)
(defun emacs-q-load-region-JY (beg end)
  (interactive "r")
  (write-region beg end "~/.emacs.d/part-to-load.el")
  (emacs-q-load-JY "~/.emacs.d/part-to-load.el")

The last command is probably the most useful. It evaluates the region in a separate instance of Emacs.

This entry was posted in Emacs and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s