Nedit -- Wrap: Inline Streams

Tony Balinski ajbj at free.fr
Tue Jun 5 20:54:56 CEST 2007


Quoting "Waring, Steve (Central-Networks)"
<steve.waring at central-networks.co.uk>:

> Quoting Tony Balinski [ajbj at free.fr]
>
> > 		I adapted my shell SH rules to allow for this, but my
> > solution isn't ideal.
...
>
> > 		In a similar way I have "improved" case/esac
> > recognition, which also has a fragile relationship with the context
> > length.
>
> I have tried Tony's suggestion for the problem with a quote within an
> inline stream, and it works fine. Tony, can you share your suggestion
> for improving case/esac please?

I highlight case/esac as keywords. The highlighting for the case limbs is the
interesting bit, and relies on the fact that, if you disregard comments and
newlines, a case limb always starts *after* a in (highlighted as a keyword),
or after a ';;' case limb end.

So you can use lookbehind to check the (already highlighted) 'in' or ';;', but
then you must match spaces, newlines etc after that upto your case pattern.
This is what makes these patterns sensitive to context requirements.

I have the following set up, immediately after the 'comments' pattern:

case val: pass 1, highlight text matching regular expression
  RE: (?<=(?:<in>|;;))(?!\w)\s*(?:(?:(?:#.*)?\n\s*)*)[^)]*\)
  - matches from just after 'in' or ';;', upto the close paren of
    the case limb (styled as label)

case val comment: subpattern, highlight text matching RE
  (parent pattern: case val)
  RE: #.*
  - matches any comment(s) in the space following previous 'in'|';;'
    (styled as Comment)

case val punct: subpattern, highlight text matching RE
  (parent pattern: case val)
  RE: [|)]
  - matches the '|' alternative pattern separator and ending paren
    of the case limb (styled as Operator)

case val end: pass 1, highlight text matching regular expression
  RE: ;;(?n(?=\s*(?:esac|[^)]*\))))
  - matches a ';;' at the end of a case limb, either followed by
    an 'esac' or by a sequence ending with a close paren (presumably
    a new limb) - this won't handle trailing comments very well!
    (styled as Operator)

What's good: it makes the case patterns really stand out, and stops
  the close parens that end each case pattern from matching other
  parens nearby (if you have Default Settings > Show Matching (..) >
  Syntax Based option turned on). I use 3 lines of context for each
  of these patterns.
What's bad: sensitivity to context length (try adding blank lines
  between a ;; and the following limb, especially with a comment
  following the ;; on the same line, then a few newlines: spectacular
  SH "reinterpretation" guaranteed!). It also cannot handle close
  parens in the case pattern (excluding correct SH for extended file
  patterns in bash (extglob), say).

Share and enjoy!

Tony


More information about the Discuss mailing list