Author Topic: Limit Back() and Forward() toggle between 2 buffers only?  (Read 7701 times)

RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Limit Back() and Forward() toggle between 2 buffers only?
« on: April 11, 2015, 07:44:50 pm »
Hi, I would like to create a button/key stroke command to toggle between the last 2 visited buffers only. Does something like that exist? I looked but could not find anything in the docs. Thanks...

hs2

  • Senior Community Member
  • Posts: 2752
  • Hero Points: 291
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #1 on: April 11, 2015, 09:32:49 pm »
Nope - you need a custom macro for that. HS2

Graeme

  • Senior Community Member
  • Posts: 2638
  • Hero Points: 330

RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #3 on: April 15, 2015, 08:46:53 am »
Hi Graeme,

Thanks for the referral, which I tried. It worked but with one side effect. When you split a window and jump between buffers that spans windows, it creates a new tab within one of the windows that references one of the buffers. It then jumps between the two buffers within that same window. I wanted to be able to span windows so I wrote the following macro:

static boolean IsGotoNextBuffer;

_command void my_back() name_info(',')
{
    if (IsGotoNextBuffer) {
        back();           
    } else {               
        forward();         
    }                     
   IsGotoNextBuffer = !IsGotoNextBuffer;
}

This works how I wanted but with one strange side effect that I can't explain. If I assign this macro to a key, it works correctly 100% of the time. If I assign it to the forward or backward mouse button, it works but during every complete back and forth cycle one mouse click gets eaten up and nothing happens until it's pressed again...

Graeme

  • Senior Community Member
  • Posts: 2638
  • Hero Points: 330
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #4 on: April 15, 2015, 09:22:10 am »
Hi
I can't really reproduce the problem with your macro except for like this  - if you watch the green left arrow, right arrow buttons on the toolbar, you can see one of them grey out if you can't go forward any more or back any more.  At that point, using your macro may or may not do something, depending on what state the  IsGotoNextBuffer variable has been left in.  If that's the problem you could probably fix it by writing your own version of back and forward and making back set the variable false (and forward set it true) so that the next time you use my_back it will go forward.

I couldn't quite follow what you're doing with the "split a window" sequence  - e.g. "it creates a new tab"  - why does jumping between buffers create a new tab?  If you can spell out a precise set of steps (exactly what you do, which commands you use) that show what's going wrong I can investigate.  Also, do you have "one file per window" enabled and "smart next window" enabled?

I'm using 19.0.2 March 26 build.
« Last Edit: April 15, 2015, 09:28:53 am by Graeme »

RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #5 on: April 15, 2015, 03:19:56 pm »
 Hi Graeme,

I know what you're saying about the "IsGotoNextBuffer" inital state so the first click or keystroke when invoking the macro may or may not work. So I don't count it for my testing. Doesn't really matter, the results are obvious, either you moved buffers or not. If not, press the key or click again. It's what happens next that's the puzzle.

What I mean is, when I assign the "my_back()" macro to the F1 key it works correctly 100% of the time. It goes to the previous buffer the first time the key was pressed. Then back to the original buffer the next time the key is pressed. This happens consistently.

If it is assigned to the mouse back button, it goes back to the previous buffer on first click, goes foreward to the original buffer on second click, does nothing on the third click, then goes back to the previous buffer on the fourth click. And so on. This also happens consistently.

Why is it always going back and forth between the last two buffers when assigned to a keystroke, but taking 3 clicks when assigned to a mouse button? That is the mystery.

I stuck the following code at the beginning of the my_back() macro:

   mmcnt88 ++;
   say('mmcnt88: ' mmcnt88);
   say('IsGo: ' IsGotoNextBuffer);
   say('=====================');

with a statement:

static int mmcnt88 = 0;

just before the macro definition.

It got executed and logged each time the assigned F1 key was pressed.

For the mouse click it was different. The first click is logged and it goes to the previous buffer. The second click is NOT logged but goes to the original buffer. The third click is logged but does nothing. The fourth click is logged and goes back to the previous buffer. Consistently.

What is happening with the 2nd and 3rd clicks? Why does it change buffers on the second click but not get logged? Why does it get logged, but not do anything on the third click?




The split window/duplicate buffer business is not important. It happened with the macros you pointed me to, specifically the "goback_last_buffer()" macro in the GFilemanGoback.e file. Since I'm not using them it no longer matters, that is, unless your interested, and I can tell you the exact sequence that I performed.

Settings:
"smart next window" is set to "no window reordering"
"one file per window" is enabled

I'm using v19.0.1.1 64-bit.


Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3396
  • Hero Points: 465
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #6 on: April 15, 2015, 03:22:18 pm »
Just to venture a guess, I wonder if you want this functionality in order to jump quickly between a .cpp file and a .h file (for example).   There is a command for that, edit_associated_file(), which is bound to Ctrl+` in most emulations.  This command works with numerous other languages also.

If you are using a split window and want to cycle between the two tab groups, you could use the next_tab_group() command.  This will also work with multiple tiles.

RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #7 on: April 15, 2015, 03:22:46 pm »
Here is the complete macro with the debug code:

static boolean IsGotoNextBuffer=true;
static int mmcnt88 = 0;

_command void my_back() name_info(',')
{
   mmcnt88 ++;
   say('mmcnt88: ' mmcnt88);
   say('IsGo: ' IsGotoNextBuffer);
   say('=====================');

    if (IsGotoNextBuffer) {
        back();           
    } else {               
        forward();         
    }                     
   IsGotoNextBuffer = !IsGotoNextBuffer;
}


RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #8 on: April 15, 2015, 03:26:02 pm »
Hi Dennis, thanks for replying.

I just wanted a simple command/mouse click to go back and forth between the last 2 visited files/buffers regardless of their types.

RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #9 on: April 15, 2015, 03:33:47 pm »
Dennis,
For example if I'm writing some code and remembered something similar in another program, even if it was a different language being able to jump back and forth. Or looking at a document then going to some code, etc. Just something quick and dirty.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3396
  • Hero Points: 465
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #10 on: April 15, 2015, 03:53:24 pm »
No problem.  Sometimes it helps to get at the reason for a feature because there may already be something that specifically addresses that problem.

hs2

  • Senior Community Member
  • Posts: 2752
  • Hero Points: 291
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #11 on: April 15, 2015, 03:54:52 pm »
@RobertH2: I wrote this 'raw' macro to toggle between last 2 buffers (bound to a key):
Code: [Select]
static _str old_buffer_name   = '';
/**
 * switch to the last (used) buffer
 *
 * @param doCenter   if 'true' the buffer is centered<br>
 *                   This can be useful when quick or visually comparing code snippets in 2 files.
 */
_command void switch_last_buffer( boolean doCenter = true )
{
   int numbuf = get_num_buffers();
   // say ("switch_last_buffer: old_buffer_name: '" old_buffer_name "' numbuf = " numbuf);
   if ( numbuf <= 1 ) return;

   int status = FILE_NOT_FOUND_RC;

   if ( old_buffer_name != '' )
   {
      // handle new <unnamed> buffers too
      _str old_buffer_name2 = ((_mdi.p_child.p_buf_name != '') ? _mdi.p_child.p_buf_name : "Untitled<"p_buf_id">");
      typeless buf_id=0;
      if ( _isno_name(old_buffer_name) )
      {
         parse old_buffer_name with '<' buf_id'>';
         _macro('m',_macro('s'));
         _macro_call('edit','+bi 'buf_id);
         status = edit('+bi 'buf_id);
         if ( ! status ) p_buf_flags=p_buf_flags & (~VSBUFFLAG_HIDDEN);
      }
      else if ( old_buffer_name != old_buffer_name2 )
      {
         _macro('m',_macro('s'));
         _macro_call('edit','+b 'old_buffer_name);
         status = edit('+b 'old_buffer_name);
         if ( ! status ) p_buf_flags=p_buf_flags & (~VSBUFFLAG_HIDDEN);
      }

      old_buffer_name = old_buffer_name2;
   }

   // use prev buffer as fallback
   if ( status ) prev_buffer();

   // auto-center can be useful when 'quick comparing' 2 locations
   if ( doCenter ) center_line();
}

Please note that it's not for public use since it doesn't cover all use cases and would need to be polished a bit ;)
Hence I didn't post it earlier. However, it might help you a bit to get your macro done.

Good luck,
HS2

Graeme

  • Senior Community Member
  • Posts: 2638
  • Hero Points: 330
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #12 on: April 16, 2015, 02:00:35 am »
Here is the complete macro with the debug code:

static boolean IsGotoNextBuffer=true;
static int mmcnt88 = 0;

_command void my_back() name_info(',')
{
   mmcnt88 ++;
   say('mmcnt88: ' mmcnt88);
   say('IsGo: ' IsGotoNextBuffer);
   say('=====================');

    if (IsGotoNextBuffer) {
        back();           
    } else {               
        forward();         
    }                     
   IsGotoNextBuffer = !IsGotoNextBuffer;
}

Your code works perfectly for me both on my home machine running 19.0.2 and work machine running 18.0.1.  I have "multiple files share window" and "smart next window" set.  I'm using BackButtonDn as the mouse event.

The third click might log but do nothing because the second click somehow bypassed your macro.

I can think of several things you could try e.g. a different mouse button, slick debugger, or add a call to _StackDump to the forward or back macros, or try a new empty config folder vs.exe +new -sc some-empty-folder.
BTW - have you seen SlickCMacroBestPractices.pdf in the installation docs folder.



RobertH2

  • Community Member
  • Posts: 20
  • Hero Points: 1
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #13 on: April 16, 2015, 12:57:49 pm »
@ hs2

Thanks so much for taking the time to put this together! Unfortunately it did not work as I wanted. My macro works fine for keystrokes but adds an extra, do nothing mouse click, when assigned to a mouse button. I do appreciate your efforts though, thanks...



@Graeme

Thanks for checking this out. It is not worth the effort to persue it further. I just thought someone would have a clue as to what is happening. Thanks. Also thanks for pointing me to the macro document. I'll check it out.

I've only been writing macros for SlickEdit for the last 2 weeks. I used SlickEdit for several years about 15 years ago (versions 3-6), so I'm reusing/recoding some of my old macros.


Graeme

  • Senior Community Member
  • Posts: 2638
  • Hero Points: 330
Re: Limit Back() and Forward() toggle between 2 buffers only?
« Reply #14 on: April 16, 2015, 01:25:09 pm »
ok.  I couldn't live without the ability to swap between the last two buffers.  It was one of the first macros I wrote for slickedit.  If backbuttondown can call the "back" macro successfully every single time then it should be able to call your own macro every single time (and it does for me, if I press the button correctly).

Have you tried xretrace, the second link I posted.  If you want me to take a look at the issue you had with split windows, let me know.