Fix terminal mode for emacs