This set of scripts permits to push and pop bookmarks (with maximum stack depth of 24).  It can also invert the "currently active" bookmarks, and make "and" and "or" operations between active and top of stack.
A simple usage would be to save bookmarks before doing a search marking lines, and then restore bookmarks later.  Another example would be to bookmark all lines matching an expression but not matching another: mark lines you want to match, push, mark lines you do not want to match, invert, pop with "and" operation.
The stack is stored in the different bits of the Scintilla marker sets, and will thus show as different symbols in the bookmark margin.  Note that marking/unmarking lines by clicking in the margin does not work as we would expect (for lines having a bookmark on the stack); you should instead use the shortcut (Ctrl+F2).

# Push bookmarks (current bookmark is mask 0x1000000, we push it by shifting right all bookmark sets) ----
line = editor.markerNext(0, 0x1FFFFFF);
while line != -1:
    marks = editor.markerGet(line);
    marks = (marks&0x1000000) | (marks>>1);
    editor.markerDelete(line, -1); editor.markerAddSet(line, marks); # set markers (by deleting then adding)
    line = editor.markerNext(line+1, 0x1FFFFFF);

# Pop bookmarks (current bookmark is mask 0x1000000, we pop by shifting left all bookmark sets) ----
line = editor.markerNext(0, 0x1FFFFFF);
while line != -1:
    marks = editor.markerGet(line);
    marks = (marks<<1)&0x1FFFFFF;
    editor.markerDelete(line, -1); editor.markerAddSet(line, marks); # set markers (by deleting then adding)
    line = editor.markerNext(line+1, 0x1FFFFFF);

# Invert bookmarks (current bookmark is mask 0x1000000, we invert that bit in all bookmark sets) ----
for line in range(editor.getLineCount()):
    marks = editor.markerGet(line);
    marks = marks^0x1000000; # invert current "top" mark
    editor.markerDelete(line, -1); editor.markerAddSet(line, marks); # set markers (by deleting then adding)

# Pop bookmarks with "and" operation ----
line = editor.markerNext(0, 0x1FFFFFF);
while line != -1:
    marks = editor.markerGet(line);
    marks = (marks&(marks<<1))&0x1000000 | (marks<<1)&0x0FFFFFF;
    editor.markerDelete(line, -1); editor.markerAddSet(line, marks); # set markers (by deleting then adding)
    line = editor.markerNext(line+1, 0x1FFFFFF);

# Pop bookmarks with "or" operation ----
line = editor.markerNext(0, 0x1FFFFFF);
while line != -1:
    marks = editor.markerGet(line);
    marks = (marks|(marks<<1))&0x1000000 | (marks<<1)&0x0FFFFFF;
    editor.markerDelete(line, -1); editor.markerAddSet(line, marks); # set markers (by deleting then adding)
    line = editor.markerNext(line+1, 0x1FFFFFF);