There is a function that does this already:
(save-buffers-kill-emacs &optional ARG)
Offer to save each buffer, then kill this Emacs process.
With prefix ARG, silently save all file-visiting buffers without asking.
You can call it interactively with C-u M-x save-buffers-kill-emacs
and all files are saved without asking you and emacs quits, problem solved!
Your keybinding didn't work for two reasons:
(kbd "S-;")
is not shifted ";" (i.e., ":"), it is ";" with the Super bit on. To bind to ":" just use ":" like this - (kbd ":")
- ":" is not a prefix key, so you can't use it in a chain
(kbd ": x")
without further changes. Either you need to define a prefix-map and bind it to ":" (see below), or investigate some other approach.
So, to get a save-all-and-quit bound to a key, the easiest solution is probably:
(global-set-key (kbd "C-c x")
(lambda ()
(interactive)
(save-buffers-kill-emacs t)))
Here the function is bound to C-c x
, but you can change it to anything else.
If you really want to use ":" as a prefix, you'd do something like this:
(define-prefix-command 'my-keymap)
(global-set-key ":" my-keymap)
;; define kill-emacs:
(define-key my-keymap "x" (lambda ()
(interactive)
(save-buffers-kill-emacs t)))
Now, of course, you've lost use of the : key for entering the ":" character. You can get it back by adding it to your keymap:
(define-key my-keymap ":" 'self-insert-command)
Now entering : x
will save all buffers and kill emacs, and : :
will enter a ":".
(kbd ": x")
. But that would only work if":"
was a prefix key. Either pressing:
inserts:
or it waits for you to type the next character, it can't do both. Are you using a vi emulation interface? Which one?