NEDIT_require_macro_file("extensions.nm") NEDIT_require_macro_file("RSextensions.nm") NEDIT_require_macro_file("RScolor.nm") NEDIT_require_macro_file("cygwin.nm") # ============================================================================== # goThereWindowsVC(): attempt to move to a line in a file specified by the # current line in "Windows VC" format from Microsoft's Visual C/C++ # compilers, ie () : . Any following # lines starting with tabs are included as content, part of a compiler # message. It colors the current line (and subsequent content lines # referencing the same destination), then attempts to open the file # mentioned and go to the line number. If this works, a calltip is # produced for the newly opened/raised file document, with the message # content. # ============================================================================== define goThereWindowsVC { $gothere[""] = 0 if ("Windows VC" in $gothere) { kill_calltip($gothere["Windows VC"]) delete $gothere["Windows VC"] } line = 0 file = "" mesg = "" if ($selection_start != -1) deselect_all() cursor = $cursor begin = start_of_line_pos() end = end_of_line_pos() s = get_range(begin, end) # look for "Windows VC" format, ie () : pos = search_string(s, "\\([0-9]+\\) :", 0, "regex") endpos = $search_end # extract pieces of the line if (pos != -1) { line = substring(s, pos + 1, endpos - 1) # line number file = substring(s, 0, pos) # file name mesg = substring(s, endpos) # line text if (search_string(file, "(^\\l:\\\\|\\\\)", 0, "regex") != -1) { ef = file # file name contains backslashes or starts with :\ - # use Cygwin convert key = "Windows VC" $sub_sep "convert pref" if (key in $gothere) { if ($gothere[key] == "DOS") ef = Cygwin_convertDOSpath(file, 1) if (ef != "") file = ef } else { ef = Cygwin_convertDOSpath(file, 1) if (ef == "") ef = file if (file != ef) { str = "" while (str == "") { str = list_dialog("Filename looks like a Windows/DOS path\n" \ "Which do you mean?", \ ef "\n" file, "OK", "Save choice", "Cancel") if ($list_dialog_button == 2) { if (str == file) $gothere[key] = "Unix" else $gothere[key] = "DOS" } else if ($list_dialog_button != 1) return } file = str } } } } # look for contiguous lines with the same file(line) : prefix if (pos != -1) { top = begin bottom = end + 1 matchfront = substring(s, 0, endpos) # search back line-by-line for (eol = begin - 1; eol >= 0; eol = start_of_line_pos(eol) - 1) { sol = start_of_line_pos(eol) if (sol != search(matchfront, sol, "case")) break # does not match our prefix top = sol txtpos = $search_end mesg = get_range(txtpos, eol + 1) mesg } # search forward line-by-line for (sol = bottom; sol < $text_length; sol = end_of_line_pos(sol) + 1) { if (sol != search(matchfront, sol, "case")) break # does not match our prefix txtpos = $search_end eol = end_of_line_pos(sol) mesg = mesg "\n" get_range(txtpos, eol) bottom = eol + 1 } mesg = break_lines_over(150, mesg) if (background_is_dark()) { contigColor = "#00407f" selectColor = "#00609F" } else { contigColor = "#80c0df" selectColor = "#a0e0FF" } # color the selection found for contiguous lines Y = rangeset_fetch("selected contiguous lines", "color", contigColor) rangeset_clear(Y) rangeset_add(Y, top, bottom) # color the selection found for the current line Z = rangeset_fetch("selected line", "color", selectColor) rangeset_clear(Z) rangeset_add(Z, begin, end) } file = NEDIT_remove_dotdot(file) if (line != 0 && file != "") { if (substring(file, 0, 1) != "/") # not an absolute path? { # try to find one which works f_ok = "" flast = "" path = $file_path if (path == "") { path = replace_in_string(shell_command("pwd", ""), "\n", "") path = path "/" } ftest = NEDIT_reduce_filename(path file) fcontent = read_file(ftest) if ($read_status) f_ok = f_ok ftest "\n" flast = ftest ftest = NEDIT_reduce_filename($NEDIT_START_DIR "/" file) if (flast != ftest) { fcontent = read_file(ftest) if ($read_status) f_ok = f_ok ftest "\n" f_ok = substring(f_ok, 0, -1) if (search_string(f_ok, "\n", 0) != -1) file = list_dialog("Alternatives are", f_ok) else if (f_ok != "") file = f_ok } else file = flast } } if (line != 0 && file != "") { fcontent = read_file(file) lost = file if ($file_path == substring(file, 0, length($file_path))) lost = substring(file, length($file_path)) if (!$read_status) { # see if we don't have a file of that name in the current directory or # below basefile = replace_in_string(file, "^.*/", "", "regex", "copy") list = shell_command("find " $file_path " -name " basefile " -print", "") # filter results for the correct file name filefilter = "^(?!/.*(?<=/)" quote_literal_as_regex(basefile) ").*\n" list = replace_in_string(list, filefilter, "", "regex", "copy") openfirst = 0 if (length(replace_in_string(list, "^.*$", "", "regex")) == 1) { # exactly one line generated in find's output openfirst = (substring(list, -1) == "\n") } if ($shell_cmd_status == 0 && list != "") { if (openfirst) { list = substring(list, 0, -1) first = list if ($file_path == substring(list, 0, length($file_path))) first = substring(list, length($file_path)) dlg_msg = "Could not find file:\n " lost dlg_msg = dlg_msg "\n\nIs the following file correct?\n\n " dlg_msg = dlg_msg first if (dialog(dlg_msg, "Yes", "Cancel") == 1) { file = list fcontent = read_file(file) } else return } else { dlg_msg = "Could not find file:\n " lost dlg_msg = dlg_msg "\n\nSelect one of the following (if correct):" file = list_dialog(dlg_msg, list, "OK", "Cancel") if (file != "" && $list_dialog_button == 1) fcontent = read_file(file) else return } } } if ($read_status) { # OK: open destination file open(file) focus_window(file) raise_window(file) seltext = "" goto_line_number(line) seltext = get_selection() # if the "grep" text doesn't match the text at the right position/line... if (mesg != "" && seltext != "" && (mesg "\n") != seltext) $gothere["Windows VC"] = calltip(mesg, -1, "tipText") } else { dialog("Could not open file for reading:\n" file) } } else { dialog("No file name found") } }