I am running Emacs 27.1 on Ubuntu.

I have installed gif-screencast and have gotten it to start recording whenever i start Emacs by adding


to my init.el. So far, so good. The problem is saving the recording when killing Emacs. I have tried to add both

(add-hook 'kill-emacs-hook 'gif-screencast-stop)


(setq confirm-kill-emacs 'gif-screencast-stop)

to my init.el, but none of them manage to stop the recording and save it before Emacs asks me whether I want to kill running processes. When I answer 'yes', it will, of course, kill the gif-screencast process before ending it properly.

My current solution, arrived at by trial and error, is to add

(advice-add 'save-buffers-kill-emacs :before #'gif-screencast-stop)

to init.el. This works when killing Emacs by using the GUI menu, but not when using C-x C-c from within Emacs. When I try the latter, i get Wrong number of arguments: (0.0), 1. When I do the former, it correctly saves the gif-screencast recording before giving me the Save file ...? prompt and then killing Emacs.

Edit: it gives me 2 prompts: First, it gives me Active processes exist; kill them and exit anyway?, then it gives me Save file ...?. The first one of these is the one that has to wait until after gif-screencast has properly finished.

My syntax is wrong somehow, but I'm not experienced enough with elisp to figure it out.

How do I make this execute correctly also when killing Emacs with C-x C-c?


I think your advice function should have the same signature as save-buffer-kill-emacs, i.e. it should take an optional argument (which it can go ahead and ignore of course):

(defun my/gif-screencast-shutdown (&optional arg)

(advice-add 'save-buffers-kill-emacs :before #'my/gif-screencast-shutdown)

That should take care of the Wrong number of arguments message (although I don't understand why/how it works from the GUI and not when called with C-x C-c).

This is all untested and may be completely wrong, but try it and see.

  • Thanks, @NickD! This does save the gif, and gives me the Active processes exist; kill them and exit anyway? prompt afterwards. However, it stumbles on the Do you want to save ... prompt. This never shows, and Emacs never quits. I tried using C-u C-x C-c instead of just C-x C-c in order to silently save all buffers, and then it works just fine, because I never encounter the Do you want to save ... prompt. Edit: I realize i was unclear on the two different prompts in my original question. I will update and clarify.
    – memius
    Sep 11 '21 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.