KeybindingTutorial
From Niki
Example 1
Sometimes you hit Ctrl+Pos1 (go to beginning of file) or Ctrl+End (go to end of file) by accident and don't know ho to get back to the position of the cursor before the jump. Or, you scroll throug a file without changing the current cursor position, then you see something that you want to change, click with the mouse there, change it and want to go to the cursor position before you scrolled. The solution is to change the keybindings like this:
nedit*text.Translations: #override \n\\ ~Shift~Alt~Meta Ctrl<Key> osfBeginLine: mark(0) beginning_of_file()\n\\ ~Shift~Alt~Meta Ctrl<Key> osfEndLine: mark(0) end_of_file()\n\\ ~Shift~Alt~Meta~Ctrl<Btn1Down> : mark(0) grab_focus() \n\ <Key>F3 : goto_mark(0)\n
Explanation: The keys Ctrl+Pos1 and Ctrl+End are changed, so that they set the mark named 0 at the current cursor position before they trigger the actions go to the beginning, or to the end, of the file, respectively. (The Motif names for Pos1 and End are osfBeginline and osfEndline, cf. VirtualKeybindings.) The key F3 is bound to the action go to the mark named 0. Moreover, the left mouse click is changed to set the mark 0 to the current cursor position before moving the cursor to the mouse position. (The tilde in front of the modifier keys means that these modifiers are not pressed. So for example the X event above for the mouse button is exactly a left click with no modifiers held.)
Example 2
The spell-checker integration N-spell marks spelling mistakes by backlighting them. The wish was to point to a misspelled word with the mouse pointer and to right click to get suggestions for correcting the word. However, NEdit's scripting language has no access to the position of the mouse pointer, but only to the position of the cursor (that shouldn't change). The solution is to change the mouse settings like this:
(Attention: These bindings are part of N-spell. If you don't have N-spell, they won't work. If you have N-spell, you have them already, so you needn't copy them from here. They are here only as example to demonstrate how to change key and mouse bindings and what this can be good for.)
nedit*text.Translations: #override \n\
~Shift~Meta Ctrl Alt<Btn3Down> : mouse_pan() \n\
Ctrl~Meta Alt~Shift Button3<MotionNotify>: mouse_pan()\n\
Ctrl~Shift~Meta~Alt<Btn3Down> : mark(9) grab_focus() macro_menu_command("Spelling>SuggestCorrection@mouse") goto_mark(9)\n\
Ctrl Shift~Meta~Alt<Btn3Down> : mark(9) grab_focus() macro_menu_command("Spelling>AutoCorrect@mouse") goto_mark(9)\n\
~Ctrl~Shift~Meta Alt<Btn3Down> : mark(9) grab_focus() macro_menu_command("Spelling>IgnoreOrAddWord@mouse") goto_mark(9)\n
Explanation: First the mouse pan action, which is bound to Ctrl + right click and dragging by default, is saved to Alt + Ctrl + right click and dragging. (Might be useful still, because not all X servers support the mouse wheel.) Then Ctrl + right click is used for the sequence of actions: set the mark named 9 to the current cursor position, move the cursor to the mouse pointer position, run a macro (using the macro-menu-command action) that pops up suggestions for the misspelled word at the cursor position (which at the moment the macro starts is at the mouse pointer location) and set the cursor back to the position of mark 9 - this is done directly after the macro starts, not waiting for termination of the macro, so that the cursor position is changed only for some millisecond.
