Re: changing background colour on the current line only
Tony Balinski <[email protected]>
| Newsgroups | gmane.editors.nedit.user |
|---|---|
| Message-ID | <[email protected]> |
Quoting kuzn-Z+4OxV1pPnQgONJHhpZ/[email protected]: > Hi,> > > I worked for a company once which was using nedit, and had a macro which > > would toggle the background colour on the current line between normal -> > > yellow -> orange -> red -> normal. > > To highlight the current line you must patch the NEdit. > See Patch Collection > http://sourceforge.net/tracker/index.php?func=detail&aid=1058246&group_id=11005&atid=311005 > This patch produces highlighting you want (without the color rotating) and > many other features. You don't need that patch for the following. That patch provides a special background for the current line. Rangesets OTOH don't move with the cursor. > > This was really handy to tag the areas of code you were working on, > > especially when editing a few select lines within thousands of lines of > > code > > (i.e quick small bug fixes). > > > > Is this a script available somewhere? else I can't seem to find the macro > > subroutine to change the background colour.. it shouldn't be too hard to > > rewrite such a macro.. any pointers would be appreciated. > > > > You can try following macros. > > Cheers, > Alexey Kuznetsov > > $line_marking = $empty_array > $line_marking["\n"] = $empty_array > > define mark_line { > file = $file_path $file_name > if(!(file in $line_marking)) { > $line_marking[file] = rangeset_create() > $line_marking["\n"][file] = "yellow" > rangeset_set_color($line_marking[file], $line_marking["\n"][file]) > } > if($selection_start >= 0 && $selection_left < 0) { # Mark selection > rangeset_add($line_marking[file]) > return > } # Mark current line. > rangeset_add($line_marking[file],\ > search("^", $cursor, "regex", "backward"),\ > search("$", $cursor, "regex")) > } > > define unmark_line { > file = $file_path $file_name > if(file in $line_marking) { > i = rangeset_includes($line_marking[file], $cursor) > if(i) { > range = rangeset_range($line_marking[file], i) > rangeset_subtract($line_marking[file], range["start"], range["end"]) > } > } > } > > define rotate_color { > file = $file_path $file_name > if(file in $line_marking["\n"]) { > if($line_marking["\n"][file] == "") > $line_marking["\n"][file] = "yellow" > else if($line_marking["\n"][file] == "yellow") > $line_marking["\n"][file] = "orange" > else if($line_marking["\n"][file] == "orange") > $line_marking["\n"][file] = "red" > else if($line_marking["\n"][file] == "red") > $line_marking["\n"][file] = "" > rangeset_set_color($line_marking[file], $line_marking["\n"][file]) > } > } Here, you've got one rangeset for marking lines per file, and its color is changed by the rotate_color function. You probably want to have a number of rangesets, one for each color, and add/remove the current line with your macro to/from these sets. (Include the line terminating \n while you're at it, which will color the line beyond its RHS.) Use rangeset_set_name to provide a string name for each set, and rangeset_get_by_name to retrieve the id created with rangeset_create. Naming by color is a reasonable idea; by function might be better. A set of functions that can be used to make your life a little easier with rangesets were written by Uwe: http://nedit.hackvalue.nl/niki/index.php/RangesetMacroCollection (I use different ones, also based on the original rangeset interface.) Tony -- NEdit Discuss mailing list - [email protected] http://www.nedit.org/mailman/listinfo/discuss