I'm considering using PCE as my new primary text editor, but it really lacks configurable hotkeys. So this is my first try at hacking them in.

As this is a five minute hack, it really lacks extensibility. In the long run, this will need to be replaced by a hash-lookup on the keycode, so it is easily extensible by just plugging in the keycodes you want and one doesn't need to patch the code all the time. Oh well. So many projects, so little time.

# This needs to go into /src/pce/app/events.pm # Re-Implement key_down_filter via a hash lookup sub key_down_filter { my ($sci_frame, $event) = @_; my $key = $event->GetKeyCode; if ($key == 13){ my $newline; if ($pce::config{'editpanel'}{'blockindent'}){ my $pos = $sci_frame->GetCurrentPos-1; #$pos-- while ($sci_frame->GetCharAt($pos) == 32); my $char = $sci_frame->GetCharAt($pos); if ($char == 123) {pce::edit::format::blockindent_open( +$pos); $newline++} elsif ($char == 125) {pce::edit::format::blockindent_close +($pos); $newline++} } unless ($newline) { if ($pce::config{'editpanel'}{'autoindent'}) {pce::edit::f +ormat::autoindent();} else {$sci_frame->CmdKeyExecute(wxSTC_CMD_NEWLINE)} } return; } elsif ($key == 351){ # F10 use Data::Dumper; #pce::dialog::msg_box(undef,Dumper $pce::internal{'file'}{'cur +rent'},""); # Get "current" filename my $current_dir = $pce::internal{'file'} ->{'current'} ->{'open'} ->[pce::document::get_current_nr()] ->{'directory'}; $current_dir =~ tr!/!\\!; # Win32 fix # Spawn a console there use Cwd; my $old_dir = getcwd; chdir $current_dir; system(qq{start cmd.exe /k g:\\systeme\\tools\\path.cmd}); chdir $old_dir; #elsif ($key == 350){ # use pce::ext::Perl::Syntax; # pce::ext::Perl::Syntax::check(); # return; #}; #pce::app::visual::status_msg(); #SCI_SETSELECTIONMODE #elsif ($event->AltDown){ #if ($key == 49){pce::document::change_current(0);} #if ($key == 50){pce::document::change_current(1);} #if ($key == 51){pce::document::change_current(2);} #if ($key == 52){pce::document::change_current(3);} #if ($key == 53){pce::document::change_current(4);} #if ($key == 54){pce::document::change_current(5);} #if ($key == 55){pce::document::change_current(6);} #if ($key == 56){pce::document::change_current(7);} #if ($key == 57){pce::document::change_current(8);} #if ($key == 48){pce::document::change_current(9);} #pce::dialog::msg_box(undef,$key,""); # $event->Skip; } else { #pce::dialog::msg_box(undef,$key,""); $event->Skip; } }

A small hint - you should not edit your editor with itself unless you rarely make syntax errors :-)

Updated: BrowserUK spotted the missing http:// in front of the external link.

Replies are listed 'Best First'.
Re: Extend PCE with your own hotkeys
by sir_lichtkind (Friar) on Oct 24, 2005 at 13:57 UTC
    thanks for interest. i am very delighted to read your first sentences. your always welcome for developement but unless you don't submit in cvs its your hack. conigurable key map was from the perl coders i talked with here one of the most wanted and often i drive developement toward desired features. the problem is only that current keybinding are autogenerated. after 0.3.4 or 5 we will have full controll over it and you will get your desired features ASAP. with your help maybe sooner. have joy

      Currently, I'm thinking of an easy hack in the event.pm file:

      use vars qw(%keybinding); %keybinding = ( ... default keybinding ); my @user_bindings = do 'user_keybinding.pl'; while (@user_bindings) { my ($k,$v) = splice @user_bindings, 0, 2; $keybinding{$k} = $v; }; sub key_down_filter { my ($sci_frame, $event) = @_; my $key = $event->GetKeyCode; if ($event->AltDown) { $key = "a$key"; }; # same for shift, ctrl, meta, footpad, escape if (exists $keybinding{$key}) { # dispatch $keybinding{$key}->($sci_frame,$event,$key); }; };

      Update: I should add that using this scheme, it's not really easy to do multi-key combinations a la WordStar or vi - to implement these, multiple dispatch tables are needed. But as a first start I think this kind of keybinding will be enough.