From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24191 invoked by alias); 29 Aug 2014 16:16:23 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33065 Received: (qmail 7337 invoked from network); 29 Aug 2014 16:16:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f776d000003e54-c0-5400a7468467 Date: Fri, 29 Aug 2014 17:16:05 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: PATCH: evaluation depth in prompts Message-id: <20140829171605.7bdac33b@pwslap01u.europe.root.pri> In-reply-to: <20140826181055.59c99bdc@pwslap01u.europe.root.pri> References: <20140826174029.6478ee3a@pwslap01u.europe.root.pri> <20140826181055.59c99bdc@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmluLIzCtJLcpLzFFi42I5/e/4FV235QwhBn+nGVgcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujNu/F7EULJOq2DD1CFsD4w6RLkZODgkBE4nPu86xQdhiEhfu rQeyuTiEBJYySly+9Z0ZwlnOJLH35E0mkCoWAVWJfT3TmUFsNgFDiambZjN2MXJwiAhoS7R/ FAMJCwvoS3x4vR4szCtgL7Fmug1ImFPAQWL1021gU4QESiV2/13NCmLzA5Vf/fuJCeIGe4mZ V84wgti8AoISPybfYwGxmQW0JDZva2KFsOUlNq95yzyBUWAWkrJZSMpmISlbwMi8ilE0tTS5 oDgpPddIrzgxt7g0L10vOT93EyMkAL/uYFx6zOoQowAHoxIP74sMhhAh1sSy4srcQ4wSHMxK Irx3lwCFeFMSK6tSi/Lji0pzUosPMTJxcEo1MDJKWgiFfrw8I9rcYFupOlOq4ySP9v8L6oIb NbLtxHe++cmvN+vNl5ff7hvfXZj5X/oAh/Hfj8sZfn3UNZ/z+hLrRha5S0onzueblMXlKjpN rdMWnG9hKfP3iivXN4sH9juYyp9dNUuakyzBpyhwt7kiVOht44H95hW2vz6E61q/M3MKV325 RomlOCPRUIu5qDgRAIThpk8eAgAA On Tue, 26 Aug 2014 18:10:55 +0100 Peter Stephenson wrote: > On Tue, 26 Aug 2014 17:40:29 +0100 > Peter Stephenson wrote: > > A better solution might be for a prompt escape that tracks the > > nesting level (which is trivial apart from picking a new letter). > > %e for evaluation depth (%E is taken but %e isn't). In case anyone's still following, here's the original script updated. This now gives reliable tracing of who's calling whom, even for functions calling themselves recursively, which I think was pretty much impossible to automate reliably before by means of prompt tracing --- you could hack it up or alternatively use debug traps and the functrace stuff. pws # Trivial function to trace the strcture of zsh function calls # with xtrace output using a PS4 containing %N and %i (see prompt_match # below). # # Input is stderr from a shell with xtrace active and a suitable PS4. # The completion system's ^X? binding can produce such output. # # For shells with %e (added in 5.0.7(?)): using PS4="+%e:%N:%i> " # allows better tracing by outputting the execution depth of the # construct being executed. # # If that's not available, the default PS4="+%N:%i> " is assumed. In # this case, because we can't be sure a change in execution is a new # call or a return to a previous function, we always assume the latter # where the names match. This is the normal case but may be wrong for # certain recursive structures. emulate -L zsh setopt extendedglob # Match lines for PS4="+%e:%N:%i> ". Adapt as appropriate. # With %e for evaluation depth. local eprompt_match="+(#b)([0-9]##):([^>]##):([0-9]##)> *" integer edepth_match=1 integer efunc_match=2 integer elineno_match=3 # Match lines for PS4="+%N:%i> ". Adapt as appropriate. # No evaluation depth. local prompt_match="+(#b)([^>]##):([0-9]##)> *" # Function name in $match[1] integer func_match=1 # Line number in $match[2] integer lineno_match=2 # Padding to indent a line local pad=" " local line func indent last_line integer lineno depth last_depth=-1 diff local -a match mbegin mend funcs while read line; do if [[ $line = ${~eprompt_match} ]]; then depth=$match[$edepth_match] func=$match[$efunc_match] lineno=$match[$elineno_match] if (( last_depth == -1 )); then print -r -- ${func}:${lineno} elif (( depth < last_depth )); then (( diff = last_depth - depth )) while (( diff-- )); do indent=${indent%%$pad} done elif (( depth > last_depth )); then (( diff = depth - last_depth )) while (( diff-- )); do indent+=$pad done print -r -- "$indent$last_line -> $func" fi last_depth=$depth last_line=${func}:${lineno} elif [[ $line = ${~prompt_match} ]]; then depth=$match[$depth_match] func=$match[$func_match] lineno=$match[$lineno_match] if (( ${#funcs} == 0 )); then print -r -- ${func}:${lineno} funcs+=($func) elif [[ $func != ${funcs[-1]} ]]; then if [[ $func = ${funcs[-2]} ]]; then funcs=(${funcs[1,-2]}) indent=${indent%%$pad} else indent+=$pad print -r -- "$indent$last_line -> $func" funcs+=($func) fi fi last_line=${func}:${lineno} fi done <${1:-/dev/stdin}