4

Inside EXWM (from "term") I opened another Emacs session (git commit opened it).

How do I close this Emacs session?

Drew
  • 75,699
  • 9
  • 109
  • 225

3 Answers3

3

The problem is that any commands you execute such as C-x C-c will be captured by the Emacs instance running EXWM.

The first thing to try - which did not work for OP - is to execute M-x exwm-input-grab-keyboard with the secondary Emacs window selected. This will set the window to char mode, and send the keys you type directly to that window. So C-x C-c will then cause that secondary Emacs to exit. If this works for you, you can set exwm-input-toggle-keyboard to a global key (S-i is a common binding).

If that does not work, you can send keystrokes to the secondary Emacs using M-x exwm-input-send-next-key. With the secondary Emacs window selected, you run the above command twice, sending first C-x then C-c. This command is bound by default to C-c C-q - in that case you would type C-c C-q C-x C-c C-q C-c.

As a last resort, you would open a shell and search for emacs processes, and kill the secondary Emacs process.

The more important thing is to never let this happen again. You can do that by starting the Emacs daemon from your EXWM startup code with (server-start) and setting the EDITOR environment variable with (setenv "EDITOR" "emacsclient"). Then git commit will open the file in your running Emacs.

gregoryg
  • 915
  • 6
  • 8
  • Thanks for your suggestion. Unfortunately, I usually work in other machines (through ssh) what would not allow me to change the editor to be an emacsclient from my ssh client machine. – Everton J. Carpes Sep 08 '20 at 00:00
  • I edited my answer to indicate that you have a choice to send keys to the managed Emacs process as well. That may be your best bet. – gregoryg Sep 08 '20 at 00:02
  • 1
    From your answer I was able to figure out a way that worked +- properly: Using the `exwm-input-send-next-key` shortcut `C-q` with input in "line mode" I was able to send the combinaton into the "inner" emacs `C-q C-x C-q C-c` – Everton J. Carpes Sep 08 '20 at 01:07
  • 1
    @EvertonJ.Carpes Thank you for accepting my answer. I thought it could still be improved for future searchers, so I added a better thing to first try as in Fran Burstall's answer, then what worked for you. – gregoryg Sep 12 '20 at 15:59
2

The best solution is simply to hit C-c C-k (exwm-input-release-keyboard) which puts the X-window containing the inner emacs into char-mode. Then, when that window has focus, almost all keyboard input, including C-x C-c is passed to the inner emacs.

Hit s-r (exwm-reset) to get the window back to normal line-mode.

Fran Burstall
  • 3,665
  • 10
  • 18
0

I assume you can just kill the buffer (C-x k).

Drew
  • 75,699
  • 9
  • 109
  • 225
jfwm
  • 21
  • 4
  • It works to get rid of the terminal+emacs inside it, but I would like to see if there is a way to properly close the "inner" emacs(including saving the content, etc). – Everton J. Carpes Sep 07 '20 at 23:35
  • In this case, you can use the magit package (a git porcelaine inside emacs), or similar, and C-c C-c would save and exit, whereas C-c C-k would exit without saving. On machines with a vanilla emacs, when I am in your case, I just save (C-x C-s) and exit (by killing the buffer with C-x k because C-x C-c would be caught by EXWM). Hope this clarifies and helps. – jfwm Sep 08 '20 at 06:41
  • C-x C-s is also captured by EXWM – Everton J. Carpes Sep 08 '20 at 11:34
  • Indeed! C-c C-q C-x C-c C-q C-s (or something like that) should sent directly C-x C-s to the "emacs inside". BTW, it may also be possible to exit (with something like C-c C-q C-x C-c C-q C-c) – jfwm Sep 08 '20 at 13:45