Highlight current line

Tony Balinski ajbj at free.fr
Wed Nov 29 12:56:44 CET 2006


Quoting Michael Smith <smithm at netapps.com.au>:

> On Wed, 29 Nov 2006 11:27:39 +0100
> <Ludger.Papenkort at dlr.de> wrote:
>
> > Hallo,
> >
> > how is it possible to highlight the current line ?
> >
> > Sometimes it is very usefull to highlight the line where the cursor is.
> > This feature would help to compare the text (numbers, tables or what
> > else) in the editor window with original text written on paper. You
> > could go through the text line by line with the cursor-down-key an
> > compare the highlighted line with the original.
> >
> > Is there a possibility to do that with a macro ?
>
> Yes
>
> define select_line
> {
>   start = search("\n",$cursor,"backward")
>   end = search("\n",$cursor,"forward")
>   select(start + 1,end + 1)
> }
>
> It could do with some refinement though. I don't think it works well on the
> first or last line of a file.
>
> No doubt others will post improved versions from their own collections
> shortly :)

Ha! If that's enough, then triple-click the line! I must say, I misread the
OP, thinking that this was a request to keep the cursor's line highlighted at
all times (which could still be useful for Ludger). But if you just want to be
able to add/remove a highlight on a line that just happens to be current, I
think Joerg has macros do that. Alternatively, you can set up this macro,
which just uses a rangeset instead of a selection for the highlighting:

# toggle the rangeset "Highlighted Lines" for the current line or selection
if ($selection_start >= 0)
  {
  left = $selection_start
  right = $selection_end - 1
  }
else
  {
  left = $cursor
  right = $cursor
  }

# extend to full lines
left = search("\n", left - 1, "backward") + 1
right = search("\n", right, "forward")
if (right < 0)
  right = $text_length
else
  ++right

# get our rangeset
rss = rangeset_get_by_name("Highlighted Lines")
if (rss[] == 0)
  {
  # no such rangeset: create it
  rs = rangeset_create()
  if (!rs)
    return dialog("Failed: could not create rangeset 'Highlighted Lines'")
  rangeset_set_color(rs, "lightgreen") # choose a color here
  rangeset_set_name(rs, "Highlighted Lines")
  }
else if (rss[] > 1)
  {
  # more than one rangeset with that name
  return dialog("Failed: more than one rangeset called 'Highlighted Lines'")
  }
else
  {
  # all OK
  rs = rss[0]
  }

# remove the area
if (rangeset_includes(rs, $cursor) != 0)
  rangeset_subtract(rs, left, right)
else
  rangeset_add(rs, left, right)




More information about the Discuss mailing list