3

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

How do I close this Emacs session?

2

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.

4
  • 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. Sep 8 '20 at 0: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 8 '20 at 0: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 Sep 8 '20 at 1: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.

3
  • Didn't work for me! Both in line-mode or char-mode, the C-x *** is always captured by EXWM. Sep 8 '20 at 11:29
  • That is very strange: I run inner emacsen from EXWM frequently and char-mode works perfectly for me. Maybe some weird interaction with ssh? Sep 8 '20 at 11:36
  • Yes, apparently it is something strange due to SSH. Not happening with other emacs on the same machine. Sep 8 '20 at 11:40
0

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

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). Sep 7 '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 8 '20 at 6:41
  • C-x C-s is also captured by EXWM Sep 8 '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 8 '20 at 13:45

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.