4coder»Forums
Jason
196 posts
jump to previously opened buffer(s)
Edited by Jason on Reason: Initial post
Just wondering how I might go about jumping back to the previously viewed buffer? So if I was on line 400 in file A.h and switched to B.cpp, I could jump right back to A.h at line 400 if I needed to. Is there already a built in way to do this? Typically I like to be able to hit something like 'ctrl + tab' and cycle through previous opened buffers.
John
46 posts
jump to previously opened buffer(s)
On my end (Windows 10), this is how it already works. 4coder remembers the cursor line/column for every previously opened buffer.
Jason
196 posts
jump to previously opened buffer(s)
If it's built in Could you give me an example using 4coder's custom api how I would implement my desired behavior? That is "Ctrl + tab" to cycle back to previously opened buffers/files? I've had no luck trying to implement this so far.
John
46 posts
jump to previously opened buffer(s)
It's been a while since I messed with the custom layer so this might not be the best way:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
CUSTOM_COMMAND_SIG(cycle_open_buffers)
CUSTOM_DOC("Cycles through previously opened buffers in the current view")
{
    View_Summary view = get_active_view(app, AccessAll);
    static Buffer_Summary buf;
    get_buffer_next(app, &buf, AccessAll);
    
    if(buf.buffer_id == 0)
    {
        buf = get_buffer_first(app, AccessAll);
    }
    view_set_buffer(app, &view, buf.buffer_id, SetBuffer_KeepOriginalGUI);
}


Map this to CTRL + TAB and it should cycle through.
Note that the old documentation for "get_buffer_next" states:
"The global buffer order is kept roughly in the order of most recently used to least recently used".
So you might not get the cycle in the exact order you wanted.
Jason
196 posts
jump to previously opened buffer(s)
Ah, I see. Thanks so much for the help!