# ============================================================================== # DEBUG.nm # # Author: Tony Balinski # # This file contains the following functions: # DEBUG_focus_dbg_window (don't call this directly) # DEBUG # DEBUG_clear_all # DEBUG_mark_to # DEBUG_undo_to # DEBUG_s # DEBUG_s_nl # DEBUG_s_col # DEBUG_s_nl_col # ============================================================================== NEDIT_require_macro_file("redetab.nm") $DEBUG_WINDOW_NAME = "" $DEBUG_WINDOW_PATH = "" $DEBUG_WINDOW_UNDOS = 0 $DEBUG_WINDOW_CURSOR = 0 $DEBUG_can_call_DEBUG_focus_dbg_window = 0 $DEBUG_ENABLE = 1 # ============================================================================== # DEBUG_focus_dbg_window: creates the debug window if necessary, then makes it # current. It returns the name of the (previous) current window. # ============================================================================== define DEBUG_focus_dbg_window { w = $file_path $file_name if (!$DEBUG_ENABLE) return w if (!$DEBUG_can_call_DEBUG_focus_dbg_window) { dialog("Invalid call to DEBUG_focus_dbg_window()") return "" } if ($DEBUG_WINDOW_NAME == "") { new("window") focus_window("last") set_incremental_backup(0) set_incremental_search_line(0) set_make_backup_copy(0) set_statistics_line(0) set_overtype_mode(1) set_show_matching("off") set_statistics_line(0) set_locked(1) $DEBUG_WINDOW_PATH = $file_path $DEBUG_WINDOW_NAME = $file_name $DEBUG_WINDOW_CURSOR = 0 } else if (focus_window($DEBUG_WINDOW_PATH $DEBUG_WINDOW_NAME) == "") { $DEBUG_WINDOW_NAME = "" $DEBUG_WINDOW_PATH = "" $DEBUG_WINDOW_UNDOS = 0 $DEBUG_WINDOW_CURSOR = 0 DEBUG_focus_dbg_window() } return w } # ============================================================================== # DEBUG(text): writes text to the debug window. # ============================================================================== define DEBUG { if (!$DEBUG_ENABLE) return 0 if ($n_args < 1) return 0 highlight = ($n_args == 2 && tolower($2) == "highlight") add_highlight = ($n_args == 2 && tolower($2) == "add_highlight") highlight |= add_highlight $DEBUG_can_call_DEBUG_focus_dbg_window = 1 w = DEBUG_focus_dbg_window() $DEBUG_can_call_DEBUG_focus_dbg_window = 0 beg = $DEBUG_WINDOW_CURSOR end = $DEBUG_WINDOW_CURSOR + length($1) set_locked(0) $DEBUG_WINDOW_UNDOS++ replace_range(beg, beg, $1) set_locked(1) set_cursor_pos(end) $DEBUG_WINDOW_CURSOR = end if (highlight) { highlight = rangeset_get_by_name("highlight") if (!highlight) { highlight = rangeset_create() rangeset_set_name(highlight, "highlight") rangeset_set_color(highlight, "orange") rangeset_set_mode(highlight, "break") } if (!add_highlight) rangeset_subtract(highlight, 0, $text_length) rangeset_add(highlight, beg, end) } focus_window(w) return 1 } # ============================================================================== # DEBUG_clear_all(): calls undo() on the debug window until all undone. # ============================================================================== define DEBUG_clear_all { if (!$DEBUG_ENABLE) return $DEBUG_can_call_DEBUG_focus_dbg_window = 1 w = DEBUG_focus_dbg_window() $DEBUG_can_call_DEBUG_focus_dbg_window = 0 set_locked(0) while ($DEBUG_WINDOW_UNDOS--) { undo() $DEBUG_WINDOW_CURSOR = $cursor } replace_range(0, $text_length, "") set_locked(1) $DEBUG_WINDOW_UNDOS = 0 focus_window(w) } # ============================================================================== # DEBUG_mark_to(): returns the current $DEBUG_WINDOW_UNDOS value. # ============================================================================== define DEBUG_mark_to { return $DEBUG_WINDOW_UNDOS } # ============================================================================== # DEBUG_undo_to(undo_mark): calls undo() until $DEBUG_WINDOW_UNDOS == undo_mark. # ============================================================================== define DEBUG_undo_to { if (!$DEBUG_ENABLE) return $DEBUG_can_call_DEBUG_focus_dbg_window = 1 w = DEBUG_focus_dbg_window() $DEBUG_can_call_DEBUG_focus_dbg_window = 0 set_locked(0) undo_mark = $1 while ($DEBUG_WINDOW_UNDOS > undo_mark) { undo() $DEBUG_WINDOW_CURSOR = $cursor $DEBUG_WINDOW_UNDOS-- } set_locked(1) focus_window(w) } # ============================================================================== # DEBUG_s(text): returns the text string for "display", flattening newlines. # ============================================================================== define DEBUG_s { if (!$DEBUG_ENABLE) return $1 return converttabspace($1,0,"·"," "," ","»","¶","¤") } # ============================================================================== # DEBUG_s_nl(text): returns the text string for "display", with newlines. # ============================================================================== define DEBUG_s_nl { if (!$DEBUG_ENABLE) return $1 return converttabspace($1,0,"·"," "," ","»","¶\n","¤") } # ============================================================================== # DEBUG_s_col(text): returns the text string for "display", flattening newlines. # We use $column as a length specifying start column. # ============================================================================== define DEBUG_s_col { if (!$DEBUG_ENABLE) return $1 $DEBUG_can_call_DEBUG_focus_dbg_window = 1 w = DEBUG_focus_dbg_window() $DEBUG_can_call_DEBUG_focus_dbg_window = 0 for (fill = "________"; length(fill) < $column; fill = fill fill) continue s = substring(fill, 0, $column) $1 s = converttabspace(s,0,"·"," "," ","»","¶","¤") s = substring(s, $column) focus_window(w) return s } # ============================================================================== # DEBUG_s_nl_col(text): returns the text string for "display", with newlines. We # use $column as a length specifying start column. # ============================================================================== define DEBUG_s_nl_col { if (!$DEBUG_ENABLE) return $1 $DEBUG_can_call_DEBUG_focus_dbg_window = 1 w = DEBUG_focus_dbg_window() $DEBUG_can_call_DEBUG_focus_dbg_window = 0 for (fill = "________"; length(fill) < $column; fill = fill fill) continue s = substring(fill, 0, $column) $1 s = converttabspace(s,0,"·"," "," ","»","¶\n","¤") s = substring(s, $column) focus_window(w) return s }