athoren
athoren

Reputation: 453

Using Space instead of Control to avoid emacs pinky?

I've developped a case of emacs pinky from pressing C-x too much. Ideally, I would like to use the space bar instead of control as a prefix command since it is much easier to press and hold with the thumb. Pressing and releasing space should still add a space but pressing Space+x simultaneously should be bindable to a command. For example:

(local-set-key (kbd "SPC-s") 'search-forward)

Does anyone have any ideas on how this could be implemented? Is it possible to do it using only elisp or would I have to modify the emacs source and compile my own version?

I would prefer a solution which is OS independent since I use emacs on both Windows and Linux.

EDIT: I have tried key-chord.el which helps in some cases but not all (C-x C-s). I would prefer a minor mode such as holding-space-is-control or holding-space-is-meta

EDIT: Thanks for all the replies. I'm currently using key-chord to map many C-* command to j* or f* depending on if * is a left or right hand key. For example, I've replace C-x b with jb. It works fine for all commands you typically type once but not for commands you use repeatedly (such as forward or backward-paragraph). It is the best cross-platform solution so far since it only requires a custom .emacs and the key-chord.el file. I would prefer a solution which requires less remapping and reduces the risk of typing "fyi" and getting "< yank >i". I believe using space could work but I don't know enough about the technical details of emacs to make it work.

I've considered replacing Caps-Lock or Alt with Ctrl but that only helps for the left pinky. Many common commands are executed using the right pinky (C-x, C-s, C-w, C-y).

Upvotes: 5

Views: 7107

Answers (10)

Daimrod
Daimrod

Reputation: 5030

Xah Lee has wrote a nice article on this subject, especially when he recommends to

use your palm or semi-fist instead of your pinky to press the control key

Upvotes: 3

pokita
pokita

Reputation: 1261

I do not think this is possible in Emacs Lisp. For doing what you want, one would have to check whether the 'space' key is still held down or if it was released. However, keyboard events in Emacs are simply characters, not 'pressed' and 'released' events like for mouse buttons. I don't know enough about the Emacs C code to say whether this could be implemented there without breaking the normal event loop.

So let's turn to OS-dependent solutions. Under Xorg, you can map modifiers to normal keys (using xmodmap); however, pressing 'space' would still generate a whitespace while also working as a modifier, which is not what you want. The only solution I know of is a special Xorg keyboard driver:

https://gitlab.com/at-home-modifier/at-home-modifier-evdev/wikis/home

I don't know if something similar exists for Windows, though.

Upvotes: 5

choroba
choroba

Reputation: 241968

I remapped my CapsLock to Control to avoid the pain (using KDE to do the mapping, not emacs, though).

Update: I was able to do that in LXDE and MS Windows, too.

Upvotes: 6

nasske
nasske

Reputation: 19

the exact solution is described here. it consists of using an extra software (available on each os). http://emacswiki.org/emacs/MovingTheCtrlKey#toc24

Upvotes: 1

Ben
Ben

Reputation: 158

Over the last several weeks I have written and used an AutoHotKey script that provides Windows-wide functionality to do exactly what you have described. It is now available on GitHub. While it is not an OS independent solution, there are nearly identical implementations on Linux (e.g. At-Home-Modifier and Space2Ctrl) so you should be able to have the same user experience on either platform. On the plus side you also get to use it in other programs for tasks like copying, pasting and switching browser tabs. Hope it helps.

Upvotes: 2

trogdoro
trogdoro

Reputation: 49

This should do what you want:

http://www.emacswiki.org/emacs/space-chord.el

(space-chord-define-global "s" 'search-forward)

It does "chording" so you'll have to type space and s at the same time, but doing so is easy.

Or, if you could use control-lock to help avoid holding down control as much (it's like caps lock for the control key).

Upvotes: 4

Ivan Andrus
Ivan Andrus

Reputation: 5301

You can look at cua-mode which does something similar for C-x and C-c (when mark is active). I'm certainly no expert (I don't even use cua-mode), but looking briefly at the code there is a timer which sends a timeout event so that (in your case) you would bind [?\s timeout] to insert a space and bind other keys to whatever you want. You also can't (I don't think) bind keys as if SPC were a modifier:

(local-set-key (kbd "SPC-s") 'search-forward)

but you would bind them as (say)

(define-key space-as-prefix-map (kbd "s") 'search-forward)

I tried to do a quick test using cua-mode, but unfortunately, the timer only runs when the mark is active. Well, it's a little more complicated than that but suffice it to say that I didn't persevere long enough to figure it all out. But it's definitely possible to make space be to control what escape is to meta.

Upvotes: 1

Jorge
Jorge

Reputation: 11

What I do is switch alt keys for controls and super keys for alt-meta, this avoids clicking the annoying left control. Besides I switch Caps Lock for Hyper to have an extra modifier that I use for switching between buffers H-p H-n and other stuff. If you have Ubuntu the change is trivial in your keyboard settings.

Upvotes: 1

phils
phils

Reputation: 73314

On Windows, AutoHotKey is a very flexible and scriptable solution for most kinds of key remapping requirements.

Upvotes: 5

aerique
aerique

Reputation: 981

This isn't an answer to your question but it is a way to avoid the Emacs pinky: don't use one hand to press modifiers and a key. So (assuming you have a Qwerty keyboard) use your right hand to press Control and your left hand to press the 'x'.

Upvotes: 0

Related Questions