[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding limit/expand to sh highlighting


On Tue, 3 Feb 2026 at 00:42, Bruce Steers <bsteers4@xxxxxxxxx> wrote:

> I've tried a number of things.
>
> placing...
>   limit
>   from /^function/
>
> in various places in the sh.highlight file, but no success
>
> i need to let the sh.highlignt file know a limit (function) beings in 1 of
> 2 ways
>
> function MyCommand() {
> }
> or just
> MyCommand() {
> }
>
> to be honest i don't really understand the new highlight system.
> I'm unsure of where to put the 'limit' definition in the file and what
> syntax to use to meet the above mentioned function definition.
>
> Any advice would be appreciated.
>
> Thanks
> BruceS
>

From what i understand from the wiki limit is an additional state added to
another state so i'm going the the state that has the function keyword.

like this...  (sh.highlight)
-------------
@include _number.regexp

  match /\\./
shebang{Shebang=Preprocessor}:
  from /^#!/
number:
  match /$(NUMBER)/
  match /$(NUMBER_HEXA)/
string.simple{String}:
  from ' to '
  escape:
    match /\\./
string.double{String}:
  from " to "
  escape:
    match /\\[$`'"\\]/
  expansion{Expansion=Datatype}:
    match /\$[A-Za-z0-9_]+/
  command{Expansion}:
    from ` to ` with sh
string.ansi{String}:
  from $' to '
  escape:
    match /\\[abeEfnrtv\\'"?]/
    match /\\[0-7]{3}/
    match /\\x[0-9a-fA-F]{2}/
    match /\\u[0-9a-fA-F]{4}/
    match /\\u[0-9a-fA-F]{8}/
    match /\\c[a-zA-Z]/
expansion{Expansion}:
  match /\$[A-Za-z0-9_]+/
command{Expansion}:
  from ` to ` with sh
keyword:
  keyword function do else test for to in fi if elif then return exit while
until done break continue select case esac
limit
  from /^function/
  from /\s*() {\s/
operator:
  symbol -gt -lt -ge -ne -le -eq
  symbol { } $ [ ] <<< . + << = >> == - ~ += ( , != * -= &= ) < % & @ ! ; >
| ? ^ : <= /
function{Command=Function}:
 keyword echo read cd which rm cp mv rmdir cat grep awk tr sed sleep clear
sudo su source eval export time date pwd set unset chown chmod exec alias
unalias bg bind builtin caller command compgen complete compopt declare
dirs disown enable fc fg getopts hash help history jobs kill let local
logout mapfile popd printf pushd readarray readonly shift shopt suspend
test times trap type typeset ulimit umask wait
symbol:
  match /[A-Za-z_][A-Za-z_0-9]*/
comment:
  from /^#/
  from /\s*#\s/
expansion.brace{Expansion}:
  from ${ to } with sh


I've tried various variations and cannot seem to get it working, my goal
being to have expandable/collapsible functions in sh

Respects
BruceS

Follow-Ups:
Re: adding limit/expand to sh highlightingBruce Steers <bsteers4@xxxxxxxxx>
References:
adding limit/expand to sh highlightingBruce Steers <bsteers4@xxxxxxxxx>