Fwd: Highlighting arbitrary bits of text

Greg Edwards <[email protected]> Thu, 3 Mar 2011 10:11:44 +1100
Newsgroups gmane.editors.nedit.user
Message-ID <[email protected]>
Nedit team,

Thanks to Tony Balinkski for pointing me at rangesets below. Nice to
discover your requirement is already implemented.

I had trouble finding anything on rangesets on nedit.org, and the email
archives don;t seem searchable, but plain Google for "nedit rangeset
examples" brought up quite a bit.

To help anyone else, below is my implementation of what I wanted, hacked
from old code of Tony's. A simple ability to mark up some lines and pieces
of code, to keep them easily visible in one paned window while I edit
similar code in another pane. This is only a fraction of what rangesets can
do.

This is on Mac OS X 10.6.6, nedit 5.5.

Cheers,
Greg


----- from ~/.nedit/autoload.nm ------


$line_marking = $empty_array
$line_marking["\n"] = $empty_array

define mark_area {

   # Create range if we don't already have one
   file = $file_path $file_name
   if(!(file in $line_marking)) {
      $line_marking[file] = rangeset_create()
      $line_marking["\n"][file] = "orange"
      rangeset_set_color($line_marking[file], $line_marking["\n"][file])
   }

   # Mark selection if we have one
   if($selection_start >= 0 && $selection_left < 0) {
      rangeset_add($line_marking[file])
      return
   }

   # Mark current line.
   rangeset_add($line_marking[file],\
               search("^", $cursor, "regex", "backward"),\
               search("$", $cursor, "regex"))
}

define unmark_area {

   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 undefine_range {
   file = $file_path $file_name
   if((file in $line_marking)) {
     rangeset_destroy($line_marking[file])
   }
   $line_marking = $empty_array
   $line_marking["\n"] = $empty_array
}

---- from ~/.nedit/nedit.rc ------


Rangesets>Mark line/area:Shift+F1::: {\n\
           mark_area()\n\
}\n\
Rangesets>Unmark line/area:Shift+F2::: {\n\
           unmark_area()\n\
}\n\
Rangesets>Cancel rangeset:Shift+F3::: {\n\
           undefine_range()\n\
}\n\




---------- Forwarded message ----------
From: Tony Balinski <[email protected]>
Date: Tue, Feb 15, 2011 at 6:17 PM
Subject: Re: Highlighting arbitrary bits of text
To: General NEdit discussion list <[email protected]>




On 15 Feb 2011, at 03:13, Greg Edwards <[email protected]> wrote:

> Folks,
>
> I haven't researched this properly, apologies if it's obvious, or
> obviously
> impossible :=)
>
> I'd like to be able to highlight, in some colour or some background,
> some
> small pieces of code in a program being edited with Nedit, to server
> as
> reference and reminder for editing/checking/changing some other
> similar code
> further down in a file. This seems to be in the domain of highlighting
> syntax, but it's not constant highlighting of a set syntax style. I
> just
> want to sweep over some bits of code and highlight them somehow, and
> have
> them stay highlighted until further notice
(Sorry for the empty reply earlier: finger slipped over the iphone.)
This is what rangesets are for. You need to provide a macro that will
create a rangeset and provide ranges (start and end positions) for it.
You can also give it a color and a name. You can also write macros to
jump to a range in the set, add a searched string's occurrences to a
set etc. Look in nedit's help windows for more info; various people
have macro collections for this sort of thing too.
Tony
--
NEdit Discuss mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/discuss



-- 
Greg Edwards
[email protected]
-- 
NEdit Discuss mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/discuss