# ------------------------------------------------------------------------------ # makeSelectArray([start, end [, left, right [, cursor]]]): returns an array # holding the current cursor and selection details. Alternatively, # arguments may be passed in specifying the information. # The array indices are: # ["cursor"] current cursor position # ["select"] true (1) if there is a selection active # ["rect"] true (1) if there is a rectangular selection active # ["start"] the selection start position (if any) # ["end"] the selection end position (if any) # ["left"] the rectangular selection left edge column (if any) # ["right"] the rectangular selection right edge column (if any) # ["beg"] the smaller of ["cursor"] and ["start"] # ["end"] the larger of ["cursor"] and ["end"] # ------------------------------------------------------------------------------ define makeSelectArray { # default args use current selection start = $selection_start end = $selection_end left = $selection_left right = $selection_right cursor = $cursor # pick up specified args if ($n_args >= 2 && $1 <= $2) { start = $1 end = $2 } if ($n_args >= 4 && $3 <= $4) { left = $3 right = $4 } if ($n_args >= 5 && 0 <= $5) { cursor = $5 } a = $empty_array a["cursor"] = cursor a["select"] = 0 a["rect"] = 0 a["beg"] = cursor a["fin"] = cursor if (start >= 0) { a["select"] = 1 a["rect"] = 0 a["start"] = start a["end"] = end a["beg"] = min(cursor, start) a["fin"] = max(cursor, end) } if (left >= 0) { a["rect"] = 1 a["left"] = left a["right"] = right } return a } # ------------------------------------------------------------------------------ # reselectFromArray(selArray [, restoreCursor]): makes a selection using the # values stored in selArray, of the form returned by makeSelectArray(). # If restoreCursor is present and true (non-zero), the cursor position # is moved to the one stored in selArray too. # ------------------------------------------------------------------------------ define reselectFromArray { a = $1 restoreCursor = 0 if ($n_args > 1 && $2 != 0) restoreCursor = 1 if (!(("cursor" in a) && ("select" in a))) return reselectArray_calledWithNonSelectArray() if ("left" in a) select_rectangle(a["start"], a["end"], a["left"], a["right"]) else if ("start" in a) select(a["start"], a["end"]) # else not a valid selection if (restoreCursor) set_cursor_pos(a["cursor"]) }