12

In Windows 10 I installed Subsystem for Linux Bash. But I have a problem with shortcut in Emacs Ctrl+space doesn't set mark point.

What i tried and didn't help:

  • I tried to uncheck "enable Ctrl key shortcuts" in properties menu for windows console

  • I tried to use different terminal ConEmu without success.

I wonder if this is somehow related to ubuntu which has similar problems with ctrl + space , and windows linux bash is using ubuntu repositories.

3

There are no solutions to this, in terms of making Ctrl-Space pass through the Bash terminal, at the time of this writing (1 Sep 2016)—but there is a workaround that may be sufficient for many users: use PuTTY to connect via SSH, which forces handling of Ctrl-Space. (In tty mode, it's impossible to distinguish Ctrl-Space from Ctrl-@, because they are the same character code, but that shouldn't be an issue, as by default Emacs is set up to handle set-mark-command that way.)

  1. Install the OpenSSH server with sudo apt-get install openssh-server. If it was already installed, remove it (sudo apt-get remove openssh-server) and then reinstall it to get the config files reset.
  2. Edit the /etc/ssh/sshd_config file (with sudo), as follows:

    • If there is an uncommented line setting PermitRootLogin, comment it out. Add a line PermitRootLogin no.
    • Add a line AllowUsers USERNAME, replacing USERNAME with your Linux username (if you don't know what that is, run the command whoami at your Bash prompt).
    • Ideally you should set up passwordless authentication using SSH keys, but how to do that is out of the scope of this question (there are many guides available; search the web for "passwordless ssh-keygen"). In the meantime, add or uncomment the line PasswordAuthentication yes.
    • Set UsePrivilegeSeparation no; likely you will find a line in the file saying UsePrivilegeSeparation yes; just change the yes to no and save the /etc/ssh/sshd_config file.

    If something goes wrong here, you can restore the file by repeating step #1.

  3. Startup the SSH server with the command sudo service ssh --full-restart.
  4. Using PuTTY (download here), login with localhost in the Hostname field, everything else left as default. You'll be asked to enter your Linux username and your password.
  5. Run emacs. Ctrl-space will set the mark as desired.

(Note that the steps above will not, by themselves, make your system able to accept SSH connections from other hosts. To do that, you will also have to change your Windows firewall rules to allow inbound TCP port 22.)

In another answer you said, "but putty is not a local terminal." I'm not sure if you weren't aware that you could use localhost in this way, or if you were dismissing PuTTY because of the greater overhead versus a local terminal. If the latter, I wouldn't worry, an interactive SSH session is an extremely lightweight load. (It's certainly much less load than running an X Window System so you can run a GUI Emacs or an xterm!)

The only real disadvantage to running this way versus a straight terminal is that paste events are sent letter-by-letter, as if you typed the contents of the clipboard very fast, which may cause electric pairs, indention, snippet expansion, etc. to fire. (Paste should not cause key-chord commands to fire, as there's logic to detect an in-progress paste and disable key-chords until the paste is finished.)

And there's at least one very big advantage over the standard Bash terminal, too: mouse events are supported by PuTTY in a form that Emacs can respond to, so, ironically, you can move the point with the mouse in PuTTY even if you can't with the local terminal.

5

I use ConEmu. There is no elegant way, but it can be solved using the macro.

  1. Open "Settings" (Click on the icon on the top).
  2. Click on "Keys & Macros".
  3. On the right hand side, scroll down till you see "Macro 01" .. "Macro 32" options, and pick any one that is available (does not matter).
    Let's take Macro 01 for this example.
  4. Select "Space" in 1st dropdown menu.
  5. Select "Ctrl" in 2nd dropdown menu. Leave the remaining 2 dropdown menus untouched.
  6. Paste below in the GUI Macro field:

    keys("\e");keys("x");keys("s");keys("e");keys("t");keys("-");keys("m");keys("a");keys("r");keys("k");keys("-");keys("c");keys("o");keys("m");keys("m");keys("a");keys("n");keys("d");keys("\n")
    
  7. Above basically sends M-x select-mark-command string to emacs. Now click "Save settings".


It should look like this in the end:

enter image description here

  • works like charm. Fantastic! – chriskelly Jan 31 '17 at 13:58
2

When running showkey -a in windows/ubuntu-bash console it shows that ctrl+space just sending a plain space.

And it's the same issue with ssh session to any other linux machine ctrl + space is sent as plain space.

The same behavior is with any other windows based terminal ( conemu, consolez, MobaXTerm ) - except putty can handle this well but putty is not a local terminal.

I think Windows terminals doesn't have mappings for some sequences. The same problem is with other combinations like ctrl+1 ctrl+2 .. etc. Here required is terminal which can handle the keyboard mappings for it self like putty for example.

I believe this issue should be fixed in future releases of the windows bash terminal.

  • Even worse, it doesn't seem to pass ctrl-@, either, which is the other binding for set-mark. If someone's in a real bind, they can use M-x set-mark-command. The right thing to do for now, probably, is to set a key binding to something else. – Jim Hunziker Aug 15 '16 at 18:26
  • @JimHunziker Given that set-mark-command is probably the most-frequently-used command in Emacs (aside from self-insert-command), retraining one's fingers for that is a really, really steep ask—especially if you've been using Emacs for 25+ years like me. – Trey Sep 1 '16 at 21:44
  • @Trey added another answer, if you don't mind running xming on windows – Pawel Dubiel Sep 1 '16 at 22:08
  • @PawelDubiel See my answer just added. (I gave more detailed instructions than required for you to help later readers.) You dismissed PuTTY for some reason, but didn't say what that reason is. It's certainly an option that puts much less load on the system than xming + an X terminal. – Trey Sep 1 '16 at 22:29
2

This project allows you to use MinTTY as an alternative terminal: https://github.com/mintty/wsltty. It's derived from PuTTY, but doesn't require SSH. And like PuTTY, it handles Ctrl-space just fine.

1

This issue is now fixed in Windows 10 build 14965. Check:

[Environment]::OSVersion

And install updates if you haven't!

  • Please add more detail to your answer - the link may stop working at some point at which your answer becomes useless. – djsmiley2k Apr 12 '17 at 9:31
0

There is a hack as we can install X Server for Windows

1 first install xming for windows

2 start xming

3 then from windows bash install

sudo apt-get install rxvt-unicode-256color

4 then open cmd.exe and run

bash.exe -c "urxvtd -q -o -f; bash" 

now we are in bash console and run

(DISPLAY=:0 urxvtc &)

5 At this point, we should already see a new terminal in Xming. And we can run emacs in terminal mode.

emacs -nw

And all bindings now work just fine

the related discussion is here https://github.com/Microsoft/BashOnWindows/issues/531

  • Why is this a superior workaround to using PuTTY? If you were going to run Emacs in GUI mode, I'd understand it, but your use of -nw makes it run in a terminal, just like it would with PuTTY, except you're now having to run an entire second windowing system—from my quick test, that's going to cost you almost 500 MB of memory beyond running an sshd and PuTTY and will have a similarly higher CPU cost. – Trey Sep 1 '16 at 22:44
  • @trey 500MB are you sure? on my system is exactly 5mb – Pawel Dubiel Sep 1 '16 at 23:41
  • Ah, I misread the units, you're right. But the comparable sshd + PuTTY number is about 25% of the other number, whatever it is ;-) – Trey Sep 3 '16 at 19: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.