24. 4. 2010

exit emacs + cygwin (windows) problem

I am playing with emacs editor in cygwin environment in my windows xp installation.

When you want to exit and save edited text, you've got two three possibilities (maybe there are more?):

1) From emacs manual : press C-x, C-c . Emacs manual convention says C means CTRL key and M means Meta key which depends on OS - in Windows it's ALT or ESC. So press Ctrl + X then Ctrl + C. Then question appears: Save file ?" y/n... so if you want to really save a file press "y" which means yes (or n as no which in fact act as cancel - emacs doesn't exit and stay opened, semantic no do by press "!" which exit emacs without saving).
But here is problem I was struggling with: when you press C-x C-c emacs print message "C-x C-g is undefined" like you was hitting CTRL+C, CTRL+G. Wtf? I am not exactly sure why, but this solve the problem: set the system environment variable CYGWIN to value "tty". You can do it inside cygwin by export CYGWIN="tty", but then when you exit emacs, cygwin stop echoing your keys so you don't see what you write. It's like when you typing password when using sudo command. When you set this environment variable before starting cygwin from windows everything is ok. You can set this variable in windows by SET CYGWIN="tty" in command shell (cmd.exe) or through System properties (WIN+PauseBreak).

2) M-x (ESC + X or ALT+X) to active command mode and write "save-buffers-kill-emacs" and then press "ENTER", save question appears, make choice. Note that command mode has auto complete on TAB key, so write just "sav" press TAB, emacs show all possible commands starting with "sav" or do auto complete if there is no ambiquity in names of commands.

3) C-x-s (this one I discovered just by luck when I wanted to originally press M-x and started typing "save" like in 2)

Sources:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Exiting.html
http://www.emacswiki.org/emacs/SetTty
http://blog.arithm.com/2007/12/01/killing-cygwin-emacs/