Author Topic: Keep modified line flags on buffer close as well as buffer save  (Read 4059 times)

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
In my previous version SE2007, I swear I had my line flags persisting through buffer closes. Am I missing a setting? I have it flipped in the options to keep line flags on SAVE, which works. But I am in and out of files constantly and am used to managing my own line flags.

I traced out the slick-c code and I am not seeing where the dirty deed is being done. Has something fundamental changed? If there is not an option to flip, can someone point me to the right hooks so I can write this myself?

Thanks

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Keep modified line flags on buffer close as well as buffer save
« Reply #1 on: March 23, 2013, 02:46:45 AM »
They've never persisted across buffer closes.

However, closing a window doesn't necessarily close the buffer -- other things may hold onto the buffer.  The next time you open a window for that same file, it will use the still-open-but-hidden buffer.  This can give the illusion of line flags persisting across buffer closes.

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Re: Keep modified line flags on buffer close as well as buffer save
« Reply #2 on: March 25, 2013, 12:13:24 AM »
Ive found out there is a setting to save flags across buffer closes, but it only saves last 200 files.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Keep modified line flags on buffer close as well as buffer save
« Reply #3 on: March 25, 2013, 03:33:40 AM »
Wow, you're right.  So others don't have to hunt for it, here's where I found the setting:

Tools | Options, under Application Options \ Auto Restore, the option "Auto restore line modify".

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Re: Keep modified line flags on buffer close as well as buffer save
« Reply #4 on: March 25, 2013, 12:09:30 PM »
I knew I wasn't dreaming, now if I could only find that magic number 200. Like I haven't got plenty of disk. Just have to start using GUIDs for filenames and I am all set ;)

Yummy line flag macros ahead!
Note:name_info()s need fixing and there is probably a better way possibly involving marker_lines() -- but I forget.
Code: [Select]
#pragma option(strict2,on)
#include "slick.sh"
// if 1 this once you modify keys to taste
#if 0
defeventtab default_keys;
def 'A-S-END'= curs_line_clear_mods_group; //clear mod flags downward and seek next line with mods
def 'A--'= curs_line_clear_mods; //clear this lines flags and move cursor down
def 'A-INS' 'UP'= curs_up_to_mods; //move cursor to mods (see comments)
def 'A-INS' 'DOWN'= curs_down_to_mods; //move cursor to mods (see comments)
#endif
//paranoia, lets not hang
#define BAILOUTLOOP 10000

definit(){
  //The definit module is called before defload
  //the definit procedure is invoked each time the editor is invoked
  if (arg(1)!="L")  {
    //  This is an editor invocation
  }
}
defload(){
}

_command void curs_line_clear_mods() name_info(','){
  //curs_line_clear_mods is bound to Alt+-
  //clear current line line flags for modified and inserted and move cursor down
  _lineflags(0,MODIFY_LF);
  _lineflags(0,INSERTED_LINE_LF);
  cursor_down();
}
_command void curs_line_clear_mods_group() name_info(','){
  //curs_line_clear_mods_group is bound to Alt+Shift+End
  // clear mods from current line downward and seek the next group of mods
  // good for code change reviews
  typeless p;
  save_pos(p);
  int l=p_line;
  int f=0;
  int x=0;
  int fl=_lineflags();
  _lineflags(0,MODIFY_LF);
  _lineflags(0,INSERTED_LINE_LF);
  int atm=(fl&MODIFY_LF);
  int ati=(fl&INSERTED_LINE_LF);
  while (valid_line(l+1)) {
    x++;
    if (x>BAILOUTLOOP) {
      break;
    }
    p_line=p_line+1;
    l=p_line;
    fl=_lineflags();
    if (atm||ati) {
      if (!(fl&MODIFY_LF)&&!(fl&INSERTED_LINE_LF)) {
        f=1;
        break;
      }
    } else {
      if ((fl&MODIFY_LF)||(fl&INSERTED_LINE_LF)) {
        f=1;
        break;
      }
    }
    _lineflags(0,MODIFY_LF);
    _lineflags(0,INSERTED_LINE_LF);
  }
  if (f==0) {
    restore_pos(p);
    message('No mods found');
    return;
  }
  goto_line(p_line);
  curs_down_to_mods();
}
_command void curs_down_to_mods() name_info(','){
  //curs_down_to_mods is bound to A-Ins Down
  // find next line with mods if line has no mods or
  // find next line without mods
  int l=curs_down_mod_line();
  int m=curs_down_marker_line();
  if (l!=-1&&m!=-1) {
    if (l>m) {
      goto_line(l);
    } else {
      goto_line(m);
    }
  }
  if (l==-1&&m!=-1) {
    goto_line(m);
  }
  if (l!=-1&&m==-1) {
    goto_line(l);
  }
}
_command void curs_up_to_mods() name_info(','){
  //curs_up_to_mods is bound to A-Ins Up
  // find prev line with mods if line has no mods or
  // find prev line without mods
  int l=curs_up_mod_line();
  //say('l:'l);
  int m=curs_up_marker_line();
  //say('m:'m);
  if (l!=-1&&m!=-1) {
    if (l<m) {
      goto_line(l);
    } else {
      goto_line(m);
    }
  }
  if (l==-1&&m!=-1) {
    goto_line(m);
  }
  if (l!=-1&&m==-1) {
    goto_line(l);
  }
}




static int curs_down_mod_line(){
  //discover next mod line, keep pos
  typeless p;
   save_pos(p);
   int l=p_line;
   int f=0;
   int x=0;
   int fl=_lineflags();
   int atm=(fl&MODIFY_LF);
   int ati=(fl&INSERTED_LINE_LF);
   while (valid_line(l+1)) {
      x++;
      if (x>BAILOUTLOOP) {
         break;
      }
      p_line=p_line+1;
      l=p_line;
      fl=_lineflags();
      if (atm||ati) {
         if (!(fl&MODIFY_LF)&&!(fl&INSERTED_LINE_LF)) {
            f=1;
            break;
         }
      }else{
         if ((fl&MODIFY_LF)||(fl&INSERTED_LINE_LF)) {
           f=1;
           break;
         }
      }
   }
   if (f==0) {
      restore_pos(p);
      return -1;
   }
   int rv=p_line;
   restore_pos(p);
   return rv;
}
static int curs_up_mod_line(){
  //discover prev mod line, keep pos
  typeless p;
   save_pos(p);
   int l=p_line;
   int f=0;
   int x=0;
   int fl=_lineflags();
   int atm=(fl&MODIFY_LF);
   int ati=(fl&INSERTED_LINE_LF);
   while (valid_line(l-1)) {
      x++;
      if (x>BAILOUTLOOP) {
         break;
      }
      p_line=p_line-1;
      l=p_line;
      fl=_lineflags();
      if (atm||ati) {
         if (!(fl&MODIFY_LF)&&!(fl&INSERTED_LINE_LF)) {
            f=1;
            break;
         }
      }else{
         if ((fl&MODIFY_LF)||(fl&INSERTED_LINE_LF)) {
           f=1;
           break;
         }
      }
   }
   if (f==0) {
      restore_pos(p);
      return -1;
   }
   int rv=p_line;
   restore_pos(p);
   return rv;
}
static int curs_down_marker_line(){
  // finds next marker line - I forget what this means
   typeless a=marker_lines(p_window_id);
   int lx=p_line;
   int x;
   for (x=0;x<a._length();x++) {
     int ai=a[x];
     if (ai>p_line) {
        return ai;
     }
   }
   return -1;
}
static int curs_up_marker_line(){
  // finds prev marker line - I forget what this means
   typeless a=marker_lines(p_window_id);
   a=array_reverse(a);
   int lx=p_line;
   int x;
   for (x=0;x<a._length();x++) {
     int ai=a[x];
     if (ai<p_line) {
        return ai;
     }
   }
   return -1;
}
static typeless marker_lines(int wid){
   // I forget what this means too :)
   int list[];
   typeless a[];
   int x;
   for (x=1;x<wid.p_Noflines;x++) {
      _LineMarkerFindList(list,wid,x ,0,1);
      if (list._length()>0) {
         a[a._length()]=x;
      }
   }
   return a;
}
static typeless array_reverse(typeless (&a)[]){
  // reverse the array via copy
  typeless b[];
  int x=0;
  for (x=a._length()-1;x!=-1;x--) {
    b[b._length()]=a[x];
  }
  return b;
}
static boolean valid_line(int l0){
  if (l0<1||p_Noflines<l0) {
    return false;
  }
  return true;
}


chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Keep modified line flags on buffer close as well as buffer save
« Reply #5 on: March 25, 2013, 04:03:31 PM »
I think the 200 is probably related to performance as well, beyond just disk space cost.

Also, persisting line flags across sessions means that they'll get restored to incorrect places if you edit the file in another editor or sync the file with a source control system.  It also makes it more annoying when SE flags all lines as modified, it requires manual resets more often.

I think the 200 is in def_max_filepos, and can be increased up to 5000.  Is easy to find:  look up AutoRestoreLine flags in slick.sh, look for references for the line modify flag, bang you find the macro code and configurable constants, etc.