Hot answers tagged

22

Set the variable confirm-kill-emacs to something like yes-or-no-p.


11

You can use kill-emacs-hook which is run when emacs is quit 'normally'. Hook run when kill-emacs is called. Since kill-emacs may be invoked when the terminal is disconnected (or in other similar situations), functions placed on this hook should not expect to be able to interact with the user. To ask for confirmation, see kill-emacs-query-...


7

You can use this to exit from your init file: (with-current-buffer " *load*" (goto-char (point-max))) Emacs uses the load function to execute lisp file through a temporary buffer, that's " *load*", if the name is not already taken. The above code moves the point to the end of the buffer, thus the read function will not read further code. For example, ...


6

I use this, which workds in all Emacs versions: (add-hook 'kill-emacs-query-functions (lambda () (y-or-n-p "Do you really want to exit Emacs? ")) 'append)


6

A common alternative is to unbind the key using (global-unset-key (kbd "C-x C-c")) You can always quit via M-x save-buffers-kill-terminal


6

This is explained in the manual here: C-hig (emacs)emacsclient Options RET The new graphical or text terminal frames created by the ‘-c’ or ‘-t’ options are considered “client frames”. Any new frame that you create from a client frame is also considered a client frame. If you type ‘C-x C-c’ (‘save-buffers-kill-terminal’) in a client frame, that ...


6

C-x C-c is for Kill Emacs (save-buffers-kill-terminal). Maybe on other systems you are using emacsclient, then C-x C-c behaves specially if you are using Emacs as a server. If you type it from a client frame, it closes the client connection. Or maybe you run multiple instances of Emacs? To close only one frame use C-x 5 0 or s-w. This command delete ...


4

This is a commonly asked question. It might be a duplicate here (dunno). There are various tweaks or libraries that some users use to provide what you are asking - you will likely get some answers pointing to them. But my suggestion is to not use *scratch* the way you are using it - maybe not use it at all. Instead, use C-x C-f foo.el or whatever, which ...


4

@Harald answered your question. But I would not say "unfortunately". This is by design. Buffer *scratch* is designed for what its name suggests and its initial contents describe: It is a scratchpad, for throwaway content. If you use it for some other purpose then you are misusing it. But of course you might want a scratchpad that is automatically backed ...


3

Emacs 26.1 added the confirm-kill-processes variable. To disable conformation to kill processes on Emacs exit, add to your init file: (setq confirm-kill-processes nil) Documentation: Non-nil if Emacs should confirm killing processes on exit. If this variable is nil, the value of process-query-on-exit-flag is ignored. Otherwise, if there are processes ...


3

Following my own suggestion (second comment on the question), here's an answer which avoids the prompting altogether: (require 'auto-answer) (let ((auto-answer '(("\\`Active processes exist; kill them and exit anyway\\? \\'" t)))) (save-buffers-kill-emacs)) This uses auto-answer.el, available at https://github.com/YoungFrog/auto-answer/blob/master/...


3

here's solution, shorting @abo-abo's answer. (cond ((string-equal system-type "windows-nt") ; Windows // ... ) ((string-equal system-type "gnu/linux") (start-process "my-browse" nil "setsid" "firefox" (concat "file://" buffer-file-name )) ;; (browse-url ξurl) ...


3

I use the following in my init file to solve exactly this problem. I probably cribbed this from somewhere myself but it's been so long I can't remember the source. (defun my/org-clock-query-out () "Ask the user before clocking out. This is a useful function for adding to `kill-emacs-query-functions'." (if (and (featurep 'org-clock) (...


3

When killing Emacs, there are several hooks that may end up being called -- including, but not limited to, kill-emacs-hook, kill-buffer-hook (when a buffer is killed), write-file-functions hook (if a buffer is saved). A user can inspect a hook by calling M-x describe-variable and the name of the hook. A user can run a hook by evaluating (run-hooks NAME-OF-...


2

The manual explicitly states that kill-emacs is called, running the kill-emacs-hook, when SIGTERM or SIGKILL is recieved. So I would call this a bug. https://www.gnu.org/software/emacs/manual/html_node/elisp/Killing-Emacs.html (I guess this has to do with how windows kills differently than POSIX, but it should be possible to implement the analog/correct ...


2

The short answer is yes, unfortunately. But see this question for hints on avoiding this in the future.


1

What is the actual problem and what can I do about it? The hash is only initialized in mu4e-headers-mode. Therefore, you should correct mu4e-execute-marks in the following way if you want to call it in kill-emacs-hook: (defun mu4e-execute-marks () (interactive) (when (derived-mode-p 'mu4e-headers-mode) (mu4e-mark-execute-all t)) ) How to debug ...


1

Use the function kill-emacs. From its help: kill-emacs is an interactive built-in function in `C source code'. (kill-emacs &optional ARG) Exit the Emacs job and kill it. If ARG is an integer, return ARG as the exit program code. If ARG is a string, stuff it as keyboard input. The value of `kill-emacs-hook', if not void, is a list of ...


1

C-x C-c will not prompt to ask for saving desktop, it will exit Emacs immediately. C-xC-c (save-buffers-kill-terminal) does not actually kill the server by default, unless the client invoking it was started with the --no-wait switch and there are no other remaining Emacs frames[1][2]. Is there anything I can do to prompt for confirmation when C-x C-c in ...


1

I found the answer from https://emacs.stackexchange.com/a/30475/794 The version is tweaked version from the answer in the link (defun ask-before-closing () "Prompt for confirmation for emacsclient(not daemon) like confirm-kill-emacs for running Emacs without daemon." (interactive) (if (y-or-n-p (format "Really exit Emacs? ")) (save-buffers-...


1

I think the problem is that save-buffers-kill-emacs asks that yes-or-no question. When you're asked that you must either answer yes or no or use C-g to quit (in this case, quit exiting). You could advise or redefine save-buffers-kill-emacs to accommodate what you want. Or you could just define a command that you use after using C-g to quit exiting. That ...


1

If you really want to do it, it can be done. There are two standard hooks that you can use when emacs exits: kill-emacs-hook and kill-emacs-query-functions. The former is simple to use for always clocking out when you exit emacs: (add-hook 'kill-emacs-hook #'org-clock-out) List of standard hooks: https://www.gnu.org/software/emacs/manual/html_node/elisp/...


1

Yes. However, I would like to recommend an easy way of using emacs more efficiently. First, you create emacs server: emacs --daemon This makes emacs run as daemon(server mode), which means that you have one emacs server and you can have multiple clients. Now when you open emacs(using emacsclient -t or emacsclient -c depending on console/GUI), you create ...


1

Here's a command that does what you want: (defun ora-dired-start-process (cmd &optional file-list) (interactive (let ((files (dired-get-marked-files t current-prefix-arg))) (list (unless (eq system-type 'windows-nt) (dired-read-shell-command "& on %s: " current-prefix-arg ...


1

I have come up with adding a kill emacs hook: (add-hook 'kill-emacs-hook 'emms-stop) And it solves the problem for me.


1

Well the source of the problem was this line: (setq help-char (kbd "<f1>")) I changed it to (setq help-char nil) Well it was a kinda intuitive solution, so if another answer explains it, I will accept that. Update with explanation: Well I found the error, the kbd function returns with different datatypes, according to the given keys, an example: ...


1

With the suggestions of @elethan and @Tobias I was able to generate this stack-trace: Debugger entered--Lisp error: (wrong-type-argument listp "make -k ") savehist-save(t) savehist-autosave() kill-emacs() save-buffers-kill-emacs(nil) save-buffers-kill-terminal(nil) call-interactively(save-buffers-kill-terminal nil nil) And track it down to ...


Only top voted, non community-wiki answers of a minimum length are eligible