Suspending Emacs
----------------
"Suspending Emacs" means stopping Emacs temporarily and returning
control to its superior process, which is usually the shell. This
allows you to resume editing later in the same Emacs process, with the
same buffers, the same kill ring, the same undo history, and so on. To
resume Emacs, use the appropriate command in the parent shell--most
likely `fg'.
Some operating systems do not support suspension of jobs; on these
systems, "suspension" actually creates a new shell temporarily as a
subprocess of Emacs. Then you would exit the shell to return to Emacs.
Suspension is not useful with window systems, because the Emacs job
may not have a parent that can resume it again, and in any case you can
give input to some other job such as a shell merely by moving to a
different window. Therefore, suspending is not allowed when Emacs is
using a window system (X or MS Windows).
- Function: suspend-emacs string
This function stops Emacs and returns control to the superior
process. If and when the superior process resumes Emacs,
`suspend-emacs' returns `nil' to its caller in Lisp.
If STRING is non-`nil', its characters are sent to be read as
terminal input by Emacs's superior shell. The characters in
STRING are not echoed by the superior shell; only the results
appear.
Before suspending, `suspend-emacs' runs the normal hook
`suspend-hook'.
After the user resumes Emacs, `suspend-emacs' runs the normal hook
`suspend-resume-hook'. Note:Hooks.
The next redisplay after resumption will redraw the entire screen,
unless the variable `no-redraw-on-reenter' is non-`nil' (Note:Refresh Screen).
In the following example, note that `pwd' is not echoed after
Emacs is suspended. But it is read and executed by the shell.
(suspend-emacs)
=> nil
(add-hook 'suspend-hook
(function (lambda ()
(or (y-or-n-p
"Really suspend? ")
(error "Suspend cancelled")))))
=> (lambda nil
(or (y-or-n-p "Really suspend? ")
(error "Suspend cancelled")))
(add-hook 'suspend-resume-hook
(function (lambda () (message "Resumed!"))))
=> (lambda nil (message "Resumed!"))
(suspend-emacs "pwd")
=> nil
---------- Buffer: Minibuffer ----------
Really suspend? y
---------- Buffer: Minibuffer ----------
---------- Parent Shell ----------
lewis@slug[23] % /user/lewis/manual
lewis@slug[24] % fg
---------- Echo Area ----------
Resumed!
- Variable: suspend-hook
This variable is a normal hook that Emacs runs before suspending.
- Variable: suspend-resume-hook
This variable is a normal hook that Emacs runs on resuming after a
suspension.