Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Space instead of Control to avoid emacs pinky?

Tags:

emacs

elisp

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).

like image 253
athoren Avatar asked Jan 04 '12 09:01

athoren


4 Answers

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

like image 107
phils Avatar answered Oct 14 '22 20:10

phils


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.

like image 41
choroba Avatar answered Oct 14 '22 20:10

choroba


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.

like image 35
pokita Avatar answered Oct 14 '22 20:10

pokita


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).

like image 36
trogdoro Avatar answered Oct 14 '22 21:10

trogdoro