reddit / emacs

[NOOB] Prompt for saving file when exiting emacsclient using EVIL mode

wiyomay249 · 2022-02-11 20:35
When I exit emacs with a file edited, I normally get prompted for if I want to save the file. This works great, but when I run emacs using `emacs --daemon` and I exit using `:q`, I am being asked if I want to save the current file. I have been able to get it working if I use `C-x C-c`, but not when exiting using evil mode. Do anyone know how to do this?
c3lphie · 2022-02-11 21:24
If you're gonna quit using evil mode just add a `w` for write `:wq` <-- like this
[deleted] · 2022-02-11 22:05
[deleted]
AdmiralFisticuffs · 2022-02-11 22:21
or `:x`
_asciimov · 2022-02-11 23:11
or in command mode `ZZ` to save (if needed) `ZQ` to quit without saving no pesky colon needed
wiyomay249 · 2022-02-11 23:13
Thank you both, yes, I know that I can use another command to get the same thing done, but this is more for the sake of understading elisp, configuration and how emacs works. Is there any elisp code that I can put in my configuation files which would achive what I want? Another question: How can I look up what the underlying command ran in evil-ex is called? (and yes, I know both :wq and :x are from vim:))
_asciimov · 2022-02-11 23:39
If I read your question correctly you are using `:q` to kill the buffer and exit emacs. You would like it to prompt you to save your file before killing the buffer and then exiting. First an aside you may need this code later: I have changed my evil mode such that `:q` only kills the buffer you can do that by adding the following to your init. ;; :q should kill the current buffer rather than quitting emacs entirely (evil-ex-define-cmd "q" 'kill-this-buffer) ;; Need to type out :quit to close emacs (evil-ex-define-cmd "quit" 'evil-quit) Now, if you take a look at [this stack exchange page](https://emacs.stackexchange.com/questions/30454/how-to-make-emacs-prompt-me-before-closing-the-last-emacs-gui-frame-when-running) the first answer has this snippet of code that will prompt you to save buffers before killing and exiting (defun ask-before-closing () "Close only if y was pressed." (interactive) (if (y-or-n-p (format "Are you sure you want to close this frame? ")) (save-buffers-kill-emacs) (message "Canceled frame close"))) (when (daemonp) (global-set-key (kbd "C-x C-c") 'ask-before-closing)) If you combine the two, you should be able to change the default of `:q` from `'evil-quit` to `'ask-before-closing` with (evil-ex-define-cmd "q" 'ask-before-closing)
_asciimov · 2022-02-11 23:55
[See the docs on evil-mode keymaps](https://evil.readthedocs.io/en/latest/keymaps.html#chapter-keymaps) You need to look at the listings (`C-h o`) in evil-normal-state-map
wiyomay249 · 2022-02-15 13:42
Wow, thank you for taking the time to write all of this. It was very informative!
wiyomay249 · 2022-02-15 13:45
Once again, thank you so much! I am however still not able to look up the documentation for an evil-mode command (eg. looking up what the command`:q` does. When I try looking up a command in normal mode, the `:` is interpreted as the only thing I want to look up, and when I try looking it up while in the command-mode, it still does not pick up that I try looking up a command
_asciimov · 2022-02-15 14:15
I'm not sure if there is a help function for it, however, you can look at the source code for the commands. To open the evil-maps.el file you need to `M-x find-library` and the library name is `evil-maps.el` on my system it shows up as `evil-maps.elc` `evil-maps.el` shows every key map for all the evil states.