jed-users mailing list

[2015 Date Index] [2015 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[jed-users] Re: find begin/end of block with python mode?


On Thu 2015-09-24 (17:36), Ulli Horlacher wrote:

> In C or Perl mode I use Ctrl-4 (goto_match) to jump between begin and end
> of a code block.
> 
> Is there an alternative for python mode?

I have now written the functions py_block_up() and py_block_down()
and bound them to Alt-[ and Alt-]


define py_block_up() {
  variable col;
  variable block = 0;

  call("beg_of_line");
  skip_white();
  col = what_column();
  if (looking_at("else:") or
      looking_at("elif ") or
      looking_at("except")) block = 1;
  while(1) {
    call("beg_of_line");
    call("previous_line_cmd");
    skip_white();
    if (not eolp and not looking_at("#")) {
      if (what_column() == 1) break;
      if (what_column() < col) break;
      if (what_column() == col and block) {
        if (looking_at("try:"))   break;
        if (looking_at("except")) break;
        if (looking_at("if "))    break;
        if (looking_at("elif "))  break;
      }
    }
  }
}


define py_block_down() {
  variable col;
  variable block = 0;
  
  call("beg_of_line");
  skip_white();
  col = what_column();
  if (looking_at("if ") or
      looking_at("elif ") or
      looking_at("try:") or
      looking_at("except") or
      looking_at("for ") or
      looking_at("while ") or
      looking_at("def ") or
      looking_at("class ")
     ) block = 1;
  while(1) {
    call("beg_of_line");
    call("next_line_cmd");
    skip_white();
    if (not eolp and not looking_at("#")) {
      if (what_column() == 1) break;
      if (what_column() == col and block) break;
      if (what_column() < col) break;
    }
  }
}


It works for me.

-- 
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum IZUS/TIK         E-Mail: horlacher@xxxxxxxxxxxxxxxxxxxx
Universitaet Stuttgart         Tel:    ++49-711-68565868
Allmandring 30a                Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<20150924153642.GA12747@xxxxxxxxxxxxxxxxxxxx>
_______________________________________________
For list information, visit <http://jedsoft.org/jed/mailinglists.html>.


[2015 date index] [2015 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]