Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature request (@M):# with context matches



On Jan 30,  8:54am, Bart Schaefer wrote:
}
}     while (( ( hit = $list[(i)*$search_pattern*] ) < $#list ))
}     do
} 	print -r -- $list[hit-3,hit+3]
} 	shift $hit list
}     done
} 
} with some appropriate checking that (hit-3) doesn't become negative and
} wrap around to the other end of the array, and other foo to manage the
} possiblity of overlapping contexts.

If you don't care about multiple hits or merging overlapping contexts, you
can even mash this down to a single statement.

E.g.

torch% declare S=path		# Searching in $path
torch% integer hit=0 C=2	# Context is 2 elements
torch% print -rl ${${(P)S}[$((
mathsubst> (hit = ${${(P)S}[(i)*local*]}) > C
mathsubst> ? hit < $#path
mathsubst>   ? hit-C
mathsubst>   : hit
mathsubst> : 1
mathsubst> )),$((
mathsubst> hit < $#path
mathsubst> ? hit+C
mathsubst> : hit
mathsubst> ))]}
/home/schaefer/bin
/usr/local/bin
/bin
/usr/bin

(Math parsing permits embedded newlines, subscript parsing does not, thus
the placement of "[$((" and ")),$((" and "))]".)

Note the ?: ternary tests would be different if using (I) to search from
right to left.



Messages sorted by: Reverse Date, Date, Thread, Author