Author Topic: jump to next row up/down where first word appears same col as current line?  (Read 4578 times)

tomm

  • New Community Member
  • Posts: 1
  • Hero Points: 0
hi-

first things first, the company I've just joined has a site license for SlickEdit version 8 and use it extensively, so I need to be able to edit with this app. Also, only suggestions which are applicable to this version are of use to me :(

I'm editing python files with SlickEdit, and would like to find a way to jump back and forth between start and end of code blocks.

Since python doesn't surround code blocks with parentheses but rather uses column indentation, the ctrl-] keyboard shortcut doesn't appear to work.

Can anyone suggest a way to do this with version 8?

I'm thinking that a solution would be to create a couple of macros to jump up/down to the next line where the first non-whitespace character starts at the same column indentation as the current line, and then map these to a couple of keyboard shortcuts.

Would that work? I'd be grateful for any suggestions.

Thanks.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
I don't follow how your solution finds the start or end of the code block.  Say you have this.
Code: [Select]
   for func in self.original_functions:
      file.Write("%s GLES2%s(%s) {\n" %            # line 1
                 (func.return_type, func.name,         # 2
                  func.MakeTypedOriginalArgString("")))
      return_string = "return "         # 4
      if func.return_type == "void":       # 5
        return_string = ""        # 6
      file.Write("  %sgles2::GetGLContext()->%s(%s);\n" %       # 7
                 (return_string, func.original_name,               # 8
                  func.MakeOriginalArgString("")))            # 9
      file.Write("}\n")        # 10
                                   # 11
    file.Write("\n")     # 12
                            # 13
    file.Close()          # 14

Suppose that the cursor is at the start of line 10.  When you use your up command, where should the cursor go to.

Or say the cursor is on line 5 and you do the up command.  According to your description, the cursor would go to line 4 because that line has the same indentation as line 5.

Maybe you want something like ...  scan upwards until you find a line that is less indented than the current line ?

Graeme

« Last Edit: December 29, 2009, 10:06:24 PM by Graeme »

MartyL

  • Senior Community Member
  • Posts: 166
  • Hero Points: 29
  • Synergex
Hi tomm,

I threw VSE 9.0 onto a VM to see what I could find (I don't appear to have version 8.). It looks like the Python support in 9.0 included procedure tagging, so you should be able to navigate between procedures, at the very least, with next-proc and prev-proc (Ctrl+Down and Ctrl+Up, respectively). There is also end-proc which appears to work for getting you to the end of the procedure.

However, since I often run into these same problems, I've gone ahead a whipped up a little helper macro for navigating prev/next sibling and prev/next parent based on indentation. I haven't had time to test extensively, so let me know if you encounter any problems. Just save the file, select Macro > Load Module and select the file to load it. Then bind py-next-sibling, py-prev-sibling, py-next-parent and py-prev-parent as you see fit.

Hope this helps!
Marty
« Last Edit: December 30, 2009, 06:27:13 AM by MartyL »

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Sorry for all the "free code", but the last two commands should do what you want. This may or may not handle tabs correctly -- I dont use tabs so, probably not. Also my typical indent is 2 chars in case you have to tweak this code. (and yes, I know there is an easier way to do this but my brain isnt in gear at the moment)


Code: [Select]
  _str    at_line_left_str(int offset=0)
   {
      get_line(line);
      l=substr(line,1,offset+p_col-1);
      return l;
   }
boolean valid_line(int l0)
{
   if (l0<1||p_Noflines<l0) {
      return false;
   }
   return true;
}
  int     at_line_text(_str &text,int offset=0,int line=p_line)
   {
      if (!valid_line(line+offset)) {return (-1);}
      save_pos(p);
      p_line=line+offset;
      get_line(text);
      restore_pos(p);
      return 0;
   }
  boolean at_line_flag(int offset=0,int line=p_line,int flag=0)
   {
      if (valid_line(line+offset)==false) {
         return false;
      }
      save_pos(p);
      p_line=line+offset;
      l=_lineflags();
      restore_pos(p);
      return (l&flag);
   }
  boolean at_line_minus(int offset=0,int line=p_line)
   {
      return at_line_flag(offset,line,MINUSBITMAP_LF);
   }
  boolean at_line_hid(int offset=0,int line=p_line)
   {
      return at_line_flag(offset,line,HIDDEN_LF);
   }
boolean xt_seek_compare(int i1,int i2,_str op='==')
{
   if (op=='==') {return (i1==i2);}
   if (op=='!=') {return (i1!=i2);}
   if (op=='<') {return (i1<i2);}
   if (op=='>') {return (i1>i2);}
   if (op=='>=') {return (i1>=i2);}
   if (op=='<=') {return (i1<=i2);}
   //if (op=='<>') {return (i1<i2||);}
   return false;
}
  int     at_line_indent(int offset,int line=p_line)
   {
      status=at_line_text(text,offset,line);
      if (status) {return (-1);}
      t1=strip(text,"L"," ");
      v1=length(text)-length(t1);
      t2=strip(text,"L","\t");
      v2=length(text)-length(t2);
      return (v1+(v2*2));
   }
  boolean at_line_plus(int offset=0,int line=p_line)
   {
      return at_line_flag(offset,line,PLUSBITMAP_LF);
   }

int xt_seek_indents(int prev=0,int plus=0,int indent=-1,_str comp='==',int hid=0,int l=p_line,boolean ib=false)
{
   ol=l;
   //if (indent=-1) {indent=at_line_indent(0,l);}
   //if (indent=-1) {return (-1);}
   while (true) {
      if (prev==0) {l++;}else{l--;}
      if (!valid_line(l)) {return (-1);}
      //get_line(ln);
      //at_line_text(_str &text,int offset=0,int line=p_line)
      at_line_text(ln,0,l);
      //Msg('"'ln'"');
      if (ib&&ln=='') {
      }else{
         if (plus==0) {
            if (at_line_minus(0,l)) {
               if (hid==0) {
                  if (!at_line_hid(0,l)) {
                     if (indent!=-1) {
                        if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                           return l;
                        }
                     }else{
                        return l;
                     }
                  }
               }else if (hid==1) {
                  if (at_line_hid(0,l)) {
                     if (indent!=-1) {
                        if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                           return l;
                        }
                     }else{
                        return l;
                     }
                  }
               }else{
                  if (indent!=-1) {
                     if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                        return l;
                     }
                  }else{
                     return l;
                  }
               }
            }
         }else if (plus==1) {
            if (at_line_plus(0,l)) {
               if (hid==0) {
                  if (!at_line_hid(0,l)) {
                     if (indent!=-1) {
                        if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                           return l;
                        }
                     }else{
                        return l;
                     }
                  }
               }else if (hid==1) {
                  if (at_line_hid(0,l)) {
                     if (indent!=-1) {
                        if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                           return l;
                        }
                     }else{
                        return l;
                     }
                  }
               }else{
                  if (indent!=-1) {
                     if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                        return l;
                     }
                  }else{
                     return l;
                  }
               }
            }
         }else{
            if (hid==0) {
               if (!at_line_hid(0,l)) {
                  if (indent!=-1) {
                     if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                        return l;
                     }
                  }else{
                     return l;
                  }
               }
            }else if (hid==1) {
               if (at_line_hid(0,l)) {
                  if (indent!=-1) {
                     if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                        return l;
                     }
                  }else{
                     return l;
                  }
               }
            }else{
               if (indent!=-1) {
                  if (xt_seek_compare(at_line_indent(0,l),indent,comp)) {
                     return l;
                  }
               }else{
                  return l;
               }
            }
         }
      }
   }
   return (-1);
}

  _command void curs_seek_up_indent_same() name_info(','VSARG2_LASTKEY|VSARG2_CMDLINE|VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
   //curs_seek_up_indent_same is not bound to a key
  {
     //Msg(p_col);
     //int xt_seek_indents(
     // int prev=0,
     // int plus=0,
     // int indent=-1,
     // _str comp='==',
     // int hid=0,
     // int l=p_line
     // )
     save_pos(p);
     ll=at_line_left_str();ll=length(ll);
     restore_pos(p);
     int i=xt_seek_indents(1,-1,ll);
     //Msg(i);
     if (i>1) {
        goto_line(i);
     }
  }
  _command void curs_seek_down_indent_same() name_info(','VSARG2_LASTKEY|VSARG2_CMDLINE|VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
  {
     //Msg(p_col);
     //int xt_seek_indents(
     // int prev=0,
     // int plus=0,
     // int indent=-1,
     // _str comp='==',
     // int hid=0,
     // int l=p_line
     // )
     save_pos(p);
     ll=at_line_left_str();ll=length(ll);
     restore_pos(p);
     int i=xt_seek_indents(0,-1,ll);
     //Msg(i);
     if (i>1) {
        goto_line(i);
     }
  }