TransWikia.com

How to pass an optional agrument to kill-emacs?

Emacs Asked by ianinini on September 2, 2021

I would like a way to make emacs to return a non-zero exit code when exiting.

This page https://www.gnu.org/software/emacs/manual/html_node/elisp/Killing-Emacs.html lists the command

kill-emacs &optional exit-data

as a mechanism for making emacs return with non-zero return code, stating "If exit-data is an integer, that is used as the exit status of the Emacs process".

How do I add this optional exit-data?

I have tried:

  • Interactively using M-x kill-emacs but cannot type a space after that.
  • Setting up a binding in my init.el using (global-set-key (kbd "C-x C-M-c") 'kill-emacs), but do not know the syntax well enough to pass an argument.

I see this is related to How to set the exit status for emacsclient and How to make emacs or emacsclient exit with nonzero return code? , but I cannot get the answer I want from those questions/answers.

Please can someone explain how to quit emacs with a non-zero return code and/or provide the syntax to setup a keyboard binding.

One Answer

Interactively, you can use a prefix argument.

E.g.:

  • $ emacs -Q
  • M-7 M-x kill-emacs RET
  • $ echo $?
    => 7

A command to do this, which you could bind to a key sequence, would be:

(defun my-kill-emacs ()
  (interactive)
  "Exit emacs with status 7."
  (kill-emacs 7))

Correct answer by phils on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP