domingo, 10 de enero de 2010

Banish mouse pointer on emacs

In ratpoison and stumpwm, there's a 'banish' command that exiles the mouse pointer to a corner of the screen. It's quite useful when you don't want the mouse to distract you or clobber the text you are writing.

In ratpoison, you only have to execute the command :banish, and it will move the cursor. You can bind it to a shortcut (for me it's 'c-t B').

emacs has a more sophisticated way to do it, and you can automate it to banish the cursor only when your typing is getting close to the mouse pointer, or just when you start typing in a buffer.

the function is namend mouse-avoidance-mode, and accepts some diferent symbol arguments: banish, exile, jump, animate, cat-and-mouse or proteus.

I chose banish because it's the simplest and most determinist. The "problem" there is that the mouse moves to the top-right corner, and when the active buffer is an erc buffer, the mouse is over the channel topic line, and a tooltip is displayed, distracting me. If I could only change the position where the mouse gets moved to....

Hey, it's emacs, so you can rewrite nearly all functions. Browsing through the mouse-avoidance-mode code, you can see the function that tells emacs where to place the mouse is
mouse-avoidance-banish-destination.

Just redefine it in your .emacs file like


and you're done. Now the mouse gets placed 1 line below the title line, so no tooltip window gets displayed.

If you're a seasoned emacser, this will say nothing to you, but for me, it's my first emacs 'hack', so I'm very happy it was so easy to do.

Some time ago I did some kind of modification to emacs, but was basically assisted by davazp.

No hay comentarios: