From 85c185aa895732e80d8865a851d3f7a27bbdcb5e Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Tue, 26 Jan 2016 22:47:59 -0800 Subject: 37802: Clarify zparseopts description. (This file inadvertently ommitted from previous commit.) --- Doc/Zsh/mod_zutil.yo | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/mod_zutil.yo b/Doc/Zsh/mod_zutil.yo index fd6f2f384..dc17161f1 100644 --- a/Doc/Zsh/mod_zutil.yo +++ b/Doc/Zsh/mod_zutil.yo @@ -179,13 +179,14 @@ item(tt(zregexparse))( This implements some internals of the tt(_regex_arguments) function. ) findex(zparseopts) -item(tt(zparseopts) [ tt(-DKME) ] [ tt(-a) var(array) ] [ tt(-A) var(assoc) ] var(spec) ...)( +item(tt(zparseopts) [ tt(-D) tt(-K) tt(-M) tt(-E) ] [ tt(-a) var(array) ] [ tt(-A) var(assoc) ] var(spec) ...)( This builtin simplifies the parsing of options in positional parameters, i.e. the set of arguments given by tt($*). Each var(spec) describes one option and must be of the form `var(opt)[tt(=)var(array)]'. If an option described by var(opt) is found in the positional parameters it is copied into the var(array) specified with the tt(-a) option; if the optional -`tt(=)var(array)' is given, it is instead copied into that array. +`tt(=)var(array)' is given, it is instead copied into that array, which +should be declared as a normal array and never as an associative array. Note that it is an error to give any var(spec) without an `tt(=)var(array)' unless one of the tt(-a) or tt(-A) options is used. @@ -232,7 +233,10 @@ first colon. ) enditem() -The options of tt(zparseopts) itself are: +The options of tt(zparseopts) itself cannot be stacked because, for +example, the stack `tt(-DEK)' is indistinguishable from a var(spec) for +the GNU-style long option `tt(--DEK)'. The options of tt(zparseopts) +itself are: startitem() item(tt(-a) var(array))( -- cgit v1.2.3 From 3b69b121def33bb02d01ba23a7148129ab2aed46 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 29 Jan 2016 09:18:34 +0000 Subject: 37831: typeset: Document exit status difference from parameter assignment statements --- ChangeLog | 5 +++++ Doc/Zsh/builtins.yo | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f7f8b218e..19a4d21f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-01-30 Daniel Shahaf + + * 37831: Doc/Zsh/builtins.yo: typeset: Document exit status + difference from parameter assignment statements + 2016-01-30 Jun-ichi Takimoto * 37838: Src/Builtins/rlimits.c, Src/Builtins/sched.c, diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index fb630a713..cdf405b13 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1826,6 +1826,23 @@ reserved word interface for tt(typeset) may cause problems with the output of `tt(typeset -p)', which assumes the reserved word interface is available in order to restore array and associative array values. +Unlike parameter assignment statements, tt(typeset)'s exit status on an +assignment that involves a command substitution does not reflect the exit +status of the command substitution. Therefore, to test for an error in +a command substitution, separate the declaration of the parameter from its +initialization: + +example(# WRONG +typeset var1=$(exit 1) || echo "Trouble with var1" + +# RIGHT +typeset var1 && var1=$(exit 1) || echo "Trouble with var1" +) + +To initialize a parameter var(param) to a command output and mark it readonly, +use tt(typeset -r )var(param) or tt(readonly )var(param) after the parameter +assignment statement. + If the shell option tt(TYPESET_SILENT) is not set, for each remaining var(name) that refers to a parameter that is already set, the name and value of the parameter are printed in the form of an assignment. -- cgit v1.2.3 From 31d0bc1cdce378b862f7878503195ff0cc1728d4 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 30 Jan 2016 13:07:04 -0800 Subject: 37844: reorder typeset introduction to keep related concepts together. --- ChangeLog | 5 +++++ Doc/Zsh/builtins.yo | 46 +++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 19a4d21f2..1b2c19f1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-01-30 Barton E. Schaefer + + * 37844: Doc/Zsh/builtins.yo: reorder typeset introduction to keep + related concepts together. + 2016-01-30 Daniel Shahaf * 37831: Doc/Zsh/builtins.yo: typeset: Document exit status diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index cdf405b13..365f8e1e6 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1763,18 +1763,31 @@ ifnzman(noderef(Local Parameters))\ retain their special attributes when made local. For each var(name)tt(=)var(value) assignment, the parameter -var(name) is set to var(value). All forms of the command -handle scalar assignment. +var(name) is set to var(value). -If any of the reserved words tt(declare), tt(export), tt(float), +If the shell option tt(TYPESET_SILENT) is not set, for each remaining +var(name) that refers to a parameter that is already set, the name and +value of the parameter are printed in the form of an assignment. +Nothing is printed for newly-created parameters, or when any attribute +flags listed below are given along with the var(name). Using +`tt(PLUS())' instead of minus to introduce an attribute turns it off. + +If no var(name) is present, the names and values of all parameters are +printed. In this case the attribute flags restrict the display to only +those parameters that have the specified attributes, and using `tt(PLUS())' +rather than `tt(-)' to introduce the flag suppresses printing of the values +of parameters when there is no parameter name. + +All forms of the command handle scalar assignment. Array assignment is +possible if any of the reserved words tt(declare), tt(export), tt(float), tt(integer), tt(local), tt(readonly) or tt(typeset) is matched when the -line is parsed (N.B. not when it is executed) the shell will try to parse -arguments as assignments, except that the `tt(+=)' syntax and the -tt(GLOB_ASSIGN) option are not supported. This has two major differences -from normal command line argument parsing: array assignment is possible, -and scalar values after tt(=) are not split further into words even if -expanded (regardless of the setting of the tt(KSH_TYPESET) option; this -option is obsolete). Here is an example: +line is parsed (N.B. not when it is executed). In this case the arguments +are parsed as assignments, except that the `tt(+=)' syntax and the +tt(GLOB_ASSIGN) option are not supported, and scalar values after tt(=) +are em(not) split further into words, even if expanded (regardless of the +setting of the tt(KSH_TYPESET) option; this option is obsolete). + +Examples of the differences between command and reserved word parsing: example(# Reserved word parsing typeset svar=$(echo one word) avar=(several words)) @@ -1843,19 +1856,6 @@ To initialize a parameter var(param) to a command output and mark it readonly, use tt(typeset -r )var(param) or tt(readonly )var(param) after the parameter assignment statement. -If the shell option tt(TYPESET_SILENT) is not set, for each remaining -var(name) that refers to a parameter that is already set, the name and -value of the parameter are printed in the form of an assignment. -Nothing is printed for newly-created parameters, or when any attribute -flags listed below are given along with the var(name). Using -`tt(PLUS())' instead of minus to introduce an attribute turns it off. - -If no var(name) is present, the names and values of all parameters are -printed. In this case the attribute flags restrict the display to only -those parameters that have the specified attributes, and using `tt(PLUS())' -rather than `tt(-)' to introduce the flag suppresses printing of the values -of parameters when there is no parameter name. - If no attribute flags are given, and either no var(name) arguments are present or the flag tt(+m) is used, then each parameter name printed is preceded by a list of the attributes of that parameter (tt(array), -- cgit v1.2.3 From 0baf57701c458b9497d402911fb77443b5be529c Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 31 Jan 2016 15:17:44 -0800 Subject: 37845: Forward-reference typeset instances where no parameter is created, and remove the obsolete statement about array assignments separated from typeset command on -p. --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 1b2c19f1a..acaf82201 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-01-30 Barton E. Schaefer + * 37845: Doc/Zsh/builtins.yo: Forward-reference typeset instances + where no parameter is created, and remove the obsolete statement + about array assignments separated from typeset command on -p. + * 37844: Doc/Zsh/builtins.yo: reorder typeset introduction to keep related concepts together. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 365f8e1e6..542cecffc 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1753,7 +1753,8 @@ xitem(SPACES()[ tt(+) | var(SCALAR)[tt(=)var(value)] var(array)[tt(=LPAR())var(v item(tt(typeset) tt(-f) [ {tt(PLUS())|tt(-)}tt(TUkmtuz) ] [ tt(+) ] [ var(name) ... ])( Set or display attributes and values for shell parameters. -A parameter is created for each var(name) that does not already refer +Except as noted below for control flags that change the behavior, +a parameter is created for each var(name) that does not already refer to one. When inside a function, a new parameter is created for every var(name) (even those that already exist), and is unset again when the function completes. See @@ -1909,8 +1910,7 @@ does not. ) item(tt(-p))( If the tt(-p) option is given, parameters and values are printed in the -form of a typeset command and an assignment (which will be printed -separately for arrays and associative arrays), regardless of other flags +form of a typeset command with an assignment, regardless of other flags and options. Note that the tt(-H) flag on parameters is respected; no value will be shown for these parameters. -- cgit v1.2.3 From dd2aa858073e57a52c541cce04fb99ba7553c6b8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 10 Oct 2015 12:09:26 +0200 Subject: unposted: complist module docs: Fix parameter name in an example. Submitted via GitHub (https://github.com/zsh-users/zsh/pull/6). --- ChangeLog | 5 +++++ Doc/Zsh/mod_complist.yo | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 190d2c31c..4fdefbafb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-02-07 Dominik Ritter + + * unposted: Doc/Zsh/mod_complist.yo: complist module docs: + Fix parameter name in an example. + 2016-02-07 Daniel Shahaf * unposted: README: Follow-up to 37833: extend description of diff --git a/Doc/Zsh/mod_complist.yo b/Doc/Zsh/mod_complist.yo index 164b5b03f..31aa656f1 100644 --- a/Doc/Zsh/mod_complist.yo +++ b/Doc/Zsh/mod_complist.yo @@ -150,8 +150,8 @@ containing the codes for ANSI terminals (see ifzman(the section `Other Functions' in zmanref(zshcontrib))\ ifnzman(noderef(Other Functions))\ ). For example, after loading tt(colors), one could use -`tt($colors[red])' to get the code for foreground color red and -`tt($colors[bg-green])' for the code for background color green. +`tt($color[red])' to get the code for foreground color red and +`tt($color[bg-green])' for the code for background color green. If the completion system invoked by compinit is used, these parameters should not be set directly because the system controls them -- cgit v1.2.3 From 1ab316c9b8bcf60db091ed0cabe3930a52a0d965 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 7 Feb 2016 21:01:08 +0000 Subject: 37895: $ZSH_SCRIPT is POSIX $0 but always availble --- Doc/Zsh/params.yo | 7 +++++++ Src/params.c | 1 + 2 files changed, 8 insertions(+) (limited to 'Doc') diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 672209267..ae859ce6c 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -951,6 +951,13 @@ track of versions of the shell during development between releases; hence most users should not use it and should instead rely on tt($ZSH_VERSION). ) +vindex(ZSH_SCRIPT) +item(tt(ZSH_SCRIPT))( +If zsh was invoked to run a script, this is the name of the script. +Otherwise, it is the name used to invoke the current shell. This is +the same as the value of tt($0) when the tt(POSIX_ARGZERO) option is +set, but is always available. +) item(tt(zsh_scheduled_events))( See ifzman(the section `The zsh/sched Module' in zmanref(zshmodules))\ ifnzman(noderef(The zsh/sched Module)). diff --git a/Src/params.c b/Src/params.c index 76ed61c39..0233e2b00 100644 --- a/Src/params.c +++ b/Src/params.c @@ -813,6 +813,7 @@ createparamtable(void) setsparam("TTY", ztrdup_metafy(ttystrname)); setsparam("VENDOR", ztrdup_metafy(VENDOR)); setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); + setsparam("ZSH_SCRIPT", ztrdup(posixzero)); setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION)); setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *))); -- cgit v1.2.3 From b0706d64eea55aebaad66a32510e40f41d15d32e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 7 Feb 2016 00:22:10 +0000 Subject: 37896: zshbuiltins: Document argv behaviour of 'source' without arguments --- ChangeLog | 3 +++ Doc/Zsh/builtins.yo | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 182535df8..12f5366cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-02-09 Daniel Shahaf + * 37896: Doc/Zsh/builtins.yo: zshbuiltins: Document argv + behaviour of 'source' without arguments + * unposted: ChangeLog: Move the 37678 entry to the correct location (and author). diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 542cecffc..c425ff1cd 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -81,6 +81,10 @@ then commands are read from that file instead of var(file). If any arguments var(arg) are given, they become the positional parameters; the old positional parameters are restored when the var(file) is done executing. +However, if no arguments are given, +the positional parameters remain those of the calling context, +and no restoring is done. + If var(file) was not found the return status is 127; if var(file) was found but contained a syntax error the return status is 126; else the return status is the exit status of the last command executed. -- cgit v1.2.3 From db3f2d253cacd566f68ecc0dc942a596f89674df Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 9 Feb 2016 16:03:36 +0000 Subject: 37893: document typeset -U behaviour for PATH-style variables --- ChangeLog | 5 +++++ Doc/Zsh/builtins.yo | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 7faa5ecaf..9750ed11c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-02-09 Peter Stephenson + + * 37893: Doc/Zsh/builtins.yo: document behaviour of typeset -U + for parameters with multiple interfaces. + 2016-02-09 Daniel Shahaf * 37924: Completion/Unix/Command/_git: Completion: _git: diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index c425ff1cd..e3a6d564f 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -2001,6 +2001,11 @@ item(tt(-U))( For arrays (but not for associative arrays), keep only the first occurrence of each duplicated value. This may also be set for colon-separated special parameters like tt(PATH) or tt(FIGNORE), etc. +Note the flag takes effect on assignment, and the type of the +variable being assigned to is determinative; for variables with +shared values it is therefore recommended to set the flag for +all interfaces, e.g. `tt(typeset -U PATH path)'. + This flag has a different meaning when used with tt(-f); see below. ) item(tt(-Z) [ var(n) ])( -- cgit v1.2.3 From f96a0167289d41d583b01b17482bba0641be2805 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 14 Feb 2016 14:37:53 +0000 Subject: users/21256 + workers/37965: New math functions min(), max(), sum(), provided by a new autoloadable function 'zmathfunc'. --- ChangeLog | 7 +++++++ Doc/Zsh/contrib.yo | 17 +++++++++++++++++ Doc/Zsh/mod_mathfunc.yo | 5 +++++ Src/zsh.mdd | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index c94faad3a..92c50cd46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-02-16 Daniel Shahaf + + * users/21256 + workers/37965: Doc/Zsh/contrib.yo, + Doc/Zsh/mod_mathfunc.yo, Src/zsh.mdd: New math functions + min(), max(), sum(), provided by a new autoloadable function + 'zmathfunc'. + 2016-02-15 Eric Cook * 37975: Completion/Unix/Command/_php: allow completion after diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 07a5eb08e..f8754fbcc 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3796,6 +3796,23 @@ enditem() See the comments in the function for a few extra tips. ) +findex(max) +findex(min) +findex(sum) +findex(zmathfunc) +xitem(tt(min+LPAR())var(arg)tt(, ...+RPAR())) +xitem(tt(max+LPAR())var(arg)tt(, ...+RPAR())) +xitem(tt(sum+LPAR())var(arg)tt(, ...+RPAR())) +item(tt(zmathfunc))( +The function tt(zmathfunc) defines the three mathematical functions +tt(min), tt(max), and tt(sum). The functions tt(min) and tt(max) take +one or more arguments. The function tt(sum) takes zero or more arguments. +Arguments can be of different types (ints and floats). + +Not to be confused with the tt(zsh/mathfunc) module, described in +ifzman(the section `The zsh/mathfunc Module' in zmanref(zshmodules))\ +ifnzman(noderef(The zsh/mathfunc Module)). +) findex(zmathfuncdef) item(tt(zmathfuncdef) [ var(mathfunc) [ var(body) ] ])( A convenient front end to tt(functions -M). diff --git a/Doc/Zsh/mod_mathfunc.yo b/Doc/Zsh/mod_mathfunc.yo index 5239da5f8..8b72de3ab 100644 --- a/Doc/Zsh/mod_mathfunc.yo +++ b/Doc/Zsh/mod_mathfunc.yo @@ -36,6 +36,11 @@ that it is therefore only useful immediately after a call to tt(gamma) or tt(lgamma). Note also that `tt(signgam+LPAR()RPAR())' and `tt(signgam)' are distinct expressions. +The functions tt(min), tt(max), and tt(sum) are defined not in this module +but in the tt(zmathfunc) autoloadable function, described in +ifzman(the section `Mathematical Functions' in zmanref(zshcontrib))\ +ifnzman(noderef(Mathematical Functions)). + The following functions take two floating point arguments: tt(copysign), tt(fmod), tt(hypot), tt(nextafter). diff --git a/Src/zsh.mdd b/Src/zsh.mdd index 86dd58866..324435d62 100644 --- a/Src/zsh.mdd +++ b/Src/zsh.mdd @@ -2,7 +2,7 @@ name=zsh/main link=static load=yes # load=static should replace use of alwayslink -functions='Functions/Chpwd/* Functions/Exceptions/* Functions/Misc/* Functions/MIME/* Functions/Prompts/* Functions/VCS_Info/* Functions/VCS_Info/Backends/*' +functions='Functions/Chpwd/* Functions/Exceptions/* Functions/Math/* Functions/Misc/* Functions/MIME/* Functions/Prompts/* Functions/VCS_Info/* Functions/VCS_Info/Backends/*' nozshdep=1 alwayslink=1 -- cgit v1.2.3 From 440c6beec09b3b4ba68955d807d48acef0d4360a Mon Sep 17 00:00:00 2001 From: Greg Klanderman Date: Sun, 6 Mar 2016 09:53:40 -0800 Subject: 38086: shuffle init code to localize a global, add $ZSH_ARGZERO, refine $ZSH_SCRIPT (also a couple of ChangeLog typos corrected -- Bart) --- ChangeLog | 10 ++++++++-- Doc/Zsh/params.yo | 19 ++++++++++++------- Src/init.c | 13 ++++++++----- Src/params.c | 6 ++---- 4 files changed, 30 insertions(+), 18 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 28ac59bd9..734d685fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-03-06 Barton E. Schaefer + + * Greg Klanderman: 38086: Doc/Zsh/params.yo, Src/init.c, + Src/params.c: shuffle init code to localize a global, add + $ZSH_ARGZERO, refine $ZSH_SCRIPT + 2016-03-04 Peter Stephenson * 38084: Baruch Siach: configure.ac: use the pcre-config we @@ -124,7 +130,7 @@ 2016-02-07 Peter Stephenson * 37895: Src/params.c, Doc/Zsh/parmas.yo: add ZSH_SCRIPT as - always available form of POISX $0. + always available form of POSIX $0. 2016-02-07 Dominik Ritter @@ -5516,7 +5522,7 @@ 2014-08-01 Peter Stephenson - * 32932: Src/glob.c, Src/utils.c: add hmkarray() and + * 32932: Src/subst.c, Src/utils.c: add hmkarray() and use to fix leak. 2014-07-31 Barton E. Schaefer diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ae859ce6c..d23c459a0 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -933,6 +933,13 @@ tt(zsh/zutil) module. ) enditem() ) +vindex(ZSH_ARGZERO) +item(tt(ZSH_ARGZERO))( +If zsh was invoked to run a script, this is the name of the script. +Otherwise, it is the name used to invoke the current shell. This is +the same as the value of tt($0) when the tt(POSIX_ARGZERO) option is +set, but is always available. +) vindex(ZSH_EXECUTION_STRING) item(tt(ZSH_EXECUTION_STRING))( If the shell was started with the option tt(-c), this contains @@ -951,17 +958,15 @@ track of versions of the shell during development between releases; hence most users should not use it and should instead rely on tt($ZSH_VERSION). ) -vindex(ZSH_SCRIPT) -item(tt(ZSH_SCRIPT))( -If zsh was invoked to run a script, this is the name of the script. -Otherwise, it is the name used to invoke the current shell. This is -the same as the value of tt($0) when the tt(POSIX_ARGZERO) option is -set, but is always available. -) item(tt(zsh_scheduled_events))( See ifzman(the section `The zsh/sched Module' in zmanref(zshmodules))\ ifnzman(noderef(The zsh/sched Module)). ) +vindex(ZSH_SCRIPT) +item(tt(ZSH_SCRIPT))( +If zsh was invoked to run a script, this is the name of the script, +otherwise it is unset. +) vindex(ZSH_SUBSHELL ) item(tt(ZSH_SUBSHELL))( Readonly integer. Initially zero, incremented each time the shell forks diff --git a/Src/init.c b/Src/init.c index 4097327ee..20a07eb0a 100644 --- a/Src/init.c +++ b/Src/init.c @@ -802,7 +802,7 @@ init_term(void) /**/ void -setupvals(char *cmd) +setupvals(char *cmd, char *runscript, char *zsh_name) { #ifdef USE_GETPWUID struct passwd *pswd; @@ -1089,6 +1089,9 @@ setupvals(char *cmd) if (cmd) setsparam("ZSH_EXECUTION_STRING", ztrdup(cmd)); + if (runscript) + setsparam("ZSH_SCRIPT", ztrdup(runscript)); + setsparam("ZSH_NAME", ztrdup(zsh_name)); /* NOTE: already metafied early in zsh_main() */ } /* @@ -1270,7 +1273,7 @@ run_init_scripts(void) /**/ void -init_misc(char *cmd) +init_misc(char *cmd, char *zsh_name) { #ifndef RESTRICTED_R if ( restricted ) @@ -1606,7 +1609,7 @@ mod_export int use_exit_printed; mod_export int zsh_main(UNUSED(int argc), char **argv) { - char **t, *runscript = NULL; + char **t, *runscript = NULL, *zsh_name; char *cmd; /* argument to -c */ int t0; #ifdef USE_LOCALE @@ -1660,14 +1663,14 @@ zsh_main(UNUSED(int argc), char **argv) SHTTY = -1; init_io(cmd); - setupvals(cmd); + setupvals(cmd, runscript, zsh_name); init_signals(); init_bltinmods(); init_builtins(); run_init_scripts(); setupshin(runscript); - init_misc(cmd); + init_misc(cmd, zsh_name); for (;;) { /* diff --git a/Src/params.c b/Src/params.c index 7c5f79fff..c6172e018 100644 --- a/Src/params.c +++ b/Src/params.c @@ -80,8 +80,7 @@ char *argzero, /* $0 */ *rprompt, /* $RPROMPT */ *rprompt2, /* $RPROMPT2 */ *sprompt, /* $SPROMPT */ - *wordchars, /* $WORDCHARS */ - *zsh_name; /* $ZSH_NAME */ + *wordchars; /* $WORDCHARS */ /**/ mod_export char *ifs, /* $IFS */ @@ -812,8 +811,7 @@ createparamtable(void) setsparam("OSTYPE", ztrdup_metafy(OSTYPE)); setsparam("TTY", ztrdup_metafy(ttystrname)); setsparam("VENDOR", ztrdup_metafy(VENDOR)); - setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); - setsparam("ZSH_SCRIPT", ztrdup(posixzero)); + setsparam("ZSH_ARGZERO", ztrdup(posixzero)); setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION)); setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *))); -- cgit v1.2.3 From db42e7c504d4e1ea316a3629b7d2a0206fda2354 Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Tue, 8 Mar 2016 21:31:13 +0900 Subject: 38108: enable to create both zsh_{a4,us}.pdf Default paper size is taken from LC_PAPER. Stop to check for pdfetex (obsolete and redundant). --- ChangeLog | 8 ++++++++ Config/defs.mk.in | 2 -- Doc/Makefile.in | 50 ++++++++++++++++++++++++++++++-------------------- Doc/ztexi.yo | 1 - configure.ac | 14 ++++++++++++-- 5 files changed, 50 insertions(+), 25 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f3af39aab..aadad0359 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2016-03-08 Jun-ichi Takimoto + + * 38074: Completion/Unix/Command/_git: _git reset HEAD: + complete only staged files + + * 38108: Config/defs.mk.in, Doc/Makefile.in, Doc/ztexi.yo, + configure.ac: enable to create both zsh_{a4,us}.pdf + 2016-03-07 Oliver Kiddle * 38043: Src/Zle/compcore.c, Src/Zle/complist.c, diff --git a/Config/defs.mk.in b/Config/defs.mk.in index 3c84610e8..2bc17482a 100644 --- a/Config/defs.mk.in +++ b/Config/defs.mk.in @@ -79,8 +79,6 @@ ANSI2KNR = @ANSI2KNR@ YODL = @YODL@ @YODL_OPTIONS@ YODL2TXT = @YODL@2txt YODL2HTML = @YODL@2html -PDFETEX = @PDFETEX@ -TEXI2PDF = @TEXI2PDF@ # install utility INSTALL_PROGRAM = @INSTALL_PROGRAM@ diff --git a/Doc/Makefile.in b/Doc/Makefile.in index d5899917e..2752096e4 100644 --- a/Doc/Makefile.in +++ b/Doc/Makefile.in @@ -39,9 +39,11 @@ LN_S = @LN_S@ @DEFS_MK@ MAKEINFO = makeinfo -TEXI2DVI = texi2dvi +TEXI2DVI = @TEXI2DVI@ DVIPS = dvips +TEXI2PDF = @TEXI2PDF@ TEXI2HTML = @TEXI2HTML@ +PAPERSIZE = @PAPERSIZE@ .SUFFIXES: .yo .1 @@ -86,33 +88,41 @@ Zsh/seealso.yo Zsh/tcpsys.yo Zsh/zftpsys.yo Zsh/zle.yo all: man $(runhelp) texi ../META-FAQ .PHONY: all -everything: all dvi html pdf info +everything: all html info zsh_a4.dvi zsh_us.dvi zsh_a4.pdf zsh_us.pdf \ + intro.a4.pdf intro.us.pdf .PHONY: everything dvi: zsh.dvi .PHONY: dvi -zsh.dvi: $(sdir)/zsh.texi - $(TEXI2DVI) $(sdir)/zsh.texi +zsh.dvi zsh_a4.dvi zsh_us.dvi: $(sdir)/zsh.texi + if test $@ = zsh_us.dvi || \ + { test $@ = zsh.dvi && test "$(PAPERSIZE)" = us; }; then \ + $(TEXI2DVI) -o $@ $(sdir)/zsh.texi; \ + else \ + $(TEXI2DVI) -o $@ -t @afourpaper $(sdir)/zsh.texi; \ + fi -pdf: zsh.pdf intro.a4.pdf intro.us.pdf +pdf: zsh.pdf intro.pdf .PHONY: pdf -zsh.pdf: $(sdir)/zsh.texi - if [ x$(TEXI2PDF) != x ]; then \ - $(TEXI2PDF) $(sdir)/zsh.texi; \ +zsh.pdf zsh_a4.pdf zsh_us.pdf: $(sdir)/zsh.texi + if test $@ = zsh_us.pdf || \ + { test $@ = zsh.pdf && test "$(PAPERSIZE)" = us; }; then \ + $(TEXI2PDF) -o $@ $(sdir)/zsh.texi; \ else \ - PDFTEX=$(PDFETEX) $(TEXI2DVI) --pdf $(sdir)/zsh.texi; \ + $(TEXI2PDF) -o $@ -t @afourpaper $(sdir)/zsh.texi; \ fi # Use roff2ps / ps2pdf because pdfroff produces doubled output. -intro.a4.pdf: $(sdir)/intro.ms - roff2ps -ms -P-pa4 < $(sdir)/intro.ms > intro.a4.ps - ps2pdf intro.a4.ps - -intro.us.pdf: $(sdir)/intro.ms - roff2ps -ms -P-pletter < $(sdir)/intro.ms > intro.us.ps - ps2pdf intro.us.ps +intro.pdf intro.a4.pdf intro.us.pdf: $(sdir)/intro.ms + if test $@ = intro.us.pdf || \ + { test $@ = intro.pdf && test "$(PAPERSIZE)" = us; }; then \ + roff2ps -ms -P-pletter < $(sdir)/intro.ms > intro.ps; \ + else \ + roff2ps -ms -P-pa4 < $(sdir)/intro.ms > intro.ps; \ + fi; \ + ps2pdf -sOutputFile=$@ intro.ps texi: $(sdir)/zsh.texi .PHONY: texi @@ -149,14 +159,14 @@ ps: us_ps a4_ps us_ps: zsh_us.ps .PHONY: us_ps -zsh_us.ps: zsh.dvi - $(DVIPS) -t letter -o $@ zsh.dvi +zsh_us.ps: zsh_us.dvi + $(DVIPS) -t letter -o $@ zsh_us.dvi a4_ps: zsh_a4.ps .PHONY: a4_ps -zsh_a4.ps: zsh.dvi - $(DVIPS) -t a4 -o $@ zsh.dvi +zsh_a4.ps: zsh_a4.dvi + $(DVIPS) -t a4 -o $@ zsh_a4.dvi html: zsh_toc.html .PHONY: html diff --git a/Doc/ztexi.yo b/Doc/ztexi.yo index e8783459e..7d52e6e91 100644 --- a/Doc/ztexi.yo +++ b/Doc/ztexi.yo @@ -53,7 +53,6 @@ def(texinfo)(2)(\ NOTRANS(\input texinfo.tex)+NL()\ NOTRANS(@c %**start of header)+NL()\ NOTRANS(@iftex)+NL()\ - NOTRANS(@afourpaper)+NL()\ NOTRANS(@setchapternewpage off)+NL()\ NOTRANS(@end iftex)+NL()\ NOTRANS(@setfilename )ARG1+NL()\ diff --git a/configure.ac b/configure.ac index 9947b1606..9ce3a4589 100644 --- a/configure.ac +++ b/configure.ac @@ -632,14 +632,24 @@ if test "x$ac_cv_prog_YODL" = xyodl; then fi AC_SUBST(YODL_OPTIONS) -AC_CHECK_PROGS([PDFETEX], [pdfetex], [: pdfetex]) -AC_CHECK_PROGS([TEXI2PDF], [texi2pdf], []) +AC_CHECK_PROGS([TEXI2DVI], [texi2dvi], [: texi2dvi]) +AC_CHECK_PROGS([TEXI2PDF], [texi2pdf], [: texi2pdf]) AC_CHECK_PROGS([TEXI2HTML], [texi2any texi2html], [: texi2html]) +if test x"$TEXI2PDF" != xtexi2pdf && test x"$TEXI2DVI" = xtexi2dvi; then + TEXI2PDF='texi2dvi --pdf' +fi + if test x"$TEXI2HTML" = xtexi2any; then TEXI2HTML='texi2any -c TEXI2HTML=1' fi +case "$LC_PAPER" in + ??_US*) PAPERSIZE=us ;; + *) PAPERSIZE=a4 ;; +esac +AC_SUBST(PAPERSIZE) + AC_CHECK_PROGS([ANSI2KNR], [ansi2knr], [: ansi2knr]) if test x"$ansi2knr" = xyes && test x"$ANSI2KNR" = x": ansi2knr"; then -- cgit v1.2.3 From bd06982b2354083db139b3ca65f999717a0c0b9c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 15 Mar 2016 00:06:48 +0000 Subject: 38155: docs: compsys: Clarify documentation of the 'filter' style. --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 71d8e12a4..956b145e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-03-15 Daniel Shahaf + + * 38155: Doc/Zsh/compsys.yo: docs: compsys: Clarify documentation + of the 'filter' style. + 2016-03-15 m0viefreak * 38151: Completion/Unix/Command/_git: fix tag name of remote diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 2aa0740b8..d478e818e 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1554,7 +1554,8 @@ of the links themselves. ) kindex(filter, completion style) item(tt(filter))( -This is used by the LDAP plugin for e-mail address completion to specify +The tt(ldap) plugin of email address completion (see tt(_email_addresses)) uses +this style to specify the attributes to match against when filtering entries. So for example, if the style is set to `tt(sn)', matching is done against surnames. Standard LDAP filtering is used so normal completion matching is bypassed. If this -- cgit v1.2.3 From 43e595712ce29e402bf11b27ef4262229f21bbdb Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 18 Mar 2016 21:22:58 +0000 Subject: unposted: Document run-help-* helper functions. --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index ba4e49f1d..169fcce9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-03-18 Daniel Shahaf + + * unposted: Doc/Zsh/contrib.yo: Document run-help-* helper + functions. + 2016-03-18 Mikael Magnusson * 38179: Completion/Unix/Command/_adb: Fix completion by mostly diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index f8754fbcc..923bb29a9 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -4047,12 +4047,29 @@ your search path, in order to be found and used by tt(run-help). startitem() findex(run-help-git) +findex(run-help-ip) +findex(run-help-openssl) +findex(run-help-p4) +findex(run-help-sudo) findex(run-help-svk) findex(run-help-svn) -xitem(tt(run-help-git)) -xitem(tt(run-help-svk)) +xitem(run-help-git) +xitem(run-help-ip) +xitem(run-help-openssl) +xitem(run-help-p4) +xitem(run-help-sudo) +xitem(run-help-svk) item(tt(run-help-svn))( -Assistant functions for the tt(git), tt(svk), and tt(svn) commands. +Assistant functions for the +tt(git), +tt(ip), +tt(openssl), +tt(p4), +tt(sudo), +tt(svk), +and +tt(svn), +commands. ) enditem() ) -- cgit v1.2.3 From cbc44bd64a39649b7c73123c6eb85559d8d26f6c Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 13 Mar 2016 22:51:11 +0100 Subject: 38145: ZLE parameters for isearch and completion suffixes --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 26 +++++++++++++++++++++++ Src/Zle/zle_params.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Src/vincent.zsh | 30 ++++++++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 Src/vincent.zsh (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 0d431456d..6c6e286e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-03-21 Peter Stephenson + + * m0viefreak: 38145: Doc/Zsh/zle.yo, Src/Zle/zle_params.c: Make + isearch and completion suffix variables visible as parameters. + 2016-03-19 Mikael Magnusson * 38186: Completion/Unix/Command/_adb: fix remote file completion, diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 414c8dd65..161cef77f 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -835,6 +835,19 @@ which always gives the number of the history line being added to the main shell's history. tt(HISTNO) refers to the line being retrieved within zle. ) +vindex(ISEARCH_ACTIVE) +vindex(ISEARCH_START) +vindex(ISEARCH_END) +xitem(tt(ISEARCH_ACTIVE) (integer)) +xitem(tt(ISEARCH_START) (integer)) +item(tt(ISEARCH_END) (integer))( +tt(ISEARCH_ACTIVE) indicates whether an incremental search minibuffer +is active. tt(ISEARCH_START) and tt(ISEARCH_END) give the location of +the matched pattern and are in the same units as tt(CURSOR). They are +only valid for reading when tt(ISEARCH_ACTIVE) is non-zero. + +All parameters are read-only. +) vindex(KEYMAP) item(tt(KEYMAP) (scalar))( The name of the currently selected keymap; read-only. @@ -977,6 +990,19 @@ and tt(zle_highlight); see ifzman(the section CHARACTER HIGHLIGHTING below)\ ifnzman(noderef(Character Highlighting)) for details. ) +vindex(SUFFIX_ACTIVE) +vindex(SUFFIX_START) +vindex(SUFFIX_END) +xitem(tt(SUFFIX_ACTIVE) (integer)) +xitem(tt(SUFFIX_START) (integer)) +item(tt(SUFFIX_END) (integer))( +tt(SUFFIX_ACTIVE) indicates whether an auto-removable completion suffix +is currently active. tt(SUFFIX_START) and tt(SUFFIX_END) give the +location of the suffix and are in the same units as tt(CURSOR). They are +only valid for reading when tt(SUFFIX_ACTIVE) is non-zero. + +All parameters are read-only. +) vindex(UNDO_CHANGE_NO) item(tt(UNDO_CHANGE_NO) (integer))( A number representing the state of the undo history. The only use diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index b5bb288f1..7cbb3df5a 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -103,6 +103,18 @@ static const struct gsu_integer yankend_gsu = { get_yankend, set_yankend, zleunsetfn }; static const struct gsu_integer yankactive_gsu = { get_yankactive, NULL, zleunsetfn }; +static const struct gsu_integer isearchstart_gsu = +{ get_isearchstart, NULL, zleunsetfn }; +static const struct gsu_integer isearchend_gsu = +{ get_isearchend, NULL, zleunsetfn }; +static const struct gsu_integer isearchactive_gsu = +{ get_isearchactive, NULL, zleunsetfn }; +static const struct gsu_integer suffixstart_gsu = +{ get_suffixstart, NULL, zleunsetfn }; +static const struct gsu_integer suffixend_gsu = +{ get_suffixend, NULL, zleunsetfn }; +static const struct gsu_integer suffixactive_gsu = +{ get_suffixactive, NULL, zleunsetfn }; static const struct gsu_array killring_gsu = { get_killring, set_killring, unset_killring }; @@ -152,6 +164,12 @@ static struct zleparam { { "YANK_START", PM_INTEGER, GSU(yankstart_gsu), NULL }, { "YANK_END", PM_INTEGER, GSU(yankend_gsu), NULL }, { "YANK_ACTIVE", PM_INTEGER | PM_READONLY, GSU(yankactive_gsu), NULL }, + { "ISEARCH_START", PM_INTEGER, GSU(isearchstart_gsu), NULL }, + { "ISEARCH_END", PM_INTEGER, GSU(isearchend_gsu), NULL }, + { "ISEARCH_ACTIVE", PM_INTEGER | PM_READONLY, GSU(isearchactive_gsu), NULL }, + { "SUFFIX_START", PM_INTEGER, GSU(suffixstart_gsu), NULL }, + { "SUFFIX_END", PM_INTEGER, GSU(suffixend_gsu), NULL }, + { "SUFFIX_ACTIVE", PM_INTEGER | PM_READONLY, GSU(suffixactive_gsu), NULL }, { "ZLE_STATE", PM_SCALAR | PM_READONLY, GSU(zle_state_gsu), NULL }, { NULL, 0, NULL, NULL } }; @@ -520,6 +538,48 @@ set_yankend(UNUSED(Param pm), zlong i) yanke = i; } +/**/ +static zlong +get_isearchstart(UNUSED(Param pm)) +{ + return isearch_startpos; +} + +/**/ +static zlong +get_isearchend(UNUSED(Param pm)) +{ + return isearch_endpos; +} + +/**/ +static zlong +get_isearchactive(UNUSED(Param pm)) +{ + return isearch_active; +} + +/**/ +static zlong +get_suffixstart(UNUSED(Param pm)) +{ + return zlecs - suffixlen; +} + +/**/ +static zlong +get_suffixend(UNUSED(Param pm)) +{ + return zlecs; +} + +/**/ +static zlong +get_suffixactive(UNUSED(Param pm)) +{ + return suffixlen; +} + /**/ static char * get_cutbuffer(UNUSED(Param pm)) diff --git a/Src/vincent.zsh b/Src/vincent.zsh new file mode 100644 index 000000000..65da7d764 --- /dev/null +++ b/Src/vincent.zsh @@ -0,0 +1,30 @@ +updprompt() +{ + psvar[2]="" + + unset _trapchld_called + local njobs jobstr + njobs=$#jobstates + [[ $njobs -gt 1 ]] && jobstr="s" + [[ $njobs -ge 1 ]] && jobstr=" $njobs job$jobstr |" + + echo 1 > /dev/tty + + [[ -n $TTY && $TERM == (xterm*|dtterm|mlterm|rxvt*|screen*) ]] && + { + [[ $TERM == screen* ]] || print -nP "\e]1;%m${ptsn:+[$ptsn]}:%.\x07" + print -nP "\e]2;${jobstr}${WINTITLE:+ $WINTITLE |} %n@%m - %~ | %y\x07" + } > /dev/tty + + echo 2 > /dev/tty +} + +TRAPCHLD() +{ + echo SIGCHLD 1 > /dev/tty + if [[ -o interactive && -n $TTY ]] then + updprompt + typeset -g _trapchld_called=1 + fi + echo SIGCHLD 2 > /dev/tty +} -- cgit v1.2.3 From 1ea94513cc329c682d1afeaecd3bbfc3c66882ab Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 26 Mar 2016 09:45:47 -0700 Subject: Dmitry Marakasov: 38162: accept G for gigabytes in limit command from github pull request - some formatting edited --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 1 + Src/Builtins/rlimits.c | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index a763ba2d7..b2ca1ae95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-03-26 Barton E. Schaefer + + * Dmitry Marakasov: 38162: accept G for gigabytes in limit command + 2016-03-21 Daniel Shahaf * 38182: Completion/Unix/Command/_git: Invoke reflog completion diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index e3a6d564f..7083817bf 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1083,6 +1083,7 @@ startsitem() sitem(var(n)tt(h))(hours) sitem(var(n)tt(k))(kilobytes (default)) sitem(var(n)tt(m))(megabytes or minutes) +sitem(var(n)tt(g))(gigabytes) sitem([var(mm)tt(:)]var(ss))(minutes and seconds) endsitem() diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c index 8b664e36a..29f97b41d 100644 --- a/Src/Builtins/rlimits.c +++ b/Src/Builtins/rlimits.c @@ -610,14 +610,16 @@ bin_limit(char *nam, char **argv, Options ops, UNUSED(int func)) return 1; } } else { - /* memory-type resource -- `k' and `M' modifiers are permitted, - meaning (respectively) 2^10 and 2^20. */ + /* memory-type resource -- `k', `M' and `G' modifiers are * + * permitted, meaning (respectively) 2^10, 2^20 and 2^30. */ val = zstrtorlimt(s, &s, 10); if (!*s || ((*s == 'k' || *s == 'K') && !s[1])) { if (val != RLIM_INFINITY) val *= 1024L; } else if ((*s == 'M' || *s == 'm') && !s[1]) val *= 1024L * 1024; + else if ((*s == 'G' || *s == 'g') && !s[1]) + val *= 1024L * 1024 * 1024; else { zwarnnam(nam, "unknown scaling factor: %s", s); return 1; -- cgit v1.2.3 From caff72941d86983b44103653895328b411b29b4e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 4 Apr 2016 14:53:11 +0100 Subject: 38236: Order of redirections is important. --- Doc/Zsh/redirect.yo | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Doc') diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo index 35fa773fd..66160a61e 100644 --- a/Doc/Zsh/redirect.yo +++ b/Doc/Zsh/redirect.yo @@ -234,6 +234,25 @@ example(date >foo | cat) writes the date to the file `tt(foo)', and also pipes it to cat. +Note also that redirections are always expanded in order. This happens +regardless of the setting of the tt(MULTIOS) option, but with the option +in effect there are additional consequences. For example, +the meaning of the expression tt(>&1) will change after a previous +redirection: + +example(date >&1 >output) + +In the case above, the tt(>&1) refers to the standard output at the +start of the line; the result is similar to the tt(tee) command. +However, consider: + +exmaple(date >output >&1) + +As redirections are evaluated in order, when the tt(>&1) is encountered +the standard output is set to the file tt(output) and another copy of +the output is therefore sent to that file. This is unlikely to be what +is intended. + If the tt(MULTIOS) option is set, the word after a redirection operator is also subjected to filename generation (globbing). Thus -- cgit v1.2.3 From 8fe58bf04734f7fb5155c79fc298d15b18704185 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 10 Apr 2016 11:07:44 -0700 Subject: m0viefreak: 38264: improve doc for 38145 --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index ac26813ee..a9b3d0afd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-04-10 Barton E. Schaefer + + * m0viefreak: 38264: Doc/Zsh/zle.yo: improve doc for 38145 + 2016-04-09 Barton E. Schaefer * unposted: Completion/Base/Widget/_complete_help: capture the diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 161cef77f..c482a4691 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -841,10 +841,11 @@ vindex(ISEARCH_END) xitem(tt(ISEARCH_ACTIVE) (integer)) xitem(tt(ISEARCH_START) (integer)) item(tt(ISEARCH_END) (integer))( -tt(ISEARCH_ACTIVE) indicates whether an incremental search minibuffer -is active. tt(ISEARCH_START) and tt(ISEARCH_END) give the location of -the matched pattern and are in the same units as tt(CURSOR). They are -only valid for reading when tt(ISEARCH_ACTIVE) is non-zero. +tt(ISEARCH_ACTIVE) indicates whether a part of the tt(BUFFER) is +currently matched by an incremental search pattern. tt(ISEARCH_START) +and tt(ISEARCH_END) give the location of the matched part and are +in the same units as tt(CURSOR). They are only valid for reading +when tt(ISEARCH_ACTIVE) is non-zero. All parameters are read-only. ) -- cgit v1.2.3 From f06be0ffcf2c134d0fe12ce7e83d8697923a5712 Mon Sep 17 00:00:00 2001 From: m0viefreak Date: Sun, 10 Apr 2016 14:57:51 +0200 Subject: 38291: Change names of ISEARCH_* parameters to ISEARCHMATCH_* --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 20 ++++++++++---------- Src/Zle/zle_params.c | 24 ++++++++++++------------ 3 files changed, 27 insertions(+), 22 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index e8bfad8c8..0710a0d82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-04-23 m0viefreak + + * 38291: Doc/Zsh/zle.yo, Src/Zle/zle_params.c: Change names of + ISEARCH_* parameters to ISEARCHMATCH_* + 2016-04-23 Barton E. Schaefer * Mikael Berthe: 38307: Src/Modules/pcre.c: PCRE segfault when diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index c482a4691..80d3f39d8 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -835,17 +835,17 @@ which always gives the number of the history line being added to the main shell's history. tt(HISTNO) refers to the line being retrieved within zle. ) -vindex(ISEARCH_ACTIVE) -vindex(ISEARCH_START) -vindex(ISEARCH_END) -xitem(tt(ISEARCH_ACTIVE) (integer)) -xitem(tt(ISEARCH_START) (integer)) -item(tt(ISEARCH_END) (integer))( -tt(ISEARCH_ACTIVE) indicates whether a part of the tt(BUFFER) is -currently matched by an incremental search pattern. tt(ISEARCH_START) -and tt(ISEARCH_END) give the location of the matched part and are +vindex(ISEARCHMATCH_ACTIVE) +vindex(ISEARCHMATCH_START) +vindex(ISEARCHMATCH_END) +xitem(tt(ISEARCHMATCH_ACTIVE) (integer)) +xitem(tt(ISEARCHMATCH_START) (integer)) +item(tt(ISEARCHMATCH_END) (integer))( +tt(ISEARCHMATCH_ACTIVE) indicates whether a part of the tt(BUFFER) is +currently matched by an incremental search pattern. tt(ISEARCHMATCH_START) +and tt(ISEARCHMATCH_END) give the location of the matched part and are in the same units as tt(CURSOR). They are only valid for reading -when tt(ISEARCH_ACTIVE) is non-zero. +when tt(ISEARCHMATCH_ACTIVE) is non-zero. All parameters are read-only. ) diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index 7cbb3df5a..c6387bfc7 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -103,12 +103,12 @@ static const struct gsu_integer yankend_gsu = { get_yankend, set_yankend, zleunsetfn }; static const struct gsu_integer yankactive_gsu = { get_yankactive, NULL, zleunsetfn }; -static const struct gsu_integer isearchstart_gsu = -{ get_isearchstart, NULL, zleunsetfn }; -static const struct gsu_integer isearchend_gsu = -{ get_isearchend, NULL, zleunsetfn }; -static const struct gsu_integer isearchactive_gsu = -{ get_isearchactive, NULL, zleunsetfn }; +static const struct gsu_integer isearchmatchstart_gsu = +{ get_isearchmatchstart, NULL, zleunsetfn }; +static const struct gsu_integer isearchmatchend_gsu = +{ get_isearchmatchend, NULL, zleunsetfn }; +static const struct gsu_integer isearchmatchactive_gsu = +{ get_isearchmatchactive, NULL, zleunsetfn }; static const struct gsu_integer suffixstart_gsu = { get_suffixstart, NULL, zleunsetfn }; static const struct gsu_integer suffixend_gsu = @@ -164,9 +164,9 @@ static struct zleparam { { "YANK_START", PM_INTEGER, GSU(yankstart_gsu), NULL }, { "YANK_END", PM_INTEGER, GSU(yankend_gsu), NULL }, { "YANK_ACTIVE", PM_INTEGER | PM_READONLY, GSU(yankactive_gsu), NULL }, - { "ISEARCH_START", PM_INTEGER, GSU(isearchstart_gsu), NULL }, - { "ISEARCH_END", PM_INTEGER, GSU(isearchend_gsu), NULL }, - { "ISEARCH_ACTIVE", PM_INTEGER | PM_READONLY, GSU(isearchactive_gsu), NULL }, + { "ISEARCHMATCH_START", PM_INTEGER, GSU(isearchmatchstart_gsu), NULL }, + { "ISEARCHMATCH_END", PM_INTEGER, GSU(isearchmatchend_gsu), NULL }, + { "ISEARCHMATCH_ACTIVE", PM_INTEGER | PM_READONLY, GSU(isearchmatchactive_gsu), NULL }, { "SUFFIX_START", PM_INTEGER, GSU(suffixstart_gsu), NULL }, { "SUFFIX_END", PM_INTEGER, GSU(suffixend_gsu), NULL }, { "SUFFIX_ACTIVE", PM_INTEGER | PM_READONLY, GSU(suffixactive_gsu), NULL }, @@ -540,21 +540,21 @@ set_yankend(UNUSED(Param pm), zlong i) /**/ static zlong -get_isearchstart(UNUSED(Param pm)) +get_isearchmatchstart(UNUSED(Param pm)) { return isearch_startpos; } /**/ static zlong -get_isearchend(UNUSED(Param pm)) +get_isearchmatchend(UNUSED(Param pm)) { return isearch_endpos; } /**/ static zlong -get_isearchactive(UNUSED(Param pm)) +get_isearchmatchactive(UNUSED(Param pm)) { return isearch_active; } -- cgit v1.2.3 From fea013b8e8cc3b2d8e7ca59c1f32b27cdf376155 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Fri, 29 Apr 2016 13:34:19 +0200 Subject: 38356: allow integers as curses colours --- ChangeLog | 5 ++++- Doc/Zsh/mod_curses.yo | 6 +++++- Src/Modules/curses.c | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 9577b14d3..29d2c386b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2016-04-29 Peter Stephenson - * Sebastian: 39354: Src/Modules/curses.c: alter internal return + * Sebastian: 38356: Src/Modules/curses.c, Doc/Zsh/mod_curses.yo: + allow integers as colours in curses. + + * Sebastian: 38354: Src/Modules/curses.c: alter internal return code so as not to mask curses error code. 2016-04-26 Barton E. Schaefer diff --git a/Doc/Zsh/mod_curses.yo b/Doc/Zsh/mod_curses.yo index 8104572a6..72dc4094a 100644 --- a/Doc/Zsh/mod_curses.yo +++ b/Doc/Zsh/mod_curses.yo @@ -111,7 +111,11 @@ Each var(fg_col)tt(/)var(bg_col) attribute (to be read as for character output. The color tt(default) is sometimes available (in particular if the library is ncurses), specifying the foreground or background color with which the terminal started. The color pair -tt(default/default) is always available. +tt(default/default) is always available. To use more than the 8 named +colors (red, green, etc.) construct the var(fg_col)tt(/)var(bg_col) +pairs where var(fg_col) and var(bg_col) are decimal integers, e.g +tt(128/200). The maximum color value is 254 if the terminal supports +256 colors. tt(bg) overrides the color and other attributes of all characters in the window. Its usual use is to set the background initially, but it will diff --git a/Src/Modules/curses.c b/Src/Modules/curses.c index 7fff858f4..63c6748f5 100644 --- a/Src/Modules/curses.c +++ b/Src/Modules/curses.c @@ -350,8 +350,20 @@ zcurses_colorget(const char *nam, char *colorpair) } *bg = '\0'; - f = zcurses_color(cp); - b = zcurses_color(bg+1); + + // cp/bg can be {number}/{number} or {name}/{name} + + if( cp[0] >= '0' && cp[0] <= '9' ) { + f = atoi(cp); + } else { + f = zcurses_color(cp); + } + + if( (bg+1)[0] >= '0' && (bg+1)[0] <= '9' ) { + b = atoi(bg+1); + } else { + b = zcurses_color(bg+1); + } if (f==-2 || b==-2) { if (f == -2) -- cgit v1.2.3 From 5b2b94918ae1b038144ac32c09805d97153f9f7d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 1 May 2016 13:05:08 +0100 Subject: unposted: typo in redirect doc --- ChangeLog | 4 ++++ Doc/Zsh/redirect.yo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index caebae18e..6d1c0ac14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-05-01 Peter Stephenson + + * unposted: Doc/Zsh/redirect.yo: typo. + 2016-05-01 Frank Terbeck * 38381: Completion/Unix/Command/_picocom: Add completion for diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo index 66160a61e..c793638b7 100644 --- a/Doc/Zsh/redirect.yo +++ b/Doc/Zsh/redirect.yo @@ -246,7 +246,7 @@ In the case above, the tt(>&1) refers to the standard output at the start of the line; the result is similar to the tt(tee) command. However, consider: -exmaple(date >output >&1) +example(date >output >&1) As redirections are evaluated in order, when the tt(>&1) is encountered the standard output is set to the file tt(output) and another copy of -- cgit v1.2.3 From 1bf2ba4f19fda52720cd19346d19b9b391c436c9 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Fri, 6 May 2016 21:32:01 +0200 Subject: unposted: Doc/Zsh/builtins.yo: Fix typo Found by Debian's lintian tool. --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 8237fcc51..6e6ea5d85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-05-06 Axel Beckert + + * unposted: Doc/Zsh/builtins.yo: Fix typo. + 2016-05-04 Daniel Shahaf * 38402: Completion/Zsh/Command/_precommand: Complete diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 7083817bf..1ca1f24a8 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1810,7 +1810,7 @@ example(# Normal builtin interface builtin typeset svar=$(echo two words)) The tt(builtin) keyword causes the above to use the standard builtin -interface to tt(typeset) in which argument parsing is perfomed in the same +interface to tt(typeset) in which argument parsing is performed in the same way as for other commands. This example creates a scalar tt(svar) containing the value tt(two) and another scalar parameter tt(words) with no value. An array value in this case would either cause an error or be -- cgit v1.2.3 From 21d4b4cc0ec21e204210328b63c1303c7dcfd702 Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Tue, 10 May 2016 19:19:01 +0900 Subject: 38458: mention the option -i of _multi_parts --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index cb0aa41bb..b5039a5bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-03-10 Jun-ichi Takimoto + + * Marko Myllynen: 38458: Doc/Zsh/compsys.yo: mention the option + -i of _multi_parts + 2016-05-09 Barton E. Schaefer * Jun T.: 38445 (+tweak): Test/C02cond.ztst: subsequent tests rely diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index d478e818e..203c436a5 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4416,7 +4416,7 @@ the time this function is called, tt(compstate[insert]) is cleared, so additional matches generated later are not inserted on the command line. ) findex(_multi_parts) -item(tt(_multi_parts) var(sep) var(array))( +item(tt(_multi_parts) [ tt(-i) ] var(sep) var(array))( The argument var(sep) is a separator character. The var(array) may be either the name of an array parameter or a literal array in the form -- cgit v1.2.3 From ac3173be90442033183877e65419393fd1d4e56b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 3 Jun 2016 20:50:20 +0000 Subject: 38593: _describe: Make documentation more greppable. Make the running text refer to the parameters using their names given in the signature. This enables the reader to search for the name given in the signature. --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 767af7991..af433876c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-06-04 Daniel Shahaf + + * 38593: Doc/Zsh/compsys.yo: _describe: Make documentation + more greppable. + 2016-06-04 Barton E. Schaefer * 38599: Src/subst.c: skip the "no such named directory" warning diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 203c436a5..c97f80f27 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4227,13 +4227,13 @@ different completion options var(opt)s. The var(descr) is taken as a string to display above the matches if the tt(format) style for the tt(descriptions) tag is set. This is followed by one or two names of arrays followed by options to pass to tt(compadd). The -first array contains the possible completions with their descriptions in +array var(name1) contains the possible completions with their descriptions in the form `var(completion)tt(:)var(description)'. Any literal colons in -var(completion) must be quoted with a backslash. If a second array is -given, it should have the same number of elements as the first; in this +var(completion) must be quoted with a backslash. If a var(name2) is +given, it should have the same number of elements as var(name1); in this case the corresponding elements are added as possible completions instead -of the var(completion) strings from the first array. The completion list -will retain the descriptions from the first array. Finally, a set of +of the var(completion) strings from var(name1). The completion list +will retain the descriptions from var(name1). Finally, a set of completion options can appear. If the option `tt(-o)' appears before the first argument, the matches added -- cgit v1.2.3 From 8e2ec4517fcce11475d579abb827d851f858d9aa Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 12 Jun 2016 18:50:10 -0700 Subject: 38670: New function for managing ZLE special widgets, modeled after Functions/Misc/add-zsh-hook. --- ChangeLog | 6 ++ Doc/Zsh/contrib.yo | 56 ++++++++++++++- Functions/Zle/add-zle-hook-widget | 140 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 Functions/Zle/add-zle-hook-widget (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 8c8a08948..8952bd009 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-06-12 Barton E. Schaefer + + * 38670: Doc/Zsh/contrib.yo, Functions/Zle/add-zle-hook-widget: + New function for managing ZLE special widgets, modeled after + Functions/Misc/add-zsh-hook. + 2016-06-09 Oliver Kiddle * 38579: Functions/Zle/bracketed-paste-magic: simplify saving diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 923bb29a9..dd643a140 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -292,11 +292,11 @@ cindex(hook function utility) startitem() findex(add-zsh-hook) -item(tt(add-zsh-hook) [ tt(-dD) ] [ tt(-Uzk) ] var(hook) var(function))( +item(tt(add-zsh-hook) [ tt(-L) | tt(-dD) ] [ tt(-Uzk) ] var(hook) var(function))( Several functions are special to the shell, as described in the section ifnzman(Special Functions, noderef(Functions))\ ifzman(SPECIAL FUNCTIONS, see zmanref(zshmisc)), -in that they are automatic called at a specific point during shell execution. +in that they are automatically called at specific points during shell execution. Each has an associated array consisting of names of functions to be called at the same point; these are so-called `hook functions'. The shell function tt(add-zsh-hook) provides a simple way of adding or @@ -312,6 +312,9 @@ var(function) is name of an ordinary shell function. If no options are given this will be added to the array of functions to be executed in the given context. +If the option tt(-L) is given, the current values for the hook arrays +are listed with tt(typeset). + If the option tt(-d) is given, the var(function) is removed from the array of functions to be executed. @@ -323,6 +326,55 @@ The options tt(-U), tt(-z) and tt(-k) are passed as arguments to tt(autoload) for var(function). For functions contributed with zsh, the options tt(-Uz) are appropriate. ) +findex(add-zle-hook-widget) +item(tt(add-zle-hook-widget) [ tt(-L) | tt(-dD) ] [ tt(-Uzk) ] var(hook) var(widgetname))( +Several widget names are special to the line editor, as described in the section +ifnzman(Special Widgets, noderef(Zle Widgets))\ +ifzman(Special Widgets, see zmanref(zshzle)), +in that they are automatically called at specific points during editing. +Unlike function hooks, these do not use a predefined array of other names +to call at the same point; the shell function tt(add-zle-hook-widget) +maintains a similar array and arranges for the special widget to invoke +those additional widgets. + +var(hook) is one of tt(isearch-exit), tt(isearch-update), +tt(line-pre-redraw), tt(line-init), tt(line-finish), tt(history-line-set), +or tt(keymap-select), corresponding to each of the special widgets +tt(zle-isearch-exit), etc. + +var(widgetname) is the name of a ZLE widget. If no options are given this +is added to the array of widgets to be invoked in the given hook context. +Note that the hooks are called as widgets, that is, with +`tt(zle var(widgetname) -Nw)' rather than as a function call. + +The arrays of var(widgetname) are maintained in several tt(zstyle) +contexts, one for each var(hook) context, with a style of `tt(widgets)'. +If the tt(-L) option is given, this set of styles is listed with +`tt(zstyle -L)'. These styles may be updated directly with tt(zstyle) +commands, but the special widgets that refer to the styles are created +only if tt(add-zle-hook-widget) is called to add at least one widget. + +If the option tt(-d) is given, the var(widgename) is removed from +the array of widgets to be executed. + +If the option tt(-D) is given, the var(widgetname) is treated as a pattern +and any matching names of widgets are removed from the array. + +If var(widgetname) does not name an existing widget when added to the +array, it is assumed that a shell function also named var(widgetname) is +meant to provide the implementation of the widget. This name is therefore +marked for autoloading, and the options tt(-U), tt(-z) and tt(-k) are +passed as arguments to tt(autoload) as with tt(add-zsh-hook). The +widget is also created with `tt(zle -N var(widgetname))' to cause the +corresponding function to be loaded the first time the hook is called. + +In addition, var(widgetname) may be of the form var(index)tt(:)var(name). +In this case var(index) is an integer which determines the order in +which the widget var(name) will be called relative to other widgets in +the array. Widgets having the same var(index) are called in unspecified +order, and all widgets declared with an index are called before any +widgets that have no index. +) enditem() texinode(Recent Directories)(Other Directory Functions)(Utilities)(User Contributions) diff --git a/Functions/Zle/add-zle-hook-widget b/Functions/Zle/add-zle-hook-widget new file mode 100644 index 000000000..eeb0191f0 --- /dev/null +++ b/Functions/Zle/add-zle-hook-widget @@ -0,0 +1,140 @@ +# Add to HOOK the given WIDGET +# +# HOOK is one of isearch-exit, isearch-update, line-pre-redraw, line-init, +# line-finish, history-line-set, keymap-select (the zle- prefix is not +# required). +# +# WIDGET may be of the form INDEX:NAME in which case the INDEX determines +# the order in which the widget executes relative to other hook widgets. +# +# With -d, remove the widget from the hook instead; delete the hook +# variable if it is empty. +# +# -D behaves like -d, but pattern characters are active in the +# widget name, so any matching widget will be deleted from the hook. +# +# Without -d, if the WIDGET is not already defined, a function having the +# same name is marked for autoload; -U is passed down to autoload if that +# is given, as are -z and -k. (This is harmless if the function is +# already defined.) The WIDGET is then created with zle -N. + +emulate -L zsh + +# Setup - create the base functions for hook widgets that call the others + +zmodload zsh/parameter || { + print -u2 "Need parameter module for zle hooks" + return 1 +} + +local -a hooktypes=( isearch-exit isearch-update + line-pre-redraw line-init line-finish + history-line-set keymap-select ) +# Stash in zstyle to make it global +zstyle zle-hook types $hooktypes + +for hook in $hooktypes +do + function zle-$hook { + local -a hook_widgets + local hook + # Values of these styles look like number:name + # and we run them in number order + # $funcstack is more reliable than $0 + # Also, ksh_arrays is annoying + emulate zsh -c 'zstyle -a $funcstack[2] widgets hook_widgets' + for hook in "${@${(@on)hook_widgets}#*:}" + do + zle "$hook" -Nw || return + done + return 0 + } +done + +# Redefine ourself with the setup left out + +function add-zle-hook-widget { + local -a hooktypes + zstyle -a zle-hook types hooktypes + + # This part copied from add-zsh-hook + local usage="Usage: $0 hook widgetname\nValid hooks are:\n $hooktypes" + + local opt + local -a autoopts + integer del list help + + while getopts "dDhLUzk" opt; do + case $opt in + (d) + del=1 + ;; + + (D) + del=2 + ;; + + (h) + help=1 + ;; + + (L) + list=1 + ;; + + ([Uzk]) + autoopts+=(-$opt) + ;; + + (*) + return 1 + ;; + esac + done + shift $(( OPTIND - 1 )) + + if (( list )); then + zstyle -L "zle-(${1:-${(@j:|:)hooktypes}})" widgets + return $? + elif (( help || $# != 2 || ${hooktypes[(I)${1#zle-}]} == 0 )); then + print -u$(( 2 - help )) $usage + return $(( 1 - help )) + fi + + local -aU extant_hooks + local hook="zle-${1#zle-}" + local fn="$2" + + if (( del )); then + # delete, if hook is set + if zstyle -g extant_hooks "$hook" widgets; then + if (( del == 2 )); then + set -A extant_hooks ${extant_hooks:#(<->:|)${~fn}} + else + set -A extant_hooks ${extant_hooks:#(<->:|)$fn} + fi + # unset if no remaining entries + if (( ${#extant_hooks} )); then + zstyle "$hook" widgets "${extant_hooks[@]}" + else + zstyle -d "$hook" widgets + fi + fi + else + zstyle -g extant_hooks "$hook" widgets + extant_hooks+=("$fn") + zstyle -- "$hook" widgets "${extant_hooks[@]}" + if [[ -z "${widgets[$fn]}" ]]; then + autoload "${autoopts[@]}" -- "$fn" + zle -N "$fn" + fi + if [[ -z "${widgets[$hook]}" ]]; then + zle -N "$hook" + fi + fi +} + +# Handle zsh autoloading conventions +if [[ "$zsh_eval_context" = *loadautofunc && ! -o kshautoload ]]; then + add-zle-hook-widget "$@" +fi -- cgit v1.2.3 From 7badf262c1a33c8c5f7ee8ccc152733fcb5a05f7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 10 Jun 2016 17:37:02 +0000 Subject: 38653 + 38657: 'functions -T' tracing: recurse into anonymous functions. --- ChangeLog | 4 ++++ Doc/Zsh/builtins.yo | 3 ++- Src/exec.c | 12 +++++++++--- Test/E02xtrace.ztst | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index b31543b4f..f6e70e50e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-06-13 Daniel Shahaf + * 38653 + 38657: Doc/Zsh/builtins.yo, Src/exec.c, + Test/E02xtrace.ztst: 'functions -T' tracing: recurse into + anonymous functions. + * 38651: Completion/Unix/Command/_git: Escape parameter arguments to _call_program. diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 1ca1f24a8..5c33cd1cf 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -2028,7 +2028,8 @@ The names refer to functions rather than parameters. No assignments can be made, and the only other valid flags are tt(-t), tt(-T), tt(-k), tt(-u), tt(-U) and tt(-z). The flag tt(-t) turns on execution tracing for this function; the flag tt(-T) does the same, but turns off tracing -on any function called from the present one, unless that function also +for any named (not anonymous) function called from the present one, +unless that function also has the tt(-t) or tt(-T) flag. The tt(-u) and tt(-U) flags cause the function to be marked for autoloading; tt(-U) also causes alias expansion to be suppressed when the function is loaded. See the diff --git a/Src/exec.c b/Src/exec.c index 2dcd5bcf5..515406f33 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4615,6 +4615,8 @@ exectime(Estate state, UNUSED(int do_exec)) /* Define a shell function */ +static const char *const ANONYMOUS_FUNCTION_NAME = "(anon)"; + /**/ static int execfuncdef(Estate state, Eprog redir_prog) @@ -4732,7 +4734,7 @@ execfuncdef(Estate state, Eprog redir_prog) if (!args) args = newlinklist(); - shf->node.nam = "(anon)"; + shf->node.nam = (char *) ANONYMOUS_FUNCTION_NAME; pushnode(args, shf->node.nam); execshfunc(shf, args); @@ -5165,8 +5167,12 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) if (flags & (PM_TAGGED|PM_TAGGED_LOCAL)) opts[XTRACE] = 1; - else if (oflags & PM_TAGGED_LOCAL) - opts[XTRACE] = 0; + else if (oflags & PM_TAGGED_LOCAL) { + if (shfunc->node.nam == ANONYMOUS_FUNCTION_NAME /* pointer comparison */) + flags |= PM_TAGGED_LOCAL; + else + opts[XTRACE] = 0; + } ooflags = oflags; /* * oflags is static, because we compare it on the next recursive diff --git a/Test/E02xtrace.ztst b/Test/E02xtrace.ztst index 093a587bd..6e425e703 100644 --- a/Test/E02xtrace.ztst +++ b/Test/E02xtrace.ztst @@ -127,3 +127,20 @@ ?+(eval):2> [[ 'f o' == f\ x* || 'b r' != z\ o && 'squashy sound' < 'squishy sound' ]] ?+(eval):3> [[ -e nonexistentfile || -z '' && -t 3 ]] ?+(eval):4> set +x + + # Part 1: Recurses into nested anonymous functions + fn() { + () { () { true } } + } + functions -T fn + fn + # Part 2: Doesn't recurse into named functions + gn() { true } + fn() { gn } + functions -T fn + fn +0:tracing recurses into anonymous functions +?+fn:1> '(anon)' +?+(anon):0> '(anon)' +?+(anon):0> true +?+fn:0> gn -- cgit v1.2.3 From 3859aac04e6331a939e3d6b33431ba24fb68e055 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 13 Jun 2016 16:06:22 +0100 Subject: users/21632: Use of REPORTMEMORY variable If the child's resisdent set size in megabytes exceeds this, print out the resource (TIMEFMT) string. Document you need to add memory usage to this by hand. --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 14 ++++++++++++++ Src/jobs.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 58 insertions(+), 14 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f6e70e50e..d5e7e588f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-06-13 Peter Stephenson + + * users/21632: Doc/Zsh/params.yo, Src/jobs.c: REPORTMEMORY + parameter gives minimum size to trigger usage report. + 2016-06-13 Daniel Shahaf * 38653 + 38657: Doc/Zsh/builtins.yo, Src/exec.c, diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index d23c459a0..b02d24efe 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1390,6 +1390,20 @@ item(tt(READNULLCMD) )( The command name to assume if a single input redirection is specified with no command. Defaults to tt(more). ) +vindex(REPORTMEMORY) +item(tt(REPORTMEMORY))( +If nonnegative, commands whose maximum resident set size (roughly +speaking, main memory usage) in megabytes is greater than this +value have timing statistics reported. The format used to output +statistics is the value of the tt(TIMEFMT) parameter, which is the same +as for the tt(REPORTTIME) variable and the tt(time) builtin; note that +by default this does not output memory usage. Appending +tt(" max RSS %M") to the value of tt(TIMEFMT) causes it to output the +value that triggered the report. If tt(REPORTTIME) is also in use, +at most a single report is printed for both triggers. This feature +requires the tt(getrusage()) system call, commonly supported by modern +Unix-like systems. +) vindex(REPORTTIME) item(tt(REPORTTIME))( If nonnegative, commands whose combined user and system execution times diff --git a/Src/jobs.c b/Src/jobs.c index 04cb6b344..3db2ed01f 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -884,37 +884,62 @@ should_report_time(Job j) struct value vbuf; Value v; char *s = "REPORTTIME"; - zlong reporttime; + zlong reporttime = -1; +#ifdef HAVE_GETRUSAGE + char *sm = "REPORTMEMORY"; + zlong reportmemory = -1; +#endif /* if the time keyword was used */ if (j->stat & STAT_TIMED) return 1; queue_signals(); - if (!(v = getvalue(&vbuf, &s, 0)) || - (reporttime = getintvalue(v)) < 0) { - unqueue_signals(); - return 0; - } + if ((v = getvalue(&vbuf, &s, 0))) + reporttime = getintvalue(v); +#ifdef HAVE_GETRUSAGE + if ((v = getvalue(&vbuf, &sm, 0))) + reportmemory = getintvalue(v); +#endif unqueue_signals(); + if (reporttime < 0 +#ifdef HAVE_GETRUSAGE + && reportmemory < 0 +#endif + ) + return 0; /* can this ever happen? */ if (!j->procs) return 0; if (zleactive) return 0; + if (reporttime >= 0) + { #ifdef HAVE_GETRUSAGE - reporttime -= j->procs->ti.ru_utime.tv_sec + j->procs->ti.ru_stime.tv_sec; - if (j->procs->ti.ru_utime.tv_usec + - j->procs->ti.ru_stime.tv_usec >= 1000000) - reporttime--; - return reporttime <= 0; + reporttime -= j->procs->ti.ru_utime.tv_sec + + j->procs->ti.ru_stime.tv_sec; + if (j->procs->ti.ru_utime.tv_usec + + j->procs->ti.ru_stime.tv_usec >= 1000000) + reporttime--; + if (reporttime <= 0) + return 1; #else - { - clktck = get_clktck(); - return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime); + { + clktck = get_clktck(); + if ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime) + return 1; + } +#endif } + +#ifdef HAVE_GETRUSAGE + if (reportmemory >= 0 && + j->procs->ti.ru_maxrss / 1024 > reportmemory) + return 1; #endif + + return 0; } /* !(lng & 3) means jobs * -- cgit v1.2.3 From 944ab1a7aae3fc4d8517e3c97acc4e292db1cb6a Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Thu, 16 Jun 2016 08:48:12 +0900 Subject: 38684: fix format in contrib.yo --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 83f346520..c03be8c4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-06-16 Jun-ichi Takimoto + + * 38684: Doc/Zsh/contrib.yo: fix format + 2016-06-14 Eric Cook * 38676: Marko Myllynen: Completion/Linux/Command/_pidof: diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index dd643a140..2164c04c9 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -345,7 +345,7 @@ tt(zle-isearch-exit), etc. var(widgetname) is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. Note that the hooks are called as widgets, that is, with -`tt(zle var(widgetname) -Nw)' rather than as a function call. +`tt(zle )var(widgetname)tt( -Nw)' rather than as a function call. The arrays of var(widgetname) are maintained in several tt(zstyle) contexts, one for each var(hook) context, with a style of `tt(widgets)'. @@ -365,7 +365,7 @@ array, it is assumed that a shell function also named var(widgetname) is meant to provide the implementation of the widget. This name is therefore marked for autoloading, and the options tt(-U), tt(-z) and tt(-k) are passed as arguments to tt(autoload) as with tt(add-zsh-hook). The -widget is also created with `tt(zle -N var(widgetname))' to cause the +widget is also created with `tt(zle -N )var(widgetname)' to cause the corresponding function to be loaded the first time the hook is called. In addition, var(widgetname) may be of the form var(index)tt(:)var(name). @@ -2146,7 +2146,7 @@ tt(match-word-context). This should not usually need to be called directly. ) tindex(bracketed-paste-magic) -item(bracketed-paste-magic)( +item(tt(bracketed-paste-magic))( The tt(bracketed-paste) widget (see ifzman(subsection Miscellaneous in zmanref(zshzle))ifnzman(noderef(Miscellaneous) in noderef(Zle Widgets))) inserts pasted text literally into the editor buffer rather than interpret -- cgit v1.2.3 From f497573c80eff3ee0434867e24c1a4dc67ad80ee Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 16 Jun 2016 09:33:49 +0100 Subject: unposted: fix pareentheses in man for getrusage() --- ChangeLog | 4 ++++ Doc/Zsh/params.yo | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index c03be8c4c..b567cf6f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-06-16 Peter Stephenson + + * unposted: Doc/Zsh/params.yo: fix parentheses for getrusage(). + 2016-06-16 Jun-ichi Takimoto * 38684: Doc/Zsh/contrib.yo: fix format diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index b02d24efe..55930ed7b 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1401,8 +1401,8 @@ by default this does not output memory usage. Appending tt(" max RSS %M") to the value of tt(TIMEFMT) causes it to output the value that triggered the report. If tt(REPORTTIME) is also in use, at most a single report is printed for both triggers. This feature -requires the tt(getrusage()) system call, commonly supported by modern -Unix-like systems. +requires the tt(getrusage+LPAR()RPAR()) system call, commonly supported by +modern Unix-like systems. ) vindex(REPORTTIME) item(tt(REPORTTIME))( -- cgit v1.2.3 From 4cacf1624f0393c43a9a2c3259957b8d78eb7609 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 16 Jun 2016 11:39:42 +0100 Subject: 38693: Add RPN mode to zcalc --- ChangeLog | 3 + Doc/Zsh/contrib.yo | 42 ++++++++++++- Functions/Misc/zcalc | 136 +++++++++++++++++++++++++++++++++------- Functions/Zle/zcalc-auto-insert | 3 +- 4 files changed, 160 insertions(+), 24 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index b567cf6f0..2ac9ceb63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-06-16 Peter Stephenson + * 38693: Doc/Zsh/contrib.yo, Functions/Misc/zcalc, + Functions/Zle/zcalc-auto-insert: Add RPN mode to zcalc. + * unposted: Doc/Zsh/params.yo: fix parentheses for getrusage(). 2016-06-16 Jun-ichi Takimoto diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 2164c04c9..64d93f9dc 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2993,6 +2993,9 @@ the variable tt(ZCALC_AUTO_INSERT_PREFIX). Hence, for example, typing `tt(PLUS()12)' followed by return adds 12 to the previous result. +If zcalc is in RPN mode (tt(-r) option) the effect of this binding is +automatically suppressed as operators alone on a line are meaningful. + When not in zcalc, the key simply inserts the symbol itself. ) enditem() @@ -3706,7 +3709,7 @@ sect(Mathematical Functions) startitem() findex(zcalc) -item(tt(zcalc) [ tt(-ef) ] [ var(expression) ... ])( +item(tt(zcalc) [ tt(-erf) ] [ var(expression) ... ])( A reasonably powerful calculator based on zsh's arithmetic evaluation facility. The syntax is similar to that of formulae in most programming languages; see @@ -3772,6 +3775,39 @@ If the option `tt(-f)' is set, all numbers are treated as floating point, hence for example the expression `tt(3/4)' evaluates to 0.75 rather than 0. Options must appear in separate words. +If the option `tt(-r)' is set, RPN (Reverse Polish Notation) mode is +entered. This has various additional properties: +startitem() +item(Stack)( +Evaluated values are maintained in a stack; this is contained in +an array named tt(stack) with the most recent value in tt(${stack[1]}). +) +item(Operators and functions)( +If the line entered matches an operator (tt(+), tt(-), tt(*), +tt(/), tt(**), tt(^), tt(|) or tt(&)) or a function supplied by the +tt(zsh/mathfunc) library, the bottom element or elements of the stack +are popped to use as the argument or arguments. The higher elements +of stack (least recent) are used as earlier arguments. The result is +then pushed into tt(${stack[1]}). +) +item(Expressions)( +Other expressions are evaluated normally, printed, and added to the +stack as numeric values. The syntax within expressions on a single line +is normal shell arithmetic (not RPN). +) +item(Stack listing)( +If an integer follows the option tt(-r) with no space, then +on every evaluation that many elements of the stack, where available, +are printed instead of just the most recent result. Hence, for example, +tt(zcalc -r4) shows tt($stack[4]) to tt($stack[1]) each time results +are printed. +) +item(Duplication)( +The pseudo-operator tt(=) causes the most recent element of +the stack to be duplicated onto the stack. +) +enditem() + The prompt is configurable via the parameter tt(ZCALCPROMPT), which undergoes standard prompt expansion. The index of the current entry is stored locally in the first element of the array tt(psvar), which can be @@ -3844,6 +3880,10 @@ always specified in decimal. `tt([#])' restores the normal output format. Note that setting an output base suppresses floating point output; use `tt([#])' to return to normal operation. ) +item(tt($)var(var))( +Print out the value of var literally; does not affect the calculation. +To use the value of var, omit the leading `tt($)'. +) enditem() See the comments in the function for a few extra tips. diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 857007a94..eb240b2ec 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -96,6 +96,20 @@ emulate -L zsh setopt extendedglob +zcalc_show_value() { + if [[ -n $base ]]; then + print -- $(( $base $1 )) + elif [[ $1 = *.* ]] || (( outdigits )); then + if [[ -z $forms[outform] ]]; then + print -- $(( $1 )) + else + printf "$forms[outform]\n" $outdigits $1 + fi + else + printf "%d\n" $1 + fi +} + # For testing in ZLE functions. local ZCALC_ACTIVE=1 @@ -103,15 +117,20 @@ local ZCALC_ACTIVE=1 # begin with _. local line ans base defbase forms match mbegin mend psvar optlist opt arg local compcontext="-zcalc-line-" -integer num outdigits outform=1 expression_mode -local -a expressions +integer num outdigits outform=1 expression_mode rpn_mode matched show_stack i +integer max_stack +local -a expressions stack match mbegin mend # We use our own history file with an automatic pop on exit. history -ap "${ZDOTDIR:-$HOME}/.zcalc_history" forms=( '%2$g' '%.*g' '%.*f' '%.*E' '') -zmodload -i zsh/mathfunc 2>/dev/null +local mathfuncs +if zmodload -i zsh/mathfunc 2>/dev/null; then + zmodload -P mathfuncs -FL zsh/mathfunc + mathfuncs="("${(j.|.)${mathfuncs##f:}}")" +fi autoload -Uz zmathfuncdef if (( ! ${+ZCALCPROMPT} )); then @@ -127,7 +146,7 @@ if [[ -f "${ZDOTDIR:-$HOME}/.zcalcrc" ]]; then fi # Process command line -while [[ -n $1 && $1 = -(|[#-]*|f|e) ]]; do +while [[ -n $1 && $1 = -(|[#-]*|f|e|r(<->|)) ]]; do optlist=${1[2,-1]} shift [[ $optlist = (|-) ]] && break @@ -158,6 +177,14 @@ while [[ -n $1 && $1 = -(|[#-]*|f|e) ]]; do (e) # Arguments are expressions (( expression_mode = 1 )); ;; + (r) # RPN mode. + (( rpn_mode = 1 )) + ZCALC_ACTIVE=rpn + if [[ $optlist = (#b)(<->)* ]]; then + (( show_stack = ${match[1]} )) + optlist=${optlist[${#match[1]}+1,-2]} + fi + ;; esac done done @@ -281,30 +308,95 @@ while (( expression_mode )) || continue ;; + (\$[[:IDENT:]]##) + # Display only, no calculation + line=${line##\$} + print -r -- ${(P)line} + line= + continue + ;; + (*) - # Latest value is stored as a string, because it might be floating - # point or integer --- we don't know till after the evaluation, and - # arrays always store scalars anyway. - # - # Since it's a string, we'd better make sure we know which - # base it's in, so don't change that until we actually print it. - eval "ans=\$(( $line ))" - # on error $ans is not set; let user re-edit line - [[ -n $ans ]] || continue + line=${${line##[[:blank:]]##}%%[[:blank:]]##} + if (( rpn_mode )); then + matched=1 + case $line in + (=) + if (( ${#stack} < 1 )); then + print -r -- "${line}: not enough values on stack" >&2 + line= + continue + fi + ans=${stack[1]} + ;; + + (+|-|\^|\||\&|\*|\*\*|/) + # Operators with two arguments + if (( ${#stack} < 2 )); then + print -r -- "${line}: not enough values on stack" >&2 + line= + continue + fi + eval "(( ans = \${stack[2]} $line \${stack[1]} ))" + shift 2 stack + ;; + + (ldexp|jn|yn|scalb) + # Functions with two arguments + if (( ${#stack} < 2 )); then + print -r -- "${line}: not enough values on stack" >&2 + line= + continue + fi + eval "(( ans = ${line}(\${stack[2]},\${stack[1]}) ))" + shift 2 stack + ;; + + (${~mathfuncs}) + # Functions with a single argument. + # This is actually a superset, but we should have matched + # any that shouldn't be in it in previous cases. + if (( ${#stack} < 1 )); then + print -r -- "${line}: not enough values on stack" >&2 + line= + continue + fi + eval "(( ans = ${line}(\${stack[1]}) ))" + shift stack + ;; + + (*) + # Treat as expression evaluating to new value to go on stack. + matched=0 + ;; + esac + else + matched=0 + fi + if (( ! matched )); then + # Latest value is stored` as a string, because it might be floating + # point or integer --- we don't know till after the evaluation, and + # arrays always store scalars anyway. + # + # Since it's a string, we'd better make sure we know which + # base it's in, so don't change that until we actually print it. + eval "ans=\$(( $line ))" + # on error $ans is not set; let user re-edit line + [[ -n $ans ]] || continue + fi argv[num++]=$ans psvar[1]=$num + stack=($ans $stack) ;; esac - if [[ -n $base ]]; then - print -- $(( $base $ans )) - elif [[ $ans = *.* ]] || (( outdigits )); then - if [[ -z $forms[outform] ]]; then - print -- $(( $ans )) - else - printf "$forms[outform]\n" $outdigits $ans - fi + if (( show_stack )); then + (( max_stack = (show_stack > ${#stack}) ? ${#stack} : show_stack )) + for (( i = max_stack; i > 0; i-- )); do + printf "%3d: " $i + zcalc_show_value ${stack[i]} + done else - printf "%d\n" $ans + zcalc_show_value $ans fi line= done diff --git a/Functions/Zle/zcalc-auto-insert b/Functions/Zle/zcalc-auto-insert index c9a5c8867..e1affd1c3 100644 --- a/Functions/Zle/zcalc-auto-insert +++ b/Functions/Zle/zcalc-auto-insert @@ -1,6 +1,7 @@ # Bind to a binary operator keystroke for use with zcalc +# Not useful in RPN mode. -if [[ -n $ZCALC_ACTIVE ]]; then +if [[ -n $ZCALC_ACTIVE && $ZCALC_ACTIVE != rpn ]]; then if [[ $CURSOR -eq 0 || $LBUFFER[-1] = "(" ]]; then LBUFFER+=${ZCALC_AUTO_INSERT_PREFIX:-"ans "} fi -- cgit v1.2.3 From 25ae250068134eb87d8be1bd9aeee1590918d120 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 18 Jun 2016 16:20:38 -0700 Subject: unposted: when ksharrays is set, braces are required for all parameter expansions with colon-modifiers --- ChangeLog | 3 +++ Doc/Zsh/options.yo | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index e97c22b84..cc547e5fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * unposted: Functions/Misc/zed: localoptions noksharrays + * unposted: Doc/Zsh/options.yo: when ksharrays is set, braces are + required for all parameter expansions with colon-modifiers + 2016-06-18 Oliver Kiddle * 38713: Completion/Unix/Type/_dates: don't add calendar matches diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 2fce10780..0eaaecae3 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1929,7 +1929,8 @@ Emulate bf(ksh) array handling as closely as possible. If this option is set, array elements are numbered from zero, an array parameter without subscript refers to the first element instead of the whole array, and braces are required to delimit a subscript (`tt(${path[2]})' rather -than just `tt($path[2])'). +than just `tt($path[2])') or to apply modifiers to any parameter +(`tt(${PWD:h})' rather than `tt($PWD:h)'). ) pindex(KSH_AUTOLOAD) pindex(NO_KSH_AUTOLOAD) -- cgit v1.2.3 From 0b8ab3a21a15c12b22f39cd19ce5ef90fdc31ad1 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 19 Jun 2016 19:50:37 -0700 Subject: 38715: add-zle-hook-widget: assorted ksharrays fixes; assign an index to any hook that is added without one, to preserve append ordering --- ChangeLog | 6 ++++ Doc/Zsh/contrib.yo | 30 +++++++++-------- Functions/Zle/add-zle-hook-widget | 69 ++++++++++++++++++++++++++------------- 3 files changed, 69 insertions(+), 36 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index cc547e5fc..52a655069 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-06-19 Barton E. Schaefer + + * 38715: Doc/Zsh/contrib.yo, Functions/Zle/add-zle-hook-widget: + assorted ksharrays fixes; assign an index to any hook that is + added without one, to preserve append ordering + 2016-06-18 Barton E. Schaefer * unposted: Functions/Misc/zed: localoptions noksharrays diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 64d93f9dc..b9c1c0a80 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -345,14 +345,16 @@ tt(zle-isearch-exit), etc. var(widgetname) is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. Note that the hooks are called as widgets, that is, with -`tt(zle )var(widgetname)tt( -Nw)' rather than as a function call. +example(tt(zle )var(widgetname)tt( -Nw "$@")) +rather than as a function call. -The arrays of var(widgetname) are maintained in several tt(zstyle) -contexts, one for each var(hook) context, with a style of `tt(widgets)'. -If the tt(-L) option is given, this set of styles is listed with -`tt(zstyle -L)'. These styles may be updated directly with tt(zstyle) -commands, but the special widgets that refer to the styles are created -only if tt(add-zle-hook-widget) is called to add at least one widget. +In typical usage, var(widgetname) has the form var(index)tt(:)var(name). +In this case var(index) is an integer which determines the order in which +the widget var(name) will be called relative to other widgets in the +array. Widgets having the same var(index) are called in unspecified +order. However, var(widgetname) may omit the index, in which case an +index is computed for it to arrange for it to be called in the order +in which it was added to the array. If the option tt(-d) is given, the var(widgename) is removed from the array of widgets to be executed. @@ -368,12 +370,14 @@ passed as arguments to tt(autoload) as with tt(add-zsh-hook). The widget is also created with `tt(zle -N )var(widgetname)' to cause the corresponding function to be loaded the first time the hook is called. -In addition, var(widgetname) may be of the form var(index)tt(:)var(name). -In this case var(index) is an integer which determines the order in -which the widget var(name) will be called relative to other widgets in -the array. Widgets having the same var(index) are called in unspecified -order, and all widgets declared with an index are called before any -widgets that have no index. + +The arrays of var(widgetname) are currently maintained in tt(zstyle) +contexts, one for each var(hook) context, with a style of `tt(widgets)'. +If the tt(-L) option is given, this set of styles is listed with +`tt(zstyle -L)'. This implementation may change, and the special widgets +that refer to the styles are created only if tt(add-zle-hook-widget) is +called to add at least one widget, so if this function is used for any +hooks, then all hooks should be managed only via this function. ) enditem() diff --git a/Functions/Zle/add-zle-hook-widget b/Functions/Zle/add-zle-hook-widget index eeb0191f0..608a77607 100644 --- a/Functions/Zle/add-zle-hook-widget +++ b/Functions/Zle/add-zle-hook-widget @@ -6,6 +6,7 @@ # # WIDGET may be of the form INDEX:NAME in which case the INDEX determines # the order in which the widget executes relative to other hook widgets. +# Othewise the widget is assigned an index that appends it to the array. # # With -d, remove the widget from the hook instead; delete the hook # variable if it is empty. @@ -17,38 +18,45 @@ # same name is marked for autoload; -U is passed down to autoload if that # is given, as are -z and -k. (This is harmless if the function is # already defined.) The WIDGET is then created with zle -N. +# +# The -L option lists the hooks and their associated widgets. emulate -L zsh -# Setup - create the base functions for hook widgets that call the others - -zmodload zsh/parameter || { - print -u2 "Need parameter module for zle hooks" +# This is probably more safeguarding than necessary +zmodload -e zsh/zle || return 1 +{ zmodload zsh/parameter && zmodload zsh/zleparameter } || { + print -u2 "Need parameter modules for zle hooks" return 1 } -local -a hooktypes=( isearch-exit isearch-update - line-pre-redraw line-init line-finish - history-line-set keymap-select ) +# Setup - create the base functions for hook widgets that call the others + +local -a hooktypes=( zle-isearch-exit zle-isearch-update + zle-line-pre-redraw zle-line-init zle-line-finish + zle-history-line-set zle-keymap-select ) # Stash in zstyle to make it global -zstyle zle-hook types $hooktypes +zstyle zle-hook types ${hooktypes#zle-} for hook in $hooktypes do - function zle-$hook { + function azhw:$hook { local -a hook_widgets local hook # Values of these styles look like number:name # and we run them in number order - # $funcstack is more reliable than $0 - # Also, ksh_arrays is annoying - emulate zsh -c 'zstyle -a $funcstack[2] widgets hook_widgets' - for hook in "${@${(@on)hook_widgets}#*:}" - do - zle "$hook" -Nw || return + zstyle -a $WIDGET widgets hook_widgets + for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do + zle "$hook" -Nw "$@" || return done return 0 } + # Check for an existing widget, add it as the first hook + if [[ ${widgets[$hook]} = user:* ]]; then + zle -A "$hook" "${widgets[$hook]}" + zstyle -- "$hook" widgets 0:"${widgets[$hook]}" + zle -N "$hook" azhw:"$hook" + fi done # Redefine ourself with the setup left out @@ -93,25 +101,27 @@ function add-zle-hook-widget { done shift $(( OPTIND - 1 )) + 1=${1#zle-} # Strip prefix not stored in zle-hook types style + if (( list )); then - zstyle -L "zle-(${1:-${(@j:|:)hooktypes}})" widgets + zstyle -L "zle-(${1:-${(@j:|:)hooktypes[@]}})" widgets return $? - elif (( help || $# != 2 || ${hooktypes[(I)${1#zle-}]} == 0 )); then + elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 )); then print -u$(( 2 - help )) $usage return $(( 1 - help )) fi local -aU extant_hooks - local hook="zle-${1#zle-}" + local hook="zle-$1" local fn="$2" if (( del )); then # delete, if hook is set if zstyle -g extant_hooks "$hook" widgets; then if (( del == 2 )); then - set -A extant_hooks ${extant_hooks:#(<->:|)${~fn}} + set -A extant_hooks ${extant_hooks[@]:#(<->:|)${~fn}} else - set -A extant_hooks ${extant_hooks:#(<->:|)$fn} + set -A extant_hooks ${extant_hooks[@]:#(<->:|)$fn} fi # unset if no remaining entries if (( ${#extant_hooks} )); then @@ -121,15 +131,28 @@ function add-zle-hook-widget { fi fi else + integer i=${#options[ksharrays]}-2 zstyle -g extant_hooks "$hook" widgets - extant_hooks+=("$fn") + if [[ "$fn" != <->:* ]]; then + if [[ -z ${(M)extant_hooks[@]:#(<->:|)$fn} ]]; then + # no index and not already hooked + # assign largest existing index plus 10 + i=${${(On@)${(@M)extant_hooks[@]#<->:}%:}[i]}+10 + else + return 0 + fi + else + i=${${(M)fn#<->:}%:} + fn=${fn#<->:} + fi + extant_hooks+=("${i}:${fn}") zstyle -- "$hook" widgets "${extant_hooks[@]}" if [[ -z "${widgets[$fn]}" ]]; then autoload "${autoopts[@]}" -- "$fn" - zle -N "$fn" + zle -N -- "$fn" fi if [[ -z "${widgets[$hook]}" ]]; then - zle -N "$hook" + zle -N "$hook" azhw:"$hook" fi fi } -- cgit v1.2.3 From d309d9addc114d22175f5feb0ab2e5fdf290dc02 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 21 Jun 2016 12:31:32 +0100 Subject: 38692: IFS can't be changed in restricted mode --- ChangeLog | 5 +++++ Doc/Zsh/restricted.yo | 10 +++++----- Src/params.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 52a655069..a65ba2970 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-06-21 Peter Stephenson + + * 38692: Doc/Zsh/restricted.yo, Src/params.c: IFS can't be + changed in restricted mode. + 2016-06-19 Barton E. Schaefer * 38715: Doc/Zsh/contrib.yo, Functions/Zle/add-zle-hook-widget: diff --git a/Doc/Zsh/restricted.yo b/Doc/Zsh/restricted.yo index b56b50c6f..6cf9b36b5 100644 --- a/Doc/Zsh/restricted.yo +++ b/Doc/Zsh/restricted.yo @@ -10,11 +10,11 @@ restricted mode: startitemize() itemiz(changing directories with the tt(cd) builtin) -itemiz(changing or unsetting the tt(PATH), tt(path), tt(MODULE_PATH), -tt(module_path), tt(SHELL), tt(HISTFILE), tt(HISTSIZE), tt(GID), tt(EGID), -tt(UID), tt(EUID), tt(USERNAME), tt(LD_LIBRARY_PATH), -tt(LD_AOUT_LIBRARY_PATH), tt(LD_PRELOAD) and tt(LD_AOUT_PRELOAD) -parameters) +itemiz(changing or unsetting the tt(EGID), tt(EUID), tt(GID), +tt(HISTFILE), tt(HISTSIZE), tt(IFS), tt(LD_AOUT_LIBRARY_PATH), +tt(LD_AOUT_PRELOAD), tt(LD_LIBRARY_PATH), tt(LD_PRELOAD), +tt(MODULE_PATH), tt(module_path), tt(PATH), tt(path), tt(SHELL), +tt(UID) and tt(USERNAME) parameters) itemiz(specifying command names containing tt(/)) itemiz(specifying command pathnames using tt(hash)) itemiz(redirecting output to files) diff --git a/Src/params.c b/Src/params.c index ae958abc4..e7a73657b 100644 --- a/Src/params.c +++ b/Src/params.c @@ -284,7 +284,7 @@ IPDEF2("HOME", home_gsu, PM_UNSET), IPDEF2("TERM", term_gsu, PM_UNSET), IPDEF2("TERMINFO", terminfo_gsu, PM_UNSET), IPDEF2("WORDCHARS", wordchars_gsu, 0), -IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT), +IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT | PM_RESTRICTED), IPDEF2("_", underscore_gsu, PM_DONTIMPORT), IPDEF2("KEYBOARD_HACK", keyboard_hack_gsu, PM_DONTIMPORT), IPDEF2("0", argzero_gsu, 0), -- cgit v1.2.3 From 5103c85abb239a12a3d29da9b41515cd4af19a9f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 21 Jun 2016 16:34:55 +0100 Subject: 38736: various RPN mode enhancements for zcalc --- ChangeLog | 4 ++ Completion/Zsh/Type/_module_math_func | 2 +- Completion/Zsh/Type/_user_math_func | 2 +- Doc/Zsh/contrib.yo | 23 ++++++++++- Functions/Misc/zcalc | 78 +++++++++++++++++++++++++++++------ 5 files changed, 93 insertions(+), 16 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index fd58e7aa6..4ca92814a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-06-21 Peter Stephenson + * 38736: Completion/Zsh/Type/_module_math_func, + Completion/Zsh/Type/_user_math_func, Doc/Zsh/contrib.yo, + Functions/Misc/zcalc: various RPN mode enhancments for zcalc. + * 38734: Src/loop.c, Test/A01grammar.ztst: fix final case clauses terminating with ;&. diff --git a/Completion/Zsh/Type/_module_math_func b/Completion/Zsh/Type/_module_math_func index 4df8d9714..6be9c006a 100644 --- a/Completion/Zsh/Type/_module_math_func +++ b/Completion/Zsh/Type/_module_math_func @@ -6,4 +6,4 @@ local -a funcs funcs=(${${${(f)"$(zmodload -Fl zsh/mathfunc 2>/dev/null)"}:#^+f:*}##+f:}) _wanted module-math-functions expl 'math function from zsh/mathfunc' \ - compadd -S '(' "$@" -a funcs + compadd -S '(' -q "$@" -a funcs diff --git a/Completion/Zsh/Type/_user_math_func b/Completion/Zsh/Type/_user_math_func index 16774f70b..35a49d50e 100644 --- a/Completion/Zsh/Type/_user_math_func +++ b/Completion/Zsh/Type/_user_math_func @@ -6,4 +6,4 @@ local -a funcs funcs=(${${${(f)"$(functions -M)"}##functions -M }%% *}) _wanted user-math-functions expl 'user math function' \ - compadd -S '(' "$@" -a funcs + compadd -S '(' -q "$@" -a funcs diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index b9c1c0a80..c875c95da 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3806,10 +3806,23 @@ are printed instead of just the most recent result. Hence, for example, tt(zcalc -r4) shows tt($stack[4]) to tt($stack[1]) each time results are printed. ) -item(Duplication)( +item(Duplication: tt(=))( The pseudo-operator tt(=) causes the most recent element of the stack to be duplicated onto the stack. ) +item(tt(pop))( +The pseudo-function tt(pop) causes the most recent element of +the stack to be popped. A `tt(<)' on its own has the same effect. +) +item(tt(<)var(ident))( +The expression tt(<) followed (with no space) by a shell identifier +causes the most recent element of the stack to be popped and +assigned to the identifier. +) +item(Exchange: tt(xy))( +The pseudo-function tt(xy) causes the most recent two elements of +the stack to be exchanged. +) enditem() The prompt is configurable via the parameter tt(ZCALCPROMPT), which @@ -3872,7 +3885,13 @@ Note that tt(zcalc) takes care of all quoting. Hence for example: example(:f cube $1 * $1 * $1) -defines a function to cube the sole argument. +defines a function to cube the sole argument. Functions so defined, or +indeed any functions defined directly or indirectly using tt(functions +-M), are available to execute by typing only the name on the line in RPN +mode; this pops the appropriate number of arguments off the stack +to pass to the function, i.e. 1 in the case of the example tt(cube) +function. If there are optional arguments only the mandatory +arguments are supplied by this means. ) item(tt([#)var(base)tt(]))( This is not a special command, rather part of normal arithmetic diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index eb240b2ec..fa1a8f600 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -100,7 +100,8 @@ zcalc_show_value() { if [[ -n $base ]]; then print -- $(( $base $1 )) elif [[ $1 = *.* ]] || (( outdigits )); then - if [[ -z $forms[outform] ]]; then + # With normal output, ensure trailing "." doesn't get lost. + if [[ -z $forms[outform] || ($outform -eq 1 && $1 = *.) ]]; then print -- $(( $1 )) else printf "$forms[outform]\n" $outdigits $1 @@ -115,10 +116,10 @@ local ZCALC_ACTIVE=1 # TODO: make local variables that shouldn't be visible in expressions # begin with _. -local line ans base defbase forms match mbegin mend psvar optlist opt arg +local line ans base defbase forms match mbegin mend psvar optlist opt arg tmp local compcontext="-zcalc-line-" -integer num outdigits outform=1 expression_mode rpn_mode matched show_stack i -integer max_stack +integer num outdigits outform=1 expression_mode rpn_mode matched show_stack i n +integer max_stack push local -a expressions stack match mbegin mend # We use our own history file with an automatic pop on exit. @@ -131,6 +132,13 @@ if zmodload -i zsh/mathfunc 2>/dev/null; then zmodload -P mathfuncs -FL zsh/mathfunc mathfuncs="("${(j.|.)${mathfuncs##f:}}")" fi +local -A userfuncs +for line in ${(f)"$(functions -M)"}; do + match=(${=line}) + # get minimum number of arguments + userfuncs[${match[3]}]=${match[4]} +done +line= autoload -Uz zmathfuncdef if (( ! ${+ZCALCPROMPT} )); then @@ -298,6 +306,7 @@ while (( expression_mode )) || ((function|:f(unc(tion|)|))[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*))) zmathfuncdef $match[1] $match[3] + userfuncs[$match[1]]=${$(functions -Mm $match[1])[4]} line= continue ;; @@ -318,19 +327,38 @@ while (( expression_mode )) || (*) line=${${line##[[:blank:]]##}%%[[:blank:]]##} - if (( rpn_mode )); then + if [[ rpn_mode -ne 0 && $line != '' ]]; then + push=1 matched=1 case $line in - (=) + (\=|pop|\<[[:IDENT:]]#) if (( ${#stack} < 1 )); then print -r -- "${line}: not enough values on stack" >&2 line= continue fi - ans=${stack[1]} + case $line in + (=) + ans=${stack[1]} + ;; + (pop|\<) + push=0 + shift stack + ;; + (\<[[:IDENT:]]##) + (( ${line##\<} = ${stack[1]} )) + push=0 + shift stack + ;; + (*) + print "BUG in special RPN functions" >&2 + line= + continue + ;; + esac ;; - (+|-|\^|\||\&|\*|\*\*|/) + (+|-|\^|\||\&|\*|/|\*\*|\>\>|\<\&2 @@ -341,15 +369,22 @@ while (( expression_mode )) || shift 2 stack ;; - (ldexp|jn|yn|scalb) + (ldexp|jn|yn|scalb|xy) # Functions with two arguments if (( ${#stack} < 2 )); then print -r -- "${line}: not enough values on stack" >&2 line= continue fi - eval "(( ans = ${line}(\${stack[2]},\${stack[1]}) ))" - shift 2 stack + if [[ $line = xy ]]; then + tmp=${stack[1]} + stack[1]=${stack[2]} + stack[2]=$tmp + push=0 + else + eval "(( ans = ${line}(\${stack[2]},\${stack[1]}) ))" + shift 2 stack + fi ;; (${~mathfuncs}) @@ -365,6 +400,25 @@ while (( expression_mode )) || shift stack ;; + (${(kj.|.)~userfuncs}) + # Get minimum number of arguments to user function + n=${userfuncs[$line]} + if (( ${#stack} < n )); then + print -r -- "${line}: not enough vlaues ($n) on stack" >&2 + line= + continue + fi + line+="(" + # least recent elements on stack are earlier arguments + for (( i = n; i > 0; i-- )); do + line+=${stack[i]} + (( i > 1 )) && line+="," + done + line+=")" + shift $n stack + eval "(( ans = $line ))" + ;; + (*) # Treat as expression evaluating to new value to go on stack. matched=0 @@ -386,7 +440,7 @@ while (( expression_mode )) || fi argv[num++]=$ans psvar[1]=$num - stack=($ans $stack) + (( push )) && stack=($ans $stack) ;; esac if (( show_stack )); then -- cgit v1.2.3 From 26c01f57113cc76e20ec562ffcec60a1ab9f8b1e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 21 Jun 2016 17:26:35 +0100 Subject: 38737: clean up zcalc variables. Undocumented variables now start with "_". --- ChangeLog | 3 + Doc/Zsh/contrib.yo | 17 ++- Functions/Misc/zcalc | 289 ++++++++++++++++++++++++++------------------------- 3 files changed, 163 insertions(+), 146 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 4ca92814a..b95b0fe31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-06-21 Peter Stephenson + * 38737: Functions/Misc/zcalc, Doc/Zsh/contrib.yo: document some + zcalc variable usage and make other variables start with "_". + * 38736: Completion/Zsh/Type/_module_math_func, Completion/Zsh/Type/_user_math_func, Doc/Zsh/contrib.yo, Functions/Misc/zcalc: various RPN mode enhancments for zcalc. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c875c95da..53ae96dad 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3764,8 +3764,14 @@ first few positional parameters. A visual indication of this is given when the calculator starts. The constants tt(PI) (3.14159...) and tt(E) (2.71828...) are provided. -Parameter assignment is possible, but note that all parameters will be put -into the global namespace. +Parameter assignment is possible, but note that all parameters will be +put into the global namespace unless the tt(:local) special command is +used. The function creates local variables whose names start with +tt(_), so users should avoid doing so. The variables tt(ans) (the last +answer) and tt(stack) (the stack in RPN mode) may be referred to +directly; tt(stack) is an array but elements of it are numeric. Various +other special variables are used locally with their standard meaning, +for example tt(compcontext), tt(match), tt(mbegin), tt(mend), tt(psvar). The output base can be initialised by passing the option `tt(-#)var(base)', for example `tt(zcalc -#16)' (the `tt(#)' may have to be quoted, depending @@ -3831,6 +3837,10 @@ stored locally in the first element of the array tt(psvar), which can be referred to in tt(ZCALCPROMPT) as `tt(%1v)'. The default prompt is `tt(%1v> )'. +The variable tt(ZCALC_ACTIVE) is set within the function and can +be tested by nested functions; it has the value tt(rpn) if RPN mode is +active, else 1. + A few special commands are available; these are introduced by a colon. For backward compatibility, the colon may be omitted for certain commands. Completion is available if tt(compinit) has been run. @@ -3870,8 +3880,7 @@ is executed in the context of the function, i.e. with local variables. Space is optional after tt(:!). ) item(tt(:local) var(arg) ...)( -Declare variables local to the function. Note that certain variables -are used by the function for its own purposes. Other variables +Declare variables local to the function. Other variables may be used, too, but they will be taken from or put into the global scope. ) diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index fa1a8f600..86b1e4a5b 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -97,14 +97,14 @@ emulate -L zsh setopt extendedglob zcalc_show_value() { - if [[ -n $base ]]; then - print -- $(( $base $1 )) - elif [[ $1 = *.* ]] || (( outdigits )); then + if [[ -n $_base ]]; then + print -- $(( $_base $1 )) + elif [[ $1 = *.* ]] || (( _outdigits )); then # With normal output, ensure trailing "." doesn't get lost. - if [[ -z $forms[outform] || ($outform -eq 1 && $1 = *.) ]]; then + if [[ -z $_forms[_outform] || ($_outform -eq 1 && $1 = *.) ]]; then print -- $(( $1 )) else - printf "$forms[outform]\n" $outdigits $1 + printf "$_forms[_outform]\n" $_outdigits $1 fi else printf "%d\n" $1 @@ -116,29 +116,31 @@ local ZCALC_ACTIVE=1 # TODO: make local variables that shouldn't be visible in expressions # begin with _. -local line ans base defbase forms match mbegin mend psvar optlist opt arg tmp +local _line ans _base _defbase _forms match mbegin mend +local psvar _optlist _opt _arg _tmp local compcontext="-zcalc-line-" -integer num outdigits outform=1 expression_mode rpn_mode matched show_stack i n -integer max_stack push -local -a expressions stack match mbegin mend +integer _num _outdigits _outform=1 _expression_mode +integer _rpn_mode _matched _show_stack _i _n +integer _max_stack _push +local -a _expressions stack # We use our own history file with an automatic pop on exit. history -ap "${ZDOTDIR:-$HOME}/.zcalc_history" -forms=( '%2$g' '%.*g' '%.*f' '%.*E' '') +_forms=( '%2$g' '%.*g' '%.*f' '%.*E' '') -local mathfuncs +local _mathfuncs if zmodload -i zsh/mathfunc 2>/dev/null; then - zmodload -P mathfuncs -FL zsh/mathfunc - mathfuncs="("${(j.|.)${mathfuncs##f:}}")" + zmodload -P _mathfuncs -FL zsh/mathfunc + _mathfuncs="("${(j.|.)${_mathfuncs##f:}}")" fi -local -A userfuncs -for line in ${(f)"$(functions -M)"}; do - match=(${=line}) +local -A _userfuncs +for _line in ${(f)"$(functions -M)"}; do + match=(${=_line}) # get minimum number of arguments - userfuncs[${match[3]}]=${match[4]} + _userfuncs[${match[3]}]=${match[4]} done -line= +_line= autoload -Uz zmathfuncdef if (( ! ${+ZCALCPROMPT} )); then @@ -155,118 +157,118 @@ fi # Process command line while [[ -n $1 && $1 = -(|[#-]*|f|e|r(<->|)) ]]; do - optlist=${1[2,-1]} + _optlist=${1[2,-1]} shift - [[ $optlist = (|-) ]] && break - while [[ -n $optlist ]]; do - opt=${optlist[1]} - optlist=${optlist[2,-1]} - case $opt in + [[ $_optlist = (|-) ]] && break + while [[ -n $_optlist ]]; do + _opt=${_optlist[1]} + _optlist=${_optlist[2,-1]} + case $_opt in ('#') # Default base - if [[ -n $optlist ]]; then - arg=$optlist - optlist= + if [[ -n $_optlist ]]; then + _arg=$_optlist + _optlist= elif [[ -n $1 ]]; then - arg=$1 + _arg=$1 shift else print -- "-# requires an argument" >&2 return 1 fi - if [[ $arg != (|\#)[[:digit:]]## ]]; then + if [[ $_arg != (|\#)[[:digit:]]## ]]; then print -- "-# requires a decimal number as an argument" >&2 return 1 fi - defbase="[#${arg}]" + _defbase="[#${_arg}]" ;; (f) # Force floating point operation setopt forcefloat ;; (e) # Arguments are expressions - (( expression_mode = 1 )); + (( _expression_mode = 1 )); ;; (r) # RPN mode. - (( rpn_mode = 1 )) + (( _rpn_mode = 1 )) ZCALC_ACTIVE=rpn - if [[ $optlist = (#b)(<->)* ]]; then - (( show_stack = ${match[1]} )) - optlist=${optlist[${#match[1]}+1,-2]} + if [[ $_optlist = (#b)(<->)* ]]; then + (( _show_stack = ${match[1]} )) + _optlist=${_optlist[${#match[1]}+1,-2]} fi ;; esac done done -if (( expression_mode )); then - expressions=("$@") +if (( _expression_mode )); then + _expressions=("$@") argv=() fi -for (( num = 1; num <= $#; num++ )); do +for (( _num = 1; _num <= $#; _num++ )); do # Make sure all arguments have been evaluated. # The `$' before the second argv forces string rather than numeric # substitution. - (( argv[$num] = $argv[$num] )) - print "$num> $argv[$num]" + (( argv[$_num] = $argv[$_num] )) + print "$_num> $argv[$_num]" done -psvar[1]=$num -local prev_line cont_prompt -while (( expression_mode )) || - vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do - if (( expression_mode )); then - (( ${#expressions} )) || break - line=$expressions[1] - shift expressions +psvar[1]=$_num +local _prev_line _cont_prompt +while (( _expression_mode )) || + vared -cehp "${_cont_prompt}${ZCALCPROMPT}" _line; do + if (( _expression_mode )); then + (( ${#_expressions} )) || break + _line=$_expressions[1] + shift _expressions fi - if [[ $line = (|*[^\\])('\\')#'\' ]]; then - prev_line+=$line[1,-2] - cont_prompt="..." - line= + if [[ $_line = (|*[^\\])('\\')#'\' ]]; then + _prev_line+=$_line[1,-2] + _cont_prompt="..." + _line= continue fi - line="$prev_line$line" - prev_line= - cont_prompt= + _line="$_prev_line$_line" + _prev_line= + _cont_prompt= # Test whether there are as many open as close - # parentheses in the line so far. - if [[ ${#line//[^\(]} -gt ${#line//[^\)]} ]]; then - prev_line+=$line - cont_prompt="..." - line= + # parentheses in the _line so far. + if [[ ${#_line//[^\(]} -gt ${#_line//[^\)]} ]]; then + _prev_line+=$_line + _cont_prompt="..." + _line= continue fi - [[ -z $line ]] && break + [[ -z $_line ]] && break # special cases # Set default base if `[#16]' or `[##16]' etc. on its own. # Unset it if `[#]' or `[##]'. - if [[ $line = (#b)[[:blank:]]#('[#'(\#|)((<->|)(|_|_<->))']')[[:blank:]]#(*) ]]; then + if [[ $_line = (#b)[[:blank:]]#('[#'(\#|)((<->|)(|_|_<->))']')[[:blank:]]#(*) ]]; then if [[ -z $match[6] ]]; then if [[ -z $match[3] ]]; then - defbase= + _defbase= else - defbase=$match[1] + _defbase=$match[1] fi - print -s -- $line - print -- $(( ${defbase} ans )) - line= + print -s -- $_line + print -- $(( ${_defbase} ans )) + _line= continue else - base=$match[1] + _base=$match[1] fi else - base=$defbase + _base=$_defbase fi - print -s -- $line + print -s -- $_line - line="${${line##[[:blank:]]#}%%[[:blank:]]#}" - case "$line" in + _line="${${_line##[[:blank:]]#}%%[[:blank:]]#}" + case "$_line" in # Escapes begin with a colon (:(\\|)\!*) # shell escape: handle completion's habit of quoting the ! - eval ${line##:(\\|)\![[:blank:]]#} - line= + eval ${_line##:(\\|)\![[:blank:]]#} + _line= continue ;; @@ -276,83 +278,83 @@ while (( expression_mode )) || ;; ((:|)norm) # restore output format to default - outform=1 + _outform=1 ;; ((:|)sci[[:blank:]]#(#b)(<->)(#B)) - outdigits=$match[1] - outform=2 + _outdigits=$match[1] + _outform=2 ;; ((:|)fix[[:blank:]]#(#b)(<->)(#B)) - outdigits=$match[1] - outform=3 + _outdigits=$match[1] + _outform=3 ;; ((:|)eng[[:blank:]]#(#b)(<->)(#B)) - outdigits=$match[1] - outform=4 + _outdigits=$match[1] + _outform=4 ;; (:raw) - outform=5 + _outform=5 ;; ((:|)local([[:blank:]]##*|)) - eval $line - line= + eval $_line + _line= continue ;; ((function|:f(unc(tion|)|))[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*))) zmathfuncdef $match[1] $match[3] - userfuncs[$match[1]]=${$(functions -Mm $match[1])[4]} - line= + _userfuncs[$match[1]]=${$(functions -Mm $match[1])[4]} + _line= continue ;; (:*) print "Unrecognised escape" - line= + _line= continue ;; (\$[[:IDENT:]]##) # Display only, no calculation - line=${line##\$} - print -r -- ${(P)line} - line= + _line=${_line##\$} + print -r -- ${(P)_line} + _line= continue ;; (*) - line=${${line##[[:blank:]]##}%%[[:blank:]]##} - if [[ rpn_mode -ne 0 && $line != '' ]]; then - push=1 - matched=1 - case $line in + _line=${${_line##[[:blank:]]##}%%[[:blank:]]##} + if [[ _rpn_mode -ne 0 && $_line != '' ]]; then + _push=1 + _matched=1 + case $_line in (\=|pop|\<[[:IDENT:]]#) if (( ${#stack} < 1 )); then - print -r -- "${line}: not enough values on stack" >&2 - line= + print -r -- "${_line}: not enough values on stack" >&2 + _line= continue fi - case $line in + case $_line in (=) ans=${stack[1]} ;; (pop|\<) - push=0 + _push=0 shift stack ;; (\<[[:IDENT:]]##) - (( ${line##\<} = ${stack[1]} )) - push=0 + (( ${_line##\<} = ${stack[1]} )) + _push=0 shift stack ;; (*) print "BUG in special RPN functions" >&2 - line= + _line= continue ;; esac @@ -361,98 +363,101 @@ while (( expression_mode )) || (+|-|\^|\||\&|\*|/|\*\*|\>\>|\<\&2 - line= + print -r -- "${_line}: not enough values on stack" >&2 + _line= continue fi - eval "(( ans = \${stack[2]} $line \${stack[1]} ))" + eval "(( ans = \${stack[2]} $_line \${stack[1]} ))" shift 2 stack ;; (ldexp|jn|yn|scalb|xy) # Functions with two arguments if (( ${#stack} < 2 )); then - print -r -- "${line}: not enough values on stack" >&2 - line= + print -r -- "${_line}: not enough values on stack" >&2 + _line= continue fi - if [[ $line = xy ]]; then - tmp=${stack[1]} + if [[ $_line = xy ]]; then + _tmp=${stack[1]} stack[1]=${stack[2]} - stack[2]=$tmp - push=0 + stack[2]=$_tmp + _push=0 else - eval "(( ans = ${line}(\${stack[2]},\${stack[1]}) ))" + eval "(( ans = ${_line}(\${stack[2]},\${stack[1]}) ))" shift 2 stack fi ;; - (${~mathfuncs}) + (${~_mathfuncs}) # Functions with a single argument. # This is actually a superset, but we should have matched # any that shouldn't be in it in previous cases. if (( ${#stack} < 1 )); then - print -r -- "${line}: not enough values on stack" >&2 - line= + print -r -- "${_line}: not enough values on stack" >&2 + _line= continue fi - eval "(( ans = ${line}(\${stack[1]}) ))" + eval "(( ans = ${_line}(\${stack[1]}) ))" shift stack ;; - (${(kj.|.)~userfuncs}) + (${(kj.|.)~_userfuncs}) # Get minimum number of arguments to user function - n=${userfuncs[$line]} - if (( ${#stack} < n )); then - print -r -- "${line}: not enough vlaues ($n) on stack" >&2 - line= + _n=${_userfuncs[$_line]} + if (( ${#stack} < n_ )); then + print -r -- "${_line}: not enough values ($_n) on stack" >&2 + _line= continue fi - line+="(" + _line+="(" # least recent elements on stack are earlier arguments - for (( i = n; i > 0; i-- )); do - line+=${stack[i]} - (( i > 1 )) && line+="," + for (( _i = _n; _i > 0; _i-- )); do + _line+=${stack[_i]} + (( _i > 1 )) && _line+="," done - line+=")" - shift $n stack - eval "(( ans = $line ))" + _line+=")" + shift $_n stack + eval "(( ans = $_line ))" ;; (*) # Treat as expression evaluating to new value to go on stack. - matched=0 + _matched=0 ;; esac else - matched=0 + _matched=0 fi - if (( ! matched )); then + if (( ! _matched )); then # Latest value is stored` as a string, because it might be floating # point or integer --- we don't know till after the evaluation, and # arrays always store scalars anyway. # # Since it's a string, we'd better make sure we know which # base it's in, so don't change that until we actually print it. - eval "ans=\$(( $line ))" - # on error $ans is not set; let user re-edit line + if ! eval "ans=\$(( $_line ))"; then + _line= + continue + fi + # on error $ans is not set; let user re-edit _line [[ -n $ans ]] || continue fi - argv[num++]=$ans - psvar[1]=$num - (( push )) && stack=($ans $stack) + argv[_num++]=$ans + psvar[1]=$_num + (( _push )) && stack=($ans $stack) ;; esac - if (( show_stack )); then - (( max_stack = (show_stack > ${#stack}) ? ${#stack} : show_stack )) - for (( i = max_stack; i > 0; i-- )); do - printf "%3d: " $i - zcalc_show_value ${stack[i]} + if (( _show_stack )); then + (( _max_stack = (_show_stack > ${#stack}) ? ${#stack} : _show_stack )) + for (( _i = _max_stack; _i > 0; _i-- )); do + printf "%3d: " $_i + zcalc_show_value ${stack[_i]} done else zcalc_show_value $ans fi - line= + _line= done return 0 -- cgit v1.2.3 From e83489fc4ba168abeb5ea7e23e64383fed181ed3 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Wed, 22 Jun 2016 01:37:07 +0200 Subject: 38714: add x: syntax to match specs to make it possible to disable match specs hardcoded in completion functions --- ChangeLog | 4 ++++ Doc/Zsh/compsys.yo | 5 +++-- Doc/Zsh/compwid.yo | 7 +++++++ Src/Zle/complete.c | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 3c722b79d..d352067e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-06-22 Oliver Kiddle + * 38714: Src/Zle/complete.c, Doc/Zsh/compsys.yo, + Doc/Zsh/compwid.yo: add x: syntax to match specs to make it + possible to disable match specs hardcoded in completion functions + * 38735: Completion/Unix/Command/_find, Completion/Zsh/Type/_globquals: support verbose style to allow clearer but less compact descriptions for time specifiers diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index c97f80f27..fb0abcef3 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2023,8 +2023,9 @@ only be performed with the `tt(*)' inserted. kindex(matcher, completion style) item(tt(matcher))( This style is tested separately for each tag valid in the current -context. Its value is tried before any match specifications given by the -tt(matcher-list) style. It should be in the form described in +context. Its value is placed before any match specifications given by the +tt(matcher-list) style so can override them via the use of an tt(x:) +specification. The value should be in the form described in ifzman(the section `Completion Matching Control' in zmanref(zshcompwid))\ ifnzman(noderef(Completion Matching Control))\ . For examples of this, see the description of the tt(tag-order) style. diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo index c01763316..1cc94bf95 100644 --- a/Doc/Zsh/compwid.yo +++ b/Doc/Zsh/compwid.yo @@ -913,6 +913,13 @@ line and trial completion patterns are anchored on the right side. Here an empty var(ranchor) and the tt(e) and tt(E) forms force the match to the end of the command line or trial completion string. ) +item(tt(x:))( +This form is used to mark the end of matching specifications: +subsequent specifications are ignored. In a single standalone list +of specifications this has no use but where matching specifications +are accumulated, such as from nested function calls, it can allow one +function to override another. +) enditem() Each var(lpat), var(tpat) or var(anchor) is either an empty string or diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 30fab541a..0c14d86d5 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -241,6 +241,7 @@ parse_cmatcher(char *name, char *s) case 'E': fl2 = CMF_INTER; case 'R': fl = CMF_RIGHT | CMF_LINE; break; case 'M': fl = CMF_LINE; break; + case 'x': break; default: if (name) zwarnnam(name, "unknown match specification character `%c'", @@ -252,6 +253,15 @@ parse_cmatcher(char *name, char *s) zwarnnam(name, "missing `:'"); return pcm_err; } + if (*s == 'x') { + if (s[2] && !inblank(s[2])) { + if (name) + zwarnnam(name, + "unexpected pattern following x: specification"); + return pcm_err; + } + return ret; + } s += 2; if (!*s) { if (name) -- cgit v1.2.3 From a73ae70e8217d7163aecdbdad4d8af08eced8a55 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Wed, 29 Jun 2016 17:05:06 +0200 Subject: 38770: vi upper/lowercase widgets and shell widget example that reads a vi movement --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 11 +++++++++++ Doc/Zsh/zle.yo | 14 ++++++++++++++ Functions/Zle/vi-pipe | 31 +++++++++++++++++++++++++++++++ Src/Zle/iwidgets.list | 2 ++ Src/Zle/zle_keymap.c | 5 ++++- Src/Zle/zle_vi.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Functions/Zle/vi-pipe (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 4f0a49397..831ea4e69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-06-29 Oliver Kiddle + * 38770: Src/Zle/zle_keymap.c, Src/Zle/zle_vi.c, Doc/Zsh/zle.yo, + Doc/Zsh/contrib.yo, Functions/Zle/vi-pipe: vi upper/lowercase + widgets and shell widget example that reads a vi movement + * 38752: Src/builtin.c: add comments to explain use of stdout instead of stderr for the which builtin diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 53ae96dad..f1208e843 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2968,6 +2968,17 @@ and aliases `tt(globurl)' to `tt(noglob urlglobber)'. This function takes a local URL apart, attempts to pattern-match the local file portion of the URL path, and then puts the results back into URL format again. ) +tindex(vi-pipe) +item(tt(vi-pipe))( +This function reads a movement command from the keyboard and then +prompts for an external command. The part of the buffer covered by +the movement is piped to the external command and then replaced by +the command's output. If the movement command is bound to vi-pipe, +the current line is used. + +The function serves as an example for reading a vi movement command +from within a user-defined widget. +) tindex(which-command) item(tt(which-command))( This function is a drop-in replacement for the builtin widget diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 80d3f39d8..1bae0ccf7 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1781,6 +1781,13 @@ tindex(down-case-word) item(tt(down-case-word) (tt(ESC-L ESC-l)) (unbound) (unbound))( Convert the current word to all lowercase and move past it. ) +tindex(vi-down-case) +item(tt(vi-down-case)) ((unbound) (tt(gu)) (unbound))( +Read a movement command from the keyboard, and convert all characters +from the cursor position to the endpoint of the movement to lowercase. +If the movement command is tt(vi-down-case), swap the case of all +characters on the current line. +) tindex(kill-word) item(tt(kill-word) (tt(ESC-D ESC-d)) (unbound) (unbound))( Kill the current word. @@ -1946,6 +1953,13 @@ tindex(vi-unindent) item(tt(vi-unindent) (unbound) (tt(<)) (unbound))( Unindent a number of lines. ) +tindex(vi-up-case) +item(tt(vi-up-case)) ((unbound) (tt(gU)) (unbound))( +Read a movement command from the keyboard, and convert all characters +from the cursor position to the endpoint of the movement to lowercase. +If the movement command is tt(vi-up-case), swap the case of all +characters on the current line. +) tindex(up-case-word) item(tt(up-case-word) (tt(ESC-U ESC-u)) (unbound) (unbound))( Convert the current word to all caps and move past it. diff --git a/Functions/Zle/vi-pipe b/Functions/Zle/vi-pipe new file mode 100644 index 000000000..2d2e29587 --- /dev/null +++ b/Functions/Zle/vi-pipe @@ -0,0 +1,31 @@ +# Example of a widget that takes a vi motion + +# Filter part of buffer corresponding to a vi motion through an external +# program. + +# To enable with vi compatible bindings use: +# autoload -Uz vi-pipe +# bindkey -a '!' vi-pipe + +autoload -Uz read-from-minibuffer +local _save_cut="$CUTBUFFER" REPLY + +# Use the standard vi-delete to accept a vi motion. +zle .vi-delete || return +read-from-minibuffer "!" +local _save_cur=$CURSOR + +# cut buffer contains the deleted text and can be modified +CUTBUFFER="$(eval $REPLY <<<$CUTBUFFER)" + +# put the modified text back in position. +if [[ CURSOR -eq 0 || $BUFFER[CURSOR] = $'\n' ]]; then + # at the beginning of a line, vi-delete won't have moved the cursor + # back to a previous line + zle .vi-put-before -n 1 +else + zle .vi-put-after -n 1 +fi + +# restore cut buffer and cursor to the start of the range +CUTBUFFER="$_save_cut" CURSOR="$_save_cur" diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index 2b2654c5d..58310cd74 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -143,6 +143,7 @@ "vi-delete", videlete, ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_VIOPER "vi-delete-char", videletechar, ZLE_KEEPSUFFIX "vi-digit-or-beginning-of-line", vidigitorbeginningofline, 0 +"vi-down-case", vidowncase, ZLE_LASTCOL | ZLE_VIOPER "vi-down-line-or-history", vidownlineorhistory, ZLE_LINEMOVE "vi-end-of-line", viendofline, ZLE_LASTCOL "vi-fetch-history", vifetchhistory, ZLE_LINEMOVE @@ -188,6 +189,7 @@ "vi-swap-case", viswapcase, ZLE_LASTCOL "vi-undo-change", viundochange, ZLE_KEEPSUFFIX "vi-unindent", viunindent, ZLE_LASTCOL | ZLE_VIOPER +"vi-up-case", viupcase, ZLE_LASTCOL | ZLE_VIOPER "vi-up-line-or-history", viuplineorhistory, ZLE_LINEMOVE "vi-yank", viyank, ZLE_LASTCOL | ZLE_VIOPER "vi-yank-eol", viyankeol, 0 diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index f547dbf17..3db4207d9 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1374,8 +1374,11 @@ default_bindings(void) bindkey(amap, "ge", refthingy(t_vibackwardwordend), NULL); bindkey(amap, "gE", refthingy(t_vibackwardblankwordend), NULL); bindkey(amap, "gg", refthingy(t_beginningofbufferorhistory), NULL); - bindkey(amap, "g~", refthingy(t_vioperswapcase), NULL); + bindkey(amap, "gu", refthingy(t_vidowncase), NULL); + bindkey(amap, "gU", refthingy(t_viupcase), NULL); bindkey(amap, "g~~", NULL, "g~g~"); + bindkey(amap, "guu", NULL, "gugu"); + bindkey(amap, "gUU", NULL, "gUgU"); /* emacs mode: arrow keys */ add_cursor_key(emap, TCUPCURSOR, t_uplineorhistory, 'A'); diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 953af2401..baa2064e9 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -729,6 +729,52 @@ vioperswapcase(UNUSED(char **args)) return ret; } +/**/ +int +viupcase(UNUSED(char **args)) +{ + int oldcs, c2, ret = 1; + + /* get the range */ + startvichange(1); + if ((c2 = getvirange(0)) != -1) { + oldcs = zlecs; + /* covert the case of all letters within range */ + while (zlecs < c2) { + zleline[zlecs] = ZC_toupper(zleline[zlecs]); + INCCS(); + } + /* go back to the first line of the range */ + zlecs = oldcs; + ret = 0; + } + vichgflag = 0; + return ret; +} + +/**/ +int +vidowncase(UNUSED(char **args)) +{ + int oldcs, c2, ret = 1; + + /* get the range */ + startvichange(1); + if ((c2 = getvirange(0)) != -1) { + oldcs = zlecs; + /* convert the case of all letters within range */ + while (zlecs < c2) { + zleline[zlecs] = ZC_tolower(zleline[zlecs]); + INCCS(); + } + /* go back to the first line of the range */ + zlecs = oldcs; + ret = 0; + } + vichgflag = 0; + return ret; +} + /**/ int virepeatchange(UNUSED(char **args)) -- cgit v1.2.3 From a7d5d239e6ab729515083a88cfaf955e078c1685 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 4 Jul 2016 12:08:14 +0100 Subject: 38783: zcalc tweaks for RPN mode. Make it more straightforward to exchange variables with stack. --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 16 ++++++++++++---- Functions/Misc/zcalc | 26 ++++++++++++++++++-------- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 831ea4e69..952b240c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-07-04 Peter Stephenson + + * 38783: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: tweaks for + variable and stack interation in RPN mode. + 2016-06-29 Oliver Kiddle * 38770: Src/Zle/zle_keymap.c, Src/Zle/zle_vi.c, Doc/Zsh/zle.yo, diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index f1208e843..d4a453849 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3829,16 +3829,24 @@ the stack to be duplicated onto the stack. ) item(tt(pop))( The pseudo-function tt(pop) causes the most recent element of -the stack to be popped. A `tt(<)' on its own has the same effect. +the stack to be popped. A `tt(>)' on its own has the same effect. +) +item(tt(>)var(ident))( +The expression tt(>) followed (with no space) by a shell identifier +causes the most recent element of the stack to be popped and +assigned to the variable with that name. The variable is +local to the tt(zcalc) function. ) item(tt(<)var(ident))( The expression tt(<) followed (with no space) by a shell identifier -causes the most recent element of the stack to be popped and -assigned to the identifier. +causes the value of the variable with that name to be pushed +onto the stack. var(ident) may be an integer, in which +case the previous result with that number (as shown before +the tt(>) in th standard standard tt(zcalc) prompt) is put on the stack. ) item(Exchange: tt(xy))( The pseudo-function tt(xy) causes the most recent two elements of -the stack to be exchanged. +the stack to be exchanged. `tt(<>)' has the same effect. ) enditem() diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 86b1e4a5b..480373345 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -94,7 +94,7 @@ # sequentially just as if read automatically. emulate -L zsh -setopt extendedglob +setopt extendedglob typesetsilent zcalc_show_value() { if [[ -n $_base ]]; then @@ -301,7 +301,7 @@ while (( _expression_mode )) || ;; ((:|)local([[:blank:]]##*|)) - eval $_line + eval ${_line##:} _line= continue ;; @@ -333,7 +333,11 @@ while (( _expression_mode )) || _push=1 _matched=1 case $_line in - (\=|pop|\<[[:IDENT:]]#) + (\<[[:IDENT:]]##) + ans=${(P)${_line##\<}} + ;; + + (\=|pop|\>[[:IDENT:]]#) if (( ${#stack} < 1 )); then print -r -- "${_line}: not enough values on stack" >&2 _line= @@ -343,12 +347,18 @@ while (( _expression_mode )) || (=) ans=${stack[1]} ;; - (pop|\<) + (pop|\>) _push=0 shift stack ;; - (\<[[:IDENT:]]##) - (( ${_line##\<} = ${stack[1]} )) + (\>[[:IDENT:]]##) + if [[ ${_line##\>} = (_*|stack|ans|PI|E) ]]; then + print "${_line##\>}: reserved variable" >&2 + _line= + continue + fi + local ${_line##\>} + (( ${_line##\>} = ${stack[1]} )) _push=0 shift stack ;; @@ -371,14 +381,14 @@ while (( _expression_mode )) || shift 2 stack ;; - (ldexp|jn|yn|scalb|xy) + (ldexp|jn|yn|scalb|xy|\<\>) # Functions with two arguments if (( ${#stack} < 2 )); then print -r -- "${_line}: not enough values on stack" >&2 _line= continue fi - if [[ $_line = xy ]]; then + if [[ $_line = (xy|\<\>) ]]; then _tmp=${stack[1]} stack[1]=${stack[2]} stack[2]=$_tmp -- cgit v1.2.3 From fc286168edac8c0b5fb9e8ec6226d4c77bcde79f Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 8 Jul 2016 22:21:42 +0200 Subject: unposted: fix duplicated words --- ChangeLog | 5 +++++ Doc/Zsh/builtins.yo | 4 ++-- Doc/Zsh/compsys.yo | 2 +- Doc/Zsh/options.yo | 2 +- Doc/Zsh/zle.yo | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 27ce01dd4..e1b5bd524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-07-08 Oliver Kiddle + + * unposted: Doc/Zsh/builtins.yo, Doc/Zsh/compsys.yo, + Doc/Zsh/options.yo, Doc/Zsh/zle.yo: fix duplicated words + 2016-07-08 Peter Stephenson * 38796: Functions/Zle/match-words-by-style: fix subword diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 5c33cd1cf..ac4441c64 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -656,7 +656,7 @@ An EOF condition will also cause the shell to exit, unless the tt(IGNORE_EOF) option is set. See notes at the end of -ifzman(the section JOBS in in zmanref(zshmisc))\ +ifzman(the section JOBS in zmanref(zshmisc))\ ifnzman(noderef(Jobs & Signals)) for some possibly unexpected interactions of the tt(exit) command with jobs. ) @@ -697,7 +697,7 @@ specifies the most recent event beginning with the given string. All substitutions var(old)tt(=)var(new), if any, are then performed on the text of the events. -In addition to the the number range, +In addition to the number range, startsitem() sitem(tt(-I))(restricts to only internal events (not from tt($HISTFILE))) sitem(tt(-L))(restricts to only local events (not from other shells, see diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index fb0abcef3..8792324e5 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3817,7 +3817,7 @@ form below, the var(action) will be executed by calling the tt(_all_labels) function to process all tag labels. No special handling of tags is needed unless a function call introduces a new one. -The functions called to execute var(action)s will be called with the the +The functions called to execute var(action)s will be called with the elements of the array named by the `tt(-O) var(name)' option as arguments. This can be used, for example, to pass the same set of options for the tt(compadd) builtin to all var(action)s. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 0eaaecae3..f68a945ec 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1598,7 +1598,7 @@ skipped. The option is restored after the trap exits. Exiting due to tt(ERR_EXIT) has certain interactions with asynchronous jobs noted in -ifzman(the section JOBS in in zmanref(zshmisc))\ +ifzman(the section JOBS in zmanref(zshmisc))\ ifnzman(noderef(Jobs & Signals)). ) pindex(ERR_RETURN) diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 1bae0ccf7..f51eadac5 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -896,7 +896,7 @@ vindex(MARK) item(tt(MARK) (integer))( Like tt(CURSOR), but for the mark. With vi-mode operators that wait for a movement command to select a region of text, setting tt(MARK) allows -the selection to extend in both directions from the the initial cursor +the selection to extend in both directions from the initial cursor position. ) vindex(NUMERIC) -- cgit v1.2.3 From c32bb6a11c460faeaa9fafdb7b1f9cf3d6d10325 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 17 Jul 2016 12:09:24 +0200 Subject: 38845: reset region_active before entering zle It was done on exit but before zle-line-finish. Also reword documentation on region to better cover vi mode. --- ChangeLog | 6 ++++++ Doc/Zsh/zle.yo | 17 ++++++++--------- Src/Zle/zle_main.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index e89a494c5..be387302c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-07-17 Oliver Kiddle + + * 38845: Src/Zle/zle_main.c, Doc/Zsh/zle.yo: reset region_active + before entering zle - it was on exit but before zle-line-finish + Also reword documentation on region to better cover vi mode + 2016-07-13 Barton E. Schaefer * 38850: Functions/Zle/add-zle-hook-widget: Simplify indexing diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index f51eadac5..1642c5b15 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2571,15 +2571,14 @@ When one of the incremental history search widgets is active, the area of the command line matched by the search string or pattern. ) item(tt(region))( -The region between the cursor (point) and the mark as set with -tt(set-mark-command). The region is only highlighted if it is active, -which is the case if tt(set-mark-command) or tt(exchange-point-and-mark) -has been called and the line has not been subsequently modified. The -region can be deactivated by calling tt(set-mark-command) with a -negative numeric argument, or reactivated by calling -tt(exchange-point-and-mark) with a zero numeric argument. Note -that whether or not the region is active has no effect on its -use within widgets, it simply determines whether it is highlighted. +The currently selected text. In emacs terminology, this is referred to as +the region and is bounded by the cursor (point) and the mark. The region +is only highlighted if it is active, which is the case after the mark +is modified with tt(set-mark-command) or tt(exchange-point-and-mark). +Note that whether or not the region is active has no effect on its +use within emacs style widgets, it simply determines whether it is +highlighted. In vi mode, the region corresponds to selected text in +visual mode. ) cindex(special characters, highlighting) cindex(highlighting, special characters) diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 472e326d1..ac31d4e09 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1159,7 +1159,6 @@ zlecore(void) } - region_active = 0; popheap(); } @@ -1292,6 +1291,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) lastcol = -1; initmodifier(&zmod); prefixflag = 0; + region_active = 0; zrefresh(); -- cgit v1.2.3 From 18d676ff199d7ddc8c9ff3e18a4764ca1a4b25a4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 17 Jul 2016 14:57:28 +0000 Subject: users/21752: Extend zsh/zleparameter's $widgets' parameter's documentation. --- ChangeLog | 3 +++ Doc/Zsh/mod_zleparameter.yo | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index d8441b6b2..f092e815b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-07-17 Daniel Shahaf + * users/21752: Doc/Zsh/mod_zleparameter.yo: Extend + zsh/zleparameter's $widgets' parameter's documentation. + * unposted (cf. users/21737):: Completion/Unix/Command/_git: _git-subtree: Record technical debt in comment. diff --git a/Doc/Zsh/mod_zleparameter.yo b/Doc/Zsh/mod_zleparameter.yo index 03d504724..76d23ba2a 100644 --- a/Doc/Zsh/mod_zleparameter.yo +++ b/Doc/Zsh/mod_zleparameter.yo @@ -15,14 +15,16 @@ This array contains the names of the keymaps currently defined. ) vindex(widgets) item(tt(widgets))( -This associative array contains one entry per widget defined. The name +This associative array contains one entry per widget. The name of the widget is the key and the value gives information about the -widget. It is either the string `tt(builtin)' for builtin widgets, a -string of the form `tt(user:)var(name)' for user-defined widgets, -where var(name) is the name of the shell function implementing the -widget, or it is a string of the form -`tt(completion:)var(type)tt(:)var(name)', for completion widgets. In -the last case var(type) is the name of the builtin widgets the +widget. It is either + the string `tt(builtin)' for builtin widgets, + a string of the form `tt(user:)var(name)' for user-defined widgets, + where var(name) is the name of the shell function implementing the widget, + a string of the form `tt(completion:)var(type)tt(:)var(name)' + for completion widgets, + or a null value if the widget is not yet fully defined. +In the penultimate case, var(type) is the name of the builtin widget the completion widget imitates in its behavior and var(name) is the name of the shell function implementing the completion widget. ) -- cgit v1.2.3 From e3884c60ed1a247af1e1578710629f2ca79630d8 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 17 Jul 2016 12:04:48 -0700 Subject: 38866: update add-zle-hook-widget doc for 38850, bug fixes Edge case handling, wrap in anonymous function for kshautoload management. --- ChangeLog | 8 ++++++ Doc/Zsh/contrib.yo | 18 +++++-------- Functions/Zle/add-zle-hook-widget | 57 ++++++++++++++++++++++++--------------- 3 files changed, 51 insertions(+), 32 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f092e815b..bb33f16b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2016-07-17 Barton E. Schaefer + + * 38866: Doc/Zsh/contrib.yo: update add-zle-hook-widget for 38850. + + * 38866 (+ tweak 38872): Functions/Zle/add-zle-hook-widget: fix + edge case handling, wrap in anonymous function for kshautoload + management. + 2016-07-17 Daniel Shahaf * users/21752: Doc/Zsh/mod_zleparameter.yo: Extend diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index d4a453849..1d2b7ca6e 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -340,23 +340,20 @@ those additional widgets. var(hook) is one of tt(isearch-exit), tt(isearch-update), tt(line-pre-redraw), tt(line-init), tt(line-finish), tt(history-line-set), or tt(keymap-select), corresponding to each of the special widgets -tt(zle-isearch-exit), etc. +tt(zle-isearch-exit), etc. The special widget names are also accepted +as the var(hook) argument. var(widgetname) is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. Note that the hooks are called as widgets, that is, with example(tt(zle )var(widgetname)tt( -Nw "$@")) -rather than as a function call. -In typical usage, var(widgetname) has the form var(index)tt(:)var(name). -In this case var(index) is an integer which determines the order in which -the widget var(name) will be called relative to other widgets in the -array. Widgets having the same var(index) are called in unspecified -order. However, var(widgetname) may omit the index, in which case an -index is computed for it to arrange for it to be called in the order -in which it was added to the array. +vindex(WIDGET, in hooks) +Note that this means that the `tt(WIDGET)' special parameter tracks the +var(widgetname) when the widget function is called, rather than tracking +the name of the corresponding special hook widget. -If the option tt(-d) is given, the var(widgename) is removed from +If the option tt(-d) is given, the var(widgetname) is removed from the array of widgets to be executed. If the option tt(-D) is given, the var(widgetname) is treated as a pattern @@ -370,7 +367,6 @@ passed as arguments to tt(autoload) as with tt(add-zsh-hook). The widget is also created with `tt(zle -N )var(widgetname)' to cause the corresponding function to be loaded the first time the hook is called. - The arrays of var(widgetname) are currently maintained in tt(zstyle) contexts, one for each var(hook) context, with a style of `tt(widgets)'. If the tt(-L) option is given, this set of styles is listed with diff --git a/Functions/Zle/add-zle-hook-widget b/Functions/Zle/add-zle-hook-widget index 760e26d29..04be50478 100644 --- a/Functions/Zle/add-zle-hook-widget +++ b/Functions/Zle/add-zle-hook-widget @@ -18,6 +18,8 @@ # # The -L option lists the hooks and their associated widgets. +() { # Preserve caller global option settings + emulate -L zsh # This is probably more safeguarding than necessary @@ -35,25 +37,23 @@ local -a hooktypes=( zle-isearch-exit zle-isearch-update # Stash in zstyle to make it global zstyle zle-hook types ${hooktypes#zle-} -for hook in $hooktypes -do - function azhw:$hook { - local -a hook_widgets - local hook - # Values of these styles look like number:name - # and we run them in number order - zstyle -a $WIDGET widgets hook_widgets - for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do - if [[ "$hook" = user:* ]]; then - # Preserve $WIDGET within the renamed widget - zle "$hook" -N "$@" - else - zle "$hook" -Nw "$@" - fi || return - done - return 0 - } -done +# Relying on multifuncdef option here +function azhw:${^hooktypes} { + local -a hook_widgets + local hook + # Values of these styles look like number:name + # and we run them in number order + zstyle -a $WIDGET widgets hook_widgets + for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do + if [[ "$hook" = user:* ]]; then + # Preserve $WIDGET within the renamed widget + zle "$hook" -N "$@" + else + zle "$hook" -Nw "$@" + fi || return + done + return 0 +} # Redefine ourself with the setup left out @@ -127,12 +127,25 @@ function add-zle-hook-widget { fi fi else + # Check whether attempting to add a widget named for the hook + if [[ "$fn" = "$hook" ]]; then + if [[ -n "${widgets[$fn]}" ]]; then + print -u2 "Cannot hook $fn to itself" + return 1 + fi + # No point in building the array until another is added + autoload "${autoopts[@]}" -- "$fn" + zle -N "$fn" + return 0 + fi integer i=${#options[ksharrays]}-2 zstyle -g extant_hooks "$hook" widgets # Check for an existing widget, add it as the first hook if [[ ${widgets[$hook]} != "user:azhw:$hook" ]]; then - zle -A "$hook" "${widgets[$hook]}" - extant_hooks=(0:"${widgets[$hook]}" "${extant_hooks[@]}") + if [[ -n ${widgets[$hook]} ]]; then + zle -A "$hook" "${widgets[$hook]}" + extant_hooks=(0:"${widgets[$hook]}" "${extant_hooks[@]}") + fi zle -N "$hook" azhw:"$hook" fi # Add new widget only if not already in the hook list @@ -155,6 +168,8 @@ function add-zle-hook-widget { fi } +} "$@" # Resume caller global options + # Handle zsh autoloading conventions: # - "file" appears last in zsh_eval_context when "source"-ing # - "evalautofunc" appears with kshautoload set or autoload -k -- cgit v1.2.3 From 6e966f691d588932cde025083fa91575f661119a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 17 Jul 2016 12:32:13 +0000 Subject: users/21777: Clarify documentation of the ':A' word modifier. --- ChangeLog | 5 +++++ Doc/Zsh/expn.yo | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 0d7c8328e..bdcfd6f6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-07-20 Daniel Shahaf + + * users/21777: Doc/Zsh/expn.yo: Clarify documentation of the + ':A' word modifier. + 2016-07-19 Jun-ichi Takimoto * 38862: Src/Modules/datetime.c: strptime(3) requires _XOPEN_SOURCE diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index c6e7b6f16..c5f3c00d3 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -224,10 +224,15 @@ Note that the transformation takes place even if the file or any intervening directories do not exist. ) item(tt(A))( -As `tt(a)', but also resolve use of symbolic links where possible. -Note that resolution of `tt(..)' occurs em(before) resolution of symbolic -links. This call is equivalent to tt(a) unless your system has the -tt(realpath) system call (modern systems do). +Turn a file name into an absolute path as the `tt(a)' modifier does, and +em(then) pass the result through the tt(realpath+LPAR()3+RPAR()) library +function to resolve symbolic links. + +Note: on systems that do not have a tt(realpath+LPAR()3+RPAR()) library +function, symbolic links are not resolved, so on those systems `tt(a)' and +`tt(A)' are equivalent. + +Note: tt(foo:A) and tt(realpath+LPAR()foo+RPAR()) are different on some inputs. ) item(tt(c))( Resolve a command name into an absolute path by searching the command -- cgit v1.2.3 From 00f18f29de1b03364eb4eff1f625bc7df936d607 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 Jul 2016 06:25:23 +0000 Subject: users/21779: Clarify documentation of the ':a' word modifier. --- ChangeLog | 3 +++ Doc/Zsh/expn.yo | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f7ca7697c..5446378ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-07-22 Daniel Shahaf + * users/21779: Doc/Zsh/expn.yo: Clarify documentation of the + ':a' word modifier. + * 38890: Completion/Zsh/Function/_add-zle-hook-widget, Completion/Zsh/Function/_add-zsh-hook: _add-zle-hook-widget: New completion. diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index c5f3c00d3..0ed320bb4 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -219,9 +219,12 @@ noted. startitem() item(tt(a))( Turn a file name into an absolute path: prepends the current directory, -if necessary, and resolves any use of `tt(..)' and `tt(.)' in the path. -Note that the transformation takes place even if the file or any -intervening directories do not exist. +if necessary; remove `tt(.)' path segments; and remove `tt(..)' path segments +and the segments that immediately precede them. + +This transformation is agnostic of the filesystem: `tt(/foo/bar/../baz)' shall +always be transformed to `tt(/foo/baz)', regardless of whether `tt(/foo)' +exists or what kind of object (dir, file, symlink, etc.) it is. ) item(tt(A))( Turn a file name into an absolute path as the `tt(a)' modifier does, and -- cgit v1.2.3 From 73ff356d7b4cb49861a420b2465ac731f29f9f1b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 22 Jul 2016 06:30:08 +0000 Subject: 38911: _arguments: Clarify documentation of '-s -w' switch --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 83788121d..1d67af1a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-07-23 Daniel Shahaf + + * 38911: Doc/Zsh/compsys.yo: _arguments: Clarify documentation of + '-s -w' switch + 2016-07-23 Barton E. Schaefer * 38923 (plus expanded comment): Src/jobs.c: zwaitjob() continues diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 8792324e5..a50df999d 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3591,8 +3591,9 @@ even if one or more of the options take arguments. For example, if tt(-x) takes an argument, with no tt(-s), `tt(-xy)' is considered as a single (unhandled) option; with tt(-s), tt(-xy) is an option with the argument `tt(y)'; with both tt(-s) -and tt(-w), tt(-xy) may be the option tt(-x) and the option tt(-y) with -arguments still to come. +and tt(-w), tt(-xy) is the option tt(-x) and the option tt(-y) with +arguments to tt(-x) (and to tt(-y), if it takes arguments) still to come +in subsequent words. ) item(tt(-W))( This option takes tt(-w) a stage further: it is possible to -- cgit v1.2.3 From 932ff2b6f8990b027facc93fb23bc1dc0163707e Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 24 Jul 2016 22:18:34 +0200 Subject: 38929: new vim style text object using match-words-by-style mechanism --- ChangeLog | 3 + Doc/Zsh/contrib.yo | 12 ++-- Functions/Zle/select-word-match | 121 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 Functions/Zle/select-word-match (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 20c401b04..086298775 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-07-24 Oliver Kiddle + * 38929: Doc/Zsh/contrib.yo, Functions/Zle/select-word-match: + new vim style text object using match-words-by-style mechanism + * 38935: Matthew Martin: Completion/Unix/Command/_tcpdump: update for Free and Open BSD diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 1d2b7ca6e..c3dec34cd 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1940,6 +1940,8 @@ tindex(transpose-words-match) tindex(capitalize-word-match) tindex(up-case-word-match) tindex(down-case-word-match) +tindex(delete-whole-word-match) +tindex(select-word-match) tindex(select-word-style) tindex(match-word-context) tindex(match-words-by-style) @@ -1947,12 +1949,14 @@ xitem(tt(forward-word-match), tt(backward-word-match)) xitem(tt(kill-word-match), tt(backward-kill-word-match)) xitem(tt(transpose-words-match), tt(capitalize-word-match)) xitem(tt(up-case-word-match), tt(down-case-word-match)) +xitem(tt(delete-whole-word-match), tt(select-word-match)) item(tt(select-word-style), tt(match-word-context), tt(match-words-by-style))( -The eight `tt(-match)' functions are drop-in replacements for the +The first eight `tt(-match)' functions are drop-in replacements for the builtin widgets without the suffix. By default they behave in a similar way. However, by the use of styles and the function tt(select-word-style), -the way words are matched can be altered. For comparison, the widgets -described in ifzman(zmanref(zshzle) under Text Objects)\ +the way words are matched can be altered. tt(select-word-match) is intended +to be used as a text object in vi mode but with custom word styles. For +comparison, the widgets described in ifzman(zmanref(zshzle) under Text Objects)\ ifnzman(noderef(Text Objects)) use fixed definitions of words, compatible with the tt(vim) editor. @@ -1960,7 +1964,7 @@ The simplest way of configuring the functions is to use tt(select-word-style), which can either be called as a normal function with the appropriate argument, or invoked as a user-defined widget that will prompt for the first character of the word style to be used. The first -time it is invoked, the eight tt(-match) functions will automatically +time it is invoked, the first eight tt(-match) functions will automatically replace the builtin versions, so they do not need to be loaded explicitly. The word styles available are as follows. Only the first character diff --git a/Functions/Zle/select-word-match b/Functions/Zle/select-word-match new file mode 100644 index 000000000..24620c995 --- /dev/null +++ b/Functions/Zle/select-word-match @@ -0,0 +1,121 @@ +# Select the entire word around the cursor. Intended for use as +# a vim-style text object in vi mode but with customisable +# word boundaries. +# +# For example: +# autoload -U select-word-match +# zle -N select-in-camel select-word-match +# bindkey -M viopp ic select-in-camel +# zstyle ':zle:*-camel' word-style normal-subword + +emulate -L zsh +setopt extendedglob + +local curcontext=:zle:$WIDGET +local -a matched_words +# Start and end of range of characters +integer pos1 pos2 num=${NUMERIC:-1} +local style word + +# choose between inner word or a word style of widget +for style in $1 ${${WIDGET#*-}[1]} $KEYS[1] "i"; do + [[ $style = [ai] ]] && break +done + +autoload -Uz match-words-by-style + +while (( num-- )); do + if (( MARK > CURSOR )); then + # if cursor is at the start of the selection, just move back a word + match-words-by-style + if [[ $style = i && -n $matched_words[3] ]]; then + word=$matched_words[3] + else + word=$matched_words[2]$matched_words[3] + fi + if [[ -n $word ]]; then + (( CURSOR -= ${#word} )) + else + return 1 + fi + elif (( MARK >= 0 && MARK < CURSOR )); then + # cursor at the end, move forward a word + (( CURSOR+1 == $#BUFFER )) && return 1 + (( CURSOR++ )) + match-words-by-style + if [[ -n $matched_words[4] ]]; then + if [[ $style = i ]]; then + # just skip the whitespace + word=$matched_words[4] + else + # skip the whitespace plus word + word=$matched_words[4]$matched_words[5] + fi + else + if [[ $style = i ]]; then + # skip the word + word=$matched_words[5] + else + # skip word and following whitespace + word=$matched_words[5]$matched_words[6] + fi + fi + (( CURSOR += ${#word} - 1 )) + else + match-words-by-style + + if [[ -n "${matched_words[3]}" ]]; then + # There's whitespace before the cursor, so the word we are selecting + # starts at the cursor position. + pos1=$CURSOR + else + # No whitespace before us, so select any wordcharacters there. + pos1="${#matched_words[1]}" + fi + + if [[ -n "${matched_words[4]}" ]]; then + if [[ -n "${matched_words[3]}" ]] || (( CURSOR == 0 )); then + # whitespace either side, select it + (( pos1 = CURSOR - ${#matched_words[3]} )) + (( pos2 = CURSOR + ${#matched_words[4]} )) + else + # There's whitespace at the cursor position, so only select + # up to the cursor position. + (( pos2 = CURSOR + 1 )) + fi + else + # No whitespace at the cursor position, so select the + # current character and any following wordcharacters. + (( pos2 = CURSOR + ${#matched_words[5]} )) + fi + + if [[ $style = a ]]; then + if [[ -n "${matched_words[4]}" && ( -n "${matched_words[3]}" || CURSOR -eq 0 ) ]]; then + # in the middle of whitespace so grab a word + if [[ -n "${matched_words[5]}" ]]; then + (( pos2 += ${#matched_words[5]} )) # preferably the one after + else + (( pos1 -= ${#matched_words[2]} )) # otherwise the one before + fi + elif [[ -n "${matched_words[6]}" ]]; then + (( pos2 += ${#matched_words[6]} )) + elif [[ -n "${matched_words[3]}" ]]; then + # couldn't grab whitespace forwards so try backwards + (( pos1 -= ${#matched_words[3]} )) + elif (( pos1 > 0 )); then + # There might have been whitespace before the word + (( CURSOR = pos1 )) + match-words-by-style + if [[ -n "${matched_words[3]}" ]]; then + (( pos1 -= ${#matched_words[3]} )) + fi + fi + fi + + (( MARK = pos1, CURSOR = pos2-1 )) + fi +done + +if [[ $KEYMAP == vicmd ]] && (( !REGION_ACTIVE )); then + (( CURSOR++ )) # Need to include cursor position for operators +fi -- cgit v1.2.3 From bdf0a3df38ccb86850527e381926d074a886d275 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 26 Jul 2016 09:35:14 +0100 Subject: 38945: Additional notes on :a behaviour --- ChangeLog | 4 ++++ Doc/Zsh/expn.yo | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f9dc8594a..61886b2b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-07-26 Peter Stephenson + + * 38945: Doc/Zsh/expn.yo: additional notes on :a behaviour. + 2016-07-24 Oliver Kiddle * 38943: Completion/Unix/Command/_texinfo: update options diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 0ed320bb4..ca4b94f5e 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -222,9 +222,13 @@ Turn a file name into an absolute path: prepends the current directory, if necessary; remove `tt(.)' path segments; and remove `tt(..)' path segments and the segments that immediately precede them. -This transformation is agnostic of the filesystem: `tt(/foo/bar/../baz)' shall -always be transformed to `tt(/foo/baz)', regardless of whether `tt(/foo)' -exists or what kind of object (dir, file, symlink, etc.) it is. +This transformation is agnostic about what is in the filesystem, i.e. is +on the logical, not the physical directory. It takes place in the same +manner as when changing directories when neither of the options +tt(CHASE_DOTS) or tt(CHASE_LINKS) is set. For example, +`tt(/before/here/../after)' is always transformed to +`tt(/before/after)', regardless of whether `tt(/before/here)' exists or what +kind of object (dir, file, symlink, etc.) it is. ) item(tt(A))( Turn a file name into an absolute path as the `tt(a)' modifier does, and -- cgit v1.2.3 From 26361e438b41862f5495ae263bc004cfffbd6b44 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 28 Jul 2016 09:50:03 +0100 Subject: 38953: Fix some issues with match-words-by-style. Add keyword retrieval of words. Improve test for start of word in subwords for use in delete-whole-word. If line after cursor is empty, white space is treated as ws-after-cursor. --- ChangeLog | 5 ++++ Doc/Zsh/contrib.yo | 11 +++++++++ Functions/Zle/delete-whole-word-match | 15 ++++++------ Functions/Zle/match-words-by-style | 45 +++++++++++++++++++++++++++++------ 4 files changed, 61 insertions(+), 15 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 88cf4cd19..03a2e29fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2016-07-28 Peter Stephenson + * 38953: Doc/Zsh/contrib.yo, + Functions/Zle/delete-whole-word-match, + Functions/Zle/match-words-by-style: Fix some problems with + match-words-by-style and add keyword retrieval of matched data. + * users/21793: README, Src/glob.c: remove ancient undocumented pre-"f" glob qualifer feature that unqualified integers were treated as octal file mode. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c3dec34cd..8db7395d0 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2132,6 +2132,17 @@ non-word characters following that word (7) the remainder of the line. Any of the elements may be an empty string; the calling function should test for this to decide whether it can perform its function. +If the variable tt(matched_words) is defined by the caller to +tt(match-words-by-style) as an associative array (tt(local -A +matched_words)), then the seven values given above should be retrieved +from it as elements named tt(start), tt(word-before-cursor), +tt(ws-before-cursor), tt(ws-after-cursor), tt(word-after-cursor), +tt(ws-after-word), and tt(end). In addition the element +tt(is-word-start) is 1 if the cursor is on the start of a word or +subword, or on white space before it (the cases can be distinguished by +testing the tt(ws-after-cursor) element) and 0 otherwise. This form is +recommended for future compatibility. + It is possible to pass options with arguments to tt(match-words-by-style) to override the use of styles. The options are: startsitem() diff --git a/Functions/Zle/delete-whole-word-match b/Functions/Zle/delete-whole-word-match index aece86065..3d52dd3d7 100644 --- a/Functions/Zle/delete-whole-word-match +++ b/Functions/Zle/delete-whole-word-match @@ -12,30 +12,29 @@ emulate -L zsh setopt extendedglob local curcontext=:zle:$WIDGET -local -a matched_words +local -A matched_words # Start and end of range of characters to remove. integer pos1 pos2 autoload -Uz match-words-by-style match-words-by-style -if [[ -n "${matched_words[3]}" ]]; then - # There's whitespace before the cursor, so the word we are deleting - # starts at the cursor position. +if (( ${matched_words[is-word-start]} )); then + # The word we are deleting starts at the cursor position. pos1=$CURSOR else - # No whitespace before us, so delete any wordcharacters there. - pos1="${#matched_words[1]}" + # Not, so delete any wordcharacters before, too + pos1="${#matched_words[start]}" fi -if [[ -n "${matched_words[4]}" ]]; then +if [[ -n "${matched_words[ws-after-cursor]}" ]]; then # There's whitespace at the cursor position, so only delete # up to the cursor position. (( pos2 = CURSOR + 1 )) else # No whitespace at the cursor position, so delete the # current character and any following wordcharacters. - (( pos2 = CURSOR + ${#matched_words[5]} + 1 )) + (( pos2 = CURSOR + ${#matched_words[word-after-cursor]} + 1 )) fi # Move the cursor then delete the block in one go for the diff --git a/Functions/Zle/match-words-by-style b/Functions/Zle/match-words-by-style index 6cdec7551..fc59c2764 100644 --- a/Functions/Zle/match-words-by-style +++ b/Functions/Zle/match-words-by-style @@ -5,8 +5,16 @@ # # # where the cursor position is always after the third item and `after' -# is to be interpreted as `after or on'. Some -# of the array elements will be empty; this depends on the style. +# is to be interpreted as `after or on'. +# +# matched_words may be an associative array, in which case the +# values above are now given by the elements named start, word-before-cursor, +# ws-before-cursor, ws-after-cursor, word-after-cursor, ws-after-word, +# end. In addition, the element is-word-start is 1 if the cursor +# is on the start of a word; this is non-trivial in the case of subword +# (camel case) matching as there may be no white space to test. +# +# Some of the array elements will be empty; this depends on the style. # For example # foo bar rod stick # ^ @@ -224,11 +232,18 @@ charskip=${(l:skip::?:)} eval pat2='${RBUFFER##(#b)('${charskip}${spacepat}')('\ ${wordpat2}')('${spacepat}')}' +if [[ -n $match[2] ]]; then + ws2=$match[1] + word2=$match[2] + ws3=$match[3] +else + # No more words, so anything left is white space after cursor. + ws2=$RBUFFER + pat2= +fi -ws2=$match[1] -word2=$match[2] -ws3=$match[3] - +integer wordstart +[[ ( -n $ws1 || -n $ws2 ) && -n $word2 ]] && wordstart=1 if [[ $wordstyle = *subword* ]]; then # Do we have a group of upper case characters at the start # of word2 (that don't form the entire word)? @@ -249,6 +264,7 @@ if [[ $wordstyle = *subword* ]]; then # if it wants. elif [[ $word2 = (#b)(?[^${~subwordrange}]##)[${~subwordrange}]* ]]; then (( epos = ${#match[1]} )) + (( wordstart = 1 )) else (( epos = 0 )) fi @@ -262,4 +278,19 @@ if [[ $wordstyle = *subword* ]]; then fi fi -matched_words=("$pat1" "$word1" "$ws1" "$ws2" "$word2" "$ws3" "$pat2") +# matched_words should be local to caller. +# Just fix type here. +if [[ ${(t)matched_words} = *association* ]]; then + matched_words=( + start "$pat1" + word-before-cursor "$word1" + ws-before-cursor "$ws1" + ws-after-cursor "$ws2" + word-after-cursor "$word2" + ws-after-word "$ws3" + end "$pat2" + is-word-start $wordstart + ) +else + matched_words=("$pat1" "$word1" "$ws1" "$ws2" "$word2" "$ws3" "$pat2") +fi -- cgit v1.2.3 From b816bb42cfc4d0fa05abb63ebf4098af05a3d593 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 28 Jul 2016 16:16:25 +0200 Subject: 38957: make use of updates to match-words-by-style and better support completion of word-style styles for zstyle --- ChangeLog | 5 ++++ Completion/Zsh/Command/_zstyle | 7 ++++-- Doc/Zsh/contrib.yo | 2 +- Functions/Zle/select-word-match | 55 ++++++++++++++++++++--------------------- 4 files changed, 38 insertions(+), 31 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 6a5b0e5c4..1d68cf75d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2016-07-28 Oliver Kiddle + * 38957: Functions/Zle/select-word-match, + Completion/Zsh/Command/_zstyle, Doc/Zsh/contrib.yo: + make use of updates to match-words-by-style and better support + completion of word-style styles for zstyle + * 38956: Completion/Zsh/Command/_bindkey, Completion/Zsh/Command/_vared, Completion/Zsh/Command/_zle, Completion/Zsh/Function/_add-zle-hook-widget, diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 9a6d61891..20ff47f87 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -173,6 +173,7 @@ styles=( url-seps e: whence e: word-chars e: + word-class e: word-style e:word-style word-context e: @@ -241,11 +242,13 @@ while (( $#state )); do case "$state[1]" in (contexts) if [[ ! -prefix :*: ]]; then - _wanted contexts expl context compadd -P : -qS : completion vcs_info zftp + _wanted contexts expl context compadd -P : -qS : chpwd completion vcs_info zftp zle elif compset -P :completion:; then contexts=( functions _completers cmdorcont argument tag ) elif compset -P :vcs_info:; then contexts=( vcs-string user-context repo-root-name ) + elif compset -P :zle:; then + _wanted widgets expl widget _widgets -qS : fi if (( $#contexts )); then for ostate in $contexts; do @@ -521,7 +524,7 @@ while (( $#state )); do ;; (word-style) - _wanted word-styles expl 'word style' compadd normal shell space + _wanted word-styles expl 'word style' compadd {normal,specified,unspecified,shell,whitespace}-subword ;; (vcs-string) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8db7395d0..00ed08029 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2105,7 +2105,7 @@ Here are some examples of use of the tt(word-context) style to extend the context. example(zstyle ':zle:*' word-context \ - "*/*" file "[[:space:]]" whitespace + "*/*" filename "[[:space:]]" whitespace zstyle ':zle:transpose-words:whitespace' word-style shell zstyle ':zle:transpose-words:filename' word-style normal zstyle ':zle:transpose-words:filename' word-chars '') diff --git a/Functions/Zle/select-word-match b/Functions/Zle/select-word-match index 24620c995..8440852ab 100644 --- a/Functions/Zle/select-word-match +++ b/Functions/Zle/select-word-match @@ -12,7 +12,7 @@ emulate -L zsh setopt extendedglob local curcontext=:zle:$WIDGET -local -a matched_words +local -A matched_words # Start and end of range of characters integer pos1 pos2 num=${NUMERIC:-1} local style word @@ -28,10 +28,10 @@ while (( num-- )); do if (( MARK > CURSOR )); then # if cursor is at the start of the selection, just move back a word match-words-by-style - if [[ $style = i && -n $matched_words[3] ]]; then - word=$matched_words[3] + if [[ $style = i && -n $matched_words[ws-before-cursor] ]]; then + word=$matched_words[ws-before-cursor] else - word=$matched_words[2]$matched_words[3] + word=$matched_words[word-before-cursor]$matched_words[ws-before-cursor] fi if [[ -n $word ]]; then (( CURSOR -= ${#word} )) @@ -43,41 +43,40 @@ while (( num-- )); do (( CURSOR+1 == $#BUFFER )) && return 1 (( CURSOR++ )) match-words-by-style - if [[ -n $matched_words[4] ]]; then + if [[ -n $matched_words[ws-after-cursor] ]]; then if [[ $style = i ]]; then # just skip the whitespace - word=$matched_words[4] + word=$matched_words[ws-after-cursor] else # skip the whitespace plus word - word=$matched_words[4]$matched_words[5] + word=$matched_words[ws-after-cursor]$matched_words[word-after-cursor] fi else if [[ $style = i ]]; then # skip the word - word=$matched_words[5] + word=$matched_words[word-after-cursor] else # skip word and following whitespace - word=$matched_words[5]$matched_words[6] + word=$matched_words[word-after-cursor]$matched_words[ws-after-word] fi fi (( CURSOR += ${#word} - 1 )) else match-words-by-style - if [[ -n "${matched_words[3]}" ]]; then - # There's whitespace before the cursor, so the word we are selecting - # starts at the cursor position. + if (( ${matched_words[is-word-start]} )); then + # The word we are selecting starts at the cursor position. pos1=$CURSOR else # No whitespace before us, so select any wordcharacters there. - pos1="${#matched_words[1]}" + pos1="${#matched_words[start]}" fi - if [[ -n "${matched_words[4]}" ]]; then - if [[ -n "${matched_words[3]}" ]] || (( CURSOR == 0 )); then + if [[ -n "${matched_words[ws-after-cursor]}" ]]; then + if [[ -n "${matched_words[ws-before-cursor]}" ]] || (( CURSOR == 0 )); then # whitespace either side, select it - (( pos1 = CURSOR - ${#matched_words[3]} )) - (( pos2 = CURSOR + ${#matched_words[4]} )) + (( pos1 = CURSOR - ${#matched_words[ws-before-cursor]} )) + (( pos2 = CURSOR + ${#matched_words[ws-after-cursor]} )) else # There's whitespace at the cursor position, so only select # up to the cursor position. @@ -86,28 +85,28 @@ while (( num-- )); do else # No whitespace at the cursor position, so select the # current character and any following wordcharacters. - (( pos2 = CURSOR + ${#matched_words[5]} )) + (( pos2 = CURSOR + ${#matched_words[word-after-cursor]} )) fi if [[ $style = a ]]; then - if [[ -n "${matched_words[4]}" && ( -n "${matched_words[3]}" || CURSOR -eq 0 ) ]]; then + if [[ -n "${matched_words[ws-after-cursor]}" && ( -n "${matched_words[ws-before-cursor]}" || CURSOR -eq 0 ) ]]; then # in the middle of whitespace so grab a word - if [[ -n "${matched_words[5]}" ]]; then - (( pos2 += ${#matched_words[5]} )) # preferably the one after + if [[ -n "${matched_words[word-after-cursor]}" ]]; then + (( pos2 += ${#matched_words[word-after-cursor]} )) # preferably the one after else - (( pos1 -= ${#matched_words[2]} )) # otherwise the one before + (( pos1 -= ${#matched_words[word-before-cursor]} )) # otherwise the one before fi - elif [[ -n "${matched_words[6]}" ]]; then - (( pos2 += ${#matched_words[6]} )) - elif [[ -n "${matched_words[3]}" ]]; then + elif [[ -n "${matched_words[ws-after-word]}" ]]; then + (( pos2 += ${#matched_words[ws-after-word]} )) + elif [[ -n "${matched_words[ws-before-cursor]}" ]]; then # couldn't grab whitespace forwards so try backwards - (( pos1 -= ${#matched_words[3]} )) + (( pos1 -= ${#matched_words[ws-before-cursor]} )) elif (( pos1 > 0 )); then # There might have been whitespace before the word (( CURSOR = pos1 )) match-words-by-style - if [[ -n "${matched_words[3]}" ]]; then - (( pos1 -= ${#matched_words[3]} )) + if [[ -n "${matched_words[ws-before-cursor]}" ]]; then + (( pos1 -= ${#matched_words[ws-before-cursor]} )) fi fi fi -- cgit v1.2.3 From 8d71a610af2a054e555cb2b97666e18f1964fdd6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 28 Jul 2016 05:25:31 +0000 Subject: 38959: Document 38956 (_widgets). --- ChangeLog | 4 ++++ Doc/Zsh/compsys.yo | 10 ++++++++++ 2 files changed, 14 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index ed7de5c4f..970d3e423 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-07-31 Daniel Shahaf + + * 38959: Doc/Zsh/compsys.yo: Document 38956 (_widgets). + 2016-07-29 Daniel Shahaf * unposted: Completion/Unix/Command/_subversion: _svnadmin: diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index a50df999d..41864f813 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -5046,6 +5046,16 @@ Like tt(_tags) this function supports the tt(-C) option to give a different name for the argument context field. The tt(-x) option has the same meaning as for tt(_description). ) +findex(_widgets) +item(tt(_widgets) [ tt(-g) var(pattern) ])( +This function completes names of zle widgets (see +ifzman(the section `Widgets' in zmanref(zshzle))\ +ifnzman(noderef(Zle Widgets))\ +). The var(pattern), if present, is matched against values of the tt($widgets) +special parameter, documented in +ifzman(the section `The zsh/zleparameter Module' in zmanref(zshmodules))\ +ifnzman(noderef(The zsh/zleparameter Module)). +) enditem() texinode(Completion Directories)()(Completion Functions)(Completion System) -- cgit v1.2.3 From 7f052ed3e44176240d53a379674cf22fcb38807a Mon Sep 17 00:00:00 2001 From: Jun-ichi Takimoto Date: Thu, 4 Aug 2016 19:32:34 +0900 Subject: unposted: fix format in zle.yo --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index ae8d0ca39..3a1fee1fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-08-04 Jun-ichi Takimoto + + * unposted: Doc/Zsh/zle.yo: fix format + 2016-08-03 Oliver Kiddle * 38989: Completion/BSD/Command/_freebsd-update, diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 1642c5b15..eaca1b3b1 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1782,7 +1782,7 @@ item(tt(down-case-word) (tt(ESC-L ESC-l)) (unbound) (unbound))( Convert the current word to all lowercase and move past it. ) tindex(vi-down-case) -item(tt(vi-down-case)) ((unbound) (tt(gu)) (unbound))( +item(tt(vi-down-case) (unbound) (tt(gu)) (unbound))( Read a movement command from the keyboard, and convert all characters from the cursor position to the endpoint of the movement to lowercase. If the movement command is tt(vi-down-case), swap the case of all @@ -1954,7 +1954,7 @@ item(tt(vi-unindent) (unbound) (tt(<)) (unbound))( Unindent a number of lines. ) tindex(vi-up-case) -item(tt(vi-up-case)) ((unbound) (tt(gU)) (unbound))( +item(tt(vi-up-case) (unbound) (tt(gU)) (unbound))( Read a movement command from the keyboard, and convert all characters from the cursor position to the endpoint of the movement to lowercase. If the movement command is tt(vi-up-case), swap the case of all -- cgit v1.2.3 From bedb61fd999b87948d30987302362b3c07302132 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 12 Aug 2016 12:54:34 +0100 Subject: 39029: document transpose-words change --- ChangeLog | 2 ++ Doc/Zsh/zle.yo | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2628a4861..4a7449ca4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2016-08-12 Peter Stephenson + * 39029: Doc/Zsh/zle.yo: document previous change. + * Han Pingtian: 38983: Src/Zle/zle_word.c: make transpose-words handle numeric arguments sensibly. diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index eaca1b3b1..fad5e15fa 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1948,6 +1948,12 @@ to the left. tindex(transpose-words) item(tt(transpose-words) (tt(ESC-T ESC-t)) (unbound) (unbound))( Exchange the current word with the one before it. + +With a positive numeric argument em(N), the word before the cursor is +transposed with the following em(N) words. + +With a negative numeric argument em(-N), the word after the cursor +is transposed with the preceding em(N) words. ) tindex(vi-unindent) item(tt(vi-unindent) (unbound) (tt(<)) (unbound))( -- cgit v1.2.3 From 062aeca2d29318d19524ab54c10502af6a98b2ad Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 15 Aug 2016 12:06:24 +0100 Subject: 39039: fix documentation of transpose-words --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 8612c1c18..fbf93064a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-08-15 Peter Stephenson + + * 39039: Doc/Zsh/zle.yo: fix documentation for transpose-words. + 2016-08-13 Oliver Kiddle * 39036: Completion/Unix/Command/_git: update up to git 2.9.2 diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index fad5e15fa..0102cb0e6 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1949,11 +1949,14 @@ tindex(transpose-words) item(tt(transpose-words) (tt(ESC-T ESC-t)) (unbound) (unbound))( Exchange the current word with the one before it. -With a positive numeric argument em(N), the word before the cursor is -transposed with the following em(N) words. - -With a negative numeric argument em(-N), the word after the cursor -is transposed with the preceding em(N) words. +With a positive numeric argument em(N), the word around the cursor, or +following it if the cursor is between words, is transposed with the +preceding em(N) words. The cursor is put at the end of the resulting +group of words. + +With a negative numeric argument em(-N), the effect is the same as using +a positive argument em(N) except that the original cursor position is +retained, regardless of how the words are rearranged. ) tindex(vi-unindent) item(tt(vi-unindent) (unbound) (tt(<)) (unbound))( -- cgit v1.2.3 From 0aa6bfd831706bc01a95af97963b702f4e6ff66c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 16 Aug 2016 22:48:41 +0000 Subject: 39044 (in part, see thread): Document _canonical_paths in the manual, too. This mostly copy-pastes the source code comments and adds markup, however, the positional arguments are now annotated optional, and a ')' was added. --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 15 +++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index fbf93064a..e899bdaaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-08-18 Daniel Shahaf + + * 39044 (in part, see thread): Doc/Zsh/compsys.yo: Document + _canonical_paths in the manual, too. + 2016-08-15 Peter Stephenson * 39039: Doc/Zsh/zle.yo: fix documentation for transpose-words. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 41864f813..8c7ef0f5a 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2978,6 +2978,21 @@ widgets to find out if the command line hasn't changed since the last time completion was tried. Only then are the tt(_ignored), tt(_correct) and tt(_approximate) completers called. ) +findex(_canonical_paths) +item(tt(_canonical_paths) [ tt(-A) var(var) ] [ tt(-N) ] [ tt(-MJV12nfX) ] var(tag) var(descr) [ var(paths) ... ])( +This completion function completes all paths given to it, and also tries to +offer completions which point to the same file as one of the paths given +(relative path when an absolute path is given, and vice versa; when tt(..)'s +are present in the word to be completed; and some paths got from symlinks). + +tt(-A), if specified, takes the paths from the array variable specified. Paths can +also be specified on the command line as shown above. tt(-N), if specified, +prevents canonicalizing the paths given before using them for completion, in +case they are already so. The options tt(-M), tt(-J), tt(-V), tt(-1), tt(-2), +tt(-n), tt(-F), tt(-X) are passed to tt(compadd). + +See tt(_description) for a description of var(tag) and var(descr). +) findex(_complete) item(tt(_complete))( This completer generates all possible completions in a context-sensitive -- cgit v1.2.3 From 7154052ebe3d810390164a05c39ff83f98a1d858 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 30 Jul 2016 16:16:22 +0000 Subject: 39046 + 39061: New :P history modifier. --- ChangeLog | 10 ++++++++++ Completion/Base/Completer/_external_pwds | 2 +- Completion/Zsh/Type/_history_modifiers | 5 +++-- Doc/Zsh/contrib.yo | 2 +- Doc/Zsh/expn.yo | 9 +++++++++ Functions/MIME/zsh-mime-handler | 2 +- Functions/VCS_Info/VCS_INFO_quilt | 2 +- Functions/Zle/expand-absolute-path | 2 +- NEWS | 11 +++++++++++ Src/params.c | 2 +- Src/subst.c | 13 +++++++++++++ Src/utils.c | 14 ++++++++------ Test/D02glob.ztst | 8 ++++++++ 13 files changed, 68 insertions(+), 14 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 65263033a..d3a7d3356 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2016-08-22 Daniel Shahaf + + * 39046 + 39061: Completion/Base/Completer/_external_pwds, + Completion/Zsh/Type/_history_modifiers, Doc/Zsh/contrib.yo, + Doc/Zsh/expn.yo, Functions/MIME/zsh-mime-handler, + Functions/VCS_Info/VCS_INFO_quilt, + Functions/Zle/expand-absolute-path, NEWS, Src/params.c, + Src/subst.c, Src/utils.c, Test/D02glob.ztst: New :P history + modifier. + 2016-08-20 Jun-ichi Takimoto * 39064: configure.ac, Src/Modules/mathfuc.c: use scalbn() instead diff --git a/Completion/Base/Completer/_external_pwds b/Completion/Base/Completer/_external_pwds index 4ad50f02b..79e3ba0eb 100644 --- a/Completion/Base/Completer/_external_pwds +++ b/Completion/Base/Completer/_external_pwds @@ -22,7 +22,7 @@ case $OSTYPE in ) ;; linux*) - dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:A) ) + dirs=( /proc/${^$(pidof zsh):#$$}/cwd(N:P) ) dirs=( $^dirs(N^@) ) ;; *) diff --git a/Completion/Zsh/Type/_history_modifiers b/Completion/Zsh/Type/_history_modifiers index 658f9f346..1a049d6cb 100644 --- a/Completion/Zsh/Type/_history_modifiers +++ b/Completion/Zsh/Type/_history_modifiers @@ -64,8 +64,8 @@ while true; do ) if (( ! global )); then list+=( - "a:absolute path" - "A:absolute path resolving symbolic links" + "a:absolute path, resolve '..' lexically" + "A:as ':a', then resolve symlinks" "c:PATH search for command" "g:globally apply s or &" "h:head - strip trailing path element" @@ -73,6 +73,7 @@ while true; do "r:root - strip suffix" "e:leave only extension" "Q:strip quotes" + "P:realpath, resolve '..' physically" "l:lower case all words" "u:upper case all words" ) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 00ed08029..63df292ac 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3477,7 +3477,7 @@ will ensure that any files found in that area will be executed as MIME types even if they are executable. As this example shows, the complete file name is matched against the pattern, regardless of how the file was passed to the handler. The file is resolved to a full path using -the tt(:A) modifier described in +the tt(:P) modifier described in ifzman(the subsection Modifiers in zmanref(zshexpn))\ ifnzman(noderef(Modifiers)); this means that symbolic links are resolved where possible, so that diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index ca4b94f5e..ecb1877a2 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -240,6 +240,7 @@ function, symbolic links are not resolved, so on those systems `tt(a)' and `tt(A)' are equivalent. Note: tt(foo:A) and tt(realpath+LPAR()foo+RPAR()) are different on some inputs. +For tt(realpath+LPAR()foo+RPAR()) semantics, see the `tt(P)` modifier. ) item(tt(c))( Resolve a command name into an absolute path by searching the command @@ -265,6 +266,14 @@ item(tt(p))( Print the new command but do not execute it. Only works with history expansion. ) +item(tt(P))( +Turn a file name into an absolute path, like tt(realpath+LPAR()3+RPAR()). +The resulting path will be absolute, have neither `tt(.)' nor `tt(..)' components, +and refer to the same directory entry as the input filename. + +Unlike tt(realpath+LPAR()3+RPAR()), non-existent trailing components are +permitted and preserved. +) item(tt(q))( Quote the substituted words, escaping further substitutions. Works with history expansion and parameter expansion, though for parameters diff --git a/Functions/MIME/zsh-mime-handler b/Functions/MIME/zsh-mime-handler index 24e5184fc..288a0796d 100644 --- a/Functions/MIME/zsh-mime-handler +++ b/Functions/MIME/zsh-mime-handler @@ -127,7 +127,7 @@ for pattern in $exec_asis; do files=(${dirpref}${~pattern}) if [[ -n ${files[(r)$1]} ]]; then for pattern in $exec_never; do - [[ ${1:A} = ${~pattern} ]] && break 2 + [[ ${1:P} = ${~pattern} ]] && break 2 done if (( list )); then for (( i = 1; i <= $#; i++ )); do diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index e7cd89f78..6adf0a358 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -170,7 +170,7 @@ function VCS_INFO_quilt() { applied=() fi patches=$(<$pc/.quilt_patches) - patches=`builtin cd -q "${pc:h}" && print -r - ${patches:A}` + patches=`builtin cd -q "${pc:h}" && print -r - ${patches:P}` fi if zstyle -t "${context}" get-unapplied; then # This zstyle call needs to be moved further up if `quilt' needs diff --git a/Functions/Zle/expand-absolute-path b/Functions/Zle/expand-absolute-path index b85757600..4887f3c60 100644 --- a/Functions/Zle/expand-absolute-path +++ b/Functions/Zle/expand-absolute-path @@ -10,7 +10,7 @@ autoload -Uz modify-current-argument if (( ! ${+functions[glob-expand-absolute-path]} )); then glob-expand-absolute-path() { local -a files - files=(${~1}(N:A)) + files=(${~1}(N:P)) (( ${#files} )) || return REPLY=${(D)files[1]} } diff --git a/NEWS b/NEWS index 15822ad34..65b246d33 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,17 @@ CHANGES FROM PREVIOUS VERSIONS OF ZSH Note also the list of incompatibilities in the README file. +Changes from 5.2 to 5.3 +----------------------- + +The new word modifier ':P' computes the physical path of the argument. +It is different from the existing ':a' modifier which always resolves +'/before/here/../after' to '/before/after', and differs from the +existing ':A' modifier which resolves symlinks only after 'here/..' is +removed, even when /before/here is itself a symbolic link. It is +recommended to review uses of ':A' and, if appropriate, convert them +to ':P' as soon as compatibility with 5.2 is no longer a requirement. + Changes from 5.1.1 to 5.2 ------------------------- diff --git a/Src/params.c b/Src/params.c index 0eda7848f..842b2f0d1 100644 --- a/Src/params.c +++ b/Src/params.c @@ -4336,7 +4336,7 @@ void homesetfn(UNUSED(Param pm), char *x) { zsfree(home); - if (x && isset(CHASELINKS) && (home = xsymlink(x))) + if (x && isset(CHASELINKS) && (home = xsymlink(x, 0))) zsfree(x); else home = x ? x : ztrdup(""); diff --git a/Src/subst.c b/Src/subst.c index c61551bf6..15eb59b64 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -4081,6 +4081,7 @@ modify(char **str, char **ptr) case 'u': case 'q': case 'Q': + case 'P': c = **ptr; break; @@ -4287,6 +4288,12 @@ modify(char **str, char **ptr) untokenize(copy); } break; + case 'P': + if (*copy != '/') { + copy = zhtricat(metafy(zgetcwd(), -1, META_HEAPDUP), "/", copy); + } + copy = xsymlink(copy, 1); + break; } tc = *tt; *tt = '\0'; @@ -4363,6 +4370,12 @@ modify(char **str, char **ptr) untokenize(*str); } break; + case 'P': + if (**str != '/') { + *str = zhtricat(metafy(zgetcwd(), -1, META_HEAPDUP), "/", *str); + } + *str = xsymlink(*str, 1); + break; } } if (rec < 0) { diff --git a/Src/utils.c b/Src/utils.c index 0a5954f65..45fd19286 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -801,9 +801,9 @@ findpwd(char *s) char *t; if (*s == '/') - return xsymlink(s); + return xsymlink(s, 0); s = tricat((pwd[1]) ? pwd : "", "/", s); - t = xsymlink(s); + t = xsymlink(s, 0); zsfree(s); return t; } @@ -969,11 +969,13 @@ xsymlinks(char *s, int full) /* * expand symlinks in s, and remove other weird things: * note that this always expands symlinks. + * + * 'heap' indicates whether to malloc() or allocate on the heap. */ /**/ char * -xsymlink(char *s) +xsymlink(char *s, int heap) { if (*s != '/') return NULL; @@ -981,8 +983,8 @@ xsymlink(char *s) if (xsymlinks(s + 1, 1) < 0) zwarn("path expansion failed, using root directory"); if (!*xbuf) - return ztrdup("/"); - return ztrdup(xbuf); + return heap ? dupstring("/") : ztrdup("/"); + return heap ? dupstring(xbuf) : ztrdup(xbuf); } /**/ @@ -1260,7 +1262,7 @@ getnameddir(char *name) /* Retrieve an entry from the password table/database for this user. */ struct passwd *pw; if ((pw = getpwnam(name))) { - char *dir = isset(CHASELINKS) ? xsymlink(pw->pw_dir) + char *dir = isset(CHASELINKS) ? xsymlink(pw->pw_dir, 0) : ztrdup(pw->pw_dir); if (dir) { adduserdir(name, dir, ND_USERNAME, 1); diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst index 7befbc21f..1385d57d9 100644 --- a/Test/D02glob.ztst +++ b/Test/D02glob.ztst @@ -678,3 +678,11 @@ rm glob.tmp/link 0:modifier ':A' resolves '..' components before symlinks # There should be no output + + ln -s dir3/subdir glob.tmp/link + () { + print ${1:P} + } glob.tmp/link/../../hello/world + rm glob.tmp/link +0:modifier ':P' resolves symlinks before '..' components +*>*glob.tmp/hello/world -- cgit v1.2.3 From fde365ea8ba91a4e7daa27dfd63fdadb55a882f5 Mon Sep 17 00:00:00 2001 From: Teubel György Date: Sat, 3 Sep 2016 23:06:30 +0200 Subject: 39167: Make $ENV handling more like POSIX --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 3 ++- Src/init.c | 25 ++++++++++++++----------- 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index b6f4836d7..f5d18990a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-05 Peter Stephenson + + * Teubel György: 39167: Src/init.c, Doc/Zsh/params.yo: Make $ENV + more like POSIX. + 2016-09-04 Daniel Shahaf * unposted: Src/Zle/comp.h, Src/Zle/complete.c: internals: diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 55930ed7b..03625ce24 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1059,7 +1059,8 @@ If the tt(ENV) environment variable is set when zsh is invoked as tt(sh) or tt(ksh), tt($ENV) is sourced after the profile scripts. The value of tt(ENV) is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a pathname. Note that -tt(ENV) is em(not) used unless zsh is emulating bf(sh) or bf(ksh). +tt(ENV) is em(not) used unless the shell is interactive and zsh is +emulating bf(sh) or bf(ksh). ) vindex(FCEDIT) item(tt(FCEDIT))( diff --git a/Src/init.c b/Src/init.c index 20a07eb0a..3dea179b9 100644 --- a/Src/init.c +++ b/Src/init.c @@ -712,7 +712,7 @@ init_term(void) if (tgetent(termbuf, term) != TGETENT_SUCCESS) #endif { - if (isset(INTERACTIVE)) + if (interact) zerr("can't find terminal definition for %s", term); errflag &= ~ERRFLAG_ERROR; termflags |= TERM_BAD; @@ -1205,19 +1205,22 @@ run_init_scripts(void) if (islogin) source("/etc/profile"); if (unset(PRIVILEGED)) { - char *s = getsparam("ENV"); if (islogin) sourcehome(".profile"); - noerrs = 2; - if (s) { - s = dupstring(s); - if (!parsestr(&s)) { - singsub(&s); - noerrs = 0; - source(s); + + if (interact) { + noerrs = 2; + char *s = getsparam("ENV"); + if (s) { + s = dupstring(s); + if (!parsestr(&s)) { + singsub(&s); + noerrs = 0; + source(s); + } } + noerrs = 0; } - noerrs = 0; } else source("/etc/suid_profile"); } else { @@ -1227,7 +1230,7 @@ run_init_scripts(void) if (isset(RCS) && unset(PRIVILEGED)) { - if (isset(INTERACTIVE)) { + if (interact) { /* * Always attempt to load the newuser module to perform * checks for new zsh users. Don't care if we can't load it. -- cgit v1.2.3 From 73c0e8d4e679ed681acc4883234324c7676cc676 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 4 Sep 2016 18:26:32 +0000 Subject: 39173: _arguments: Escape colons and backslashes in $opt_args unambiguously. --- ChangeLog | 4 ++++ Doc/Zsh/compsys.yo | 6 ++++-- README | 9 +++++++++ Src/Zle/computil.c | 12 +++++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index be821de99..4643eda77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-09-06 Daniel Shahaf + * 39173: Doc/Zsh/compsys.yo, README, Src/Zle/computil.c: + _arguments: Escape colons and backslashes in $opt_args + unambiguously. + * 39171: Completion/Unix/Command/_libvirt: Apply $opt_args-unescaping. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 8c7ef0f5a..b2cc39268 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3948,8 +3948,10 @@ command line after the command name excluding all options and their arguments. Options are stored in the associative array `tt(opt_args)' with option names as keys and their arguments as the values. For options that have more than one argument these are -given as one string, separated by colons. All colons in the original -arguments are preceded with backslashes. +given as one string, separated by colons. All colons and backslashes +in the original arguments are preceded with backslashes. (Note: +Zsh 5.2 and older did not escape backslashes in the original string; +see the tt(NEWS) file for details.) The parameter `tt(context)' is set when returning to the calling function to perform an action of the form `tt(->)var(string)'. It is set to an diff --git a/README b/README index 9de5eb4a9..019294e4b 100644 --- a/README +++ b/README @@ -87,6 +87,15 @@ The "f" qualifier has for many years been the documented way of testing file modes; it allows the "and" test ("*(f+1)" is the documented equivalent of "*(1)") as well as many other forms. +5) The completion helper function _arguments now escapes both backslashes +and colons in the values of option arguments when populating the $opt_args +associative array. Previously, colons were escaped with a backslash but +backslashes were not themselves escaped with a backslash, which lead to +ambiguity: if the -x option took two arguments (as in + _arguments : -x:foo:${action}:bar:$action +), it would be impossible to tell from $opt_args whether the command-line +was '-x foo\:bar' or '-x foo\\ bar'. + Incompatibilities between 5.0.8 and 5.2 --------------------------------------- diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index ecfa2bc34..1c90a543a 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2310,7 +2310,10 @@ ca_parse_line(Cadef d, int multi, int first) return 0; } -/* Build a colon-list from a list. */ +/* Build a colon-list from a list. + * + * This is only used to populate values of $opt_args. + */ static char * ca_colonlist(LinkList l) @@ -2320,16 +2323,19 @@ ca_colonlist(LinkList l) int len = 0; char *p, *ret, *q; + /* Compute the length to be allocated. */ for (n = firstnode(l); n; incnode(n)) { len++; for (p = (char *) getdata(n); *p; p++) - len += (*p == ':' ? 2 : 1); + len += (*p == ':' || *p == '\\') ? 2 : 1; } ret = q = (char *) zalloc(len); + /* Join L into RET, joining with colons and escaping colons and + * backslashes. */ for (n = firstnode(l); n;) { for (p = (char *) getdata(n); *p; p++) { - if (*p == ':') + if (*p == ':' || *p == '\\') *q++ = '\\'; *q++ = *p; } -- cgit v1.2.3 From 73622ae2880a599ad7ed84d43538c34cf55a48ca Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 8 Sep 2016 11:01:15 +0000 Subject: 39236 (plus typo fix): docs: Tweak _arguments $opt_args documentation added in 39173. --- ChangeLog | 5 +++++ Doc/Zsh/compsys.yo | 4 +--- README | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index a45011ed3..2651b7343 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-08 Daniel Shahaf + + * 39236 (plus typo fix): Doc/Zsh/compsys.yo, README: docs: Tweak + _arguments $opt_args documentation added in 39173. + 2016-09-08 Peter Stephenson * 39222: Test/V01zmodload.ztst: test use of module loaded math diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index b2cc39268..ecf17e728 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3949,9 +3949,7 @@ arguments. Options are stored in the associative array `tt(opt_args)' with option names as keys and their arguments as the values. For options that have more than one argument these are given as one string, separated by colons. All colons and backslashes -in the original arguments are preceded with backslashes. (Note: -Zsh 5.2 and older did not escape backslashes in the original string; -see the tt(NEWS) file for details.) +in the original arguments are preceded with backslashes. The parameter `tt(context)' is set when returning to the calling function to perform an action of the form `tt(->)var(string)'. It is set to an diff --git a/README b/README index 019294e4b..d146d4b16 100644 --- a/README +++ b/README @@ -91,10 +91,15 @@ equivalent of "*(1)") as well as many other forms. and colons in the values of option arguments when populating the $opt_args associative array. Previously, colons were escaped with a backslash but backslashes were not themselves escaped with a backslash, which lead to -ambiguity: if the -x option took two arguments (as in +ambiguity: '-x foo\:bar' (one argument with a backslashed colon) and +'-x foo\\ bar' (two arguments, and the first one ends in a backslash) would +both set $opt_args[-x] to the same value. This example assumes the -x +option's spec declared two arguments, as in: _arguments : -x:foo:${action}:bar:$action -), it would be impossible to tell from $opt_args whether the command-line -was '-x foo\:bar' or '-x foo\\ bar'. + +For the more common case of non-repeatable options that take a single +argument, completion functions now have to unescape not only colons but +also backslashes when obtaining the option's argument from $opt_args. Incompatibilities between 5.0.8 and 5.2 --------------------------------------- -- cgit v1.2.3 From 8011fe8a582bd3c018a98e0e2c08f65233bcf0fc Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 11 Sep 2016 13:22:35 +0200 Subject: 39261 (tweaked cf. Daniel: 39275): don't unconditionally elevate privileges with sudo in completion functions A new gain-privileges style enables it and a _comp_priv_prefix array added for tracking how to match privileges for the current command --- ChangeLog | 15 +++++++++ Completion/BSD/Command/_jexec | 1 + Completion/Base/Core/_main_complete | 1 + Completion/Base/Utility/_call_program | 11 +++++-- Completion/Debian/Command/_dchroot | 1 + Completion/Debian/Command/_dchroot-dsa | 1 + Completion/Debian/Command/_schroot | 1 + Completion/Mandriva/Command/_rebootin | 2 +- Completion/Solaris/Command/_pfexec | 2 +- Completion/Solaris/Command/_zlogin | 2 ++ Completion/Unix/Command/_dsh | 1 + Completion/Unix/Command/_fsh | 1 + Completion/Unix/Command/_libvirt | 10 +++--- Completion/Unix/Command/_mosh | 1 + Completion/Unix/Command/_rlogin | 1 + Completion/Unix/Command/_ssh | 1 + Completion/Unix/Command/_sudo | 2 +- Doc/Zsh/compsys.yo | 59 +++++++++++++++++++++++++++++----- 18 files changed, 95 insertions(+), 18 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 7fba3550c..78931adbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2016-09-11 Oliver Kiddle + + * 39261 (tweaked cf. Daniel: 39275): Doc/Zsh/compsys.yo: + Completion/Base/Core/_main_complete, + Completion/Base/Utility/_call_program, + Completion/Debian/Command/_dchroot, + Completion/Debian/Command/_dchroot-dsa, + Completion/Debian/Command/_schroot, + Completion/Solaris/Command/_pfexec, + Completion/Solaris/Command/_zlogin, Completion/Unix/Command/_dsh, + Completion/Unix/Command/_fsh, Completion/Unix/Command/_libvirt, + Completion/Unix/Command/_mosh, Completion/Unix/Command/_rlogin, + Completion/Unix/Command/_ssh, Completion/Unix/Command/_sudo: + don't unconditionally gain privileges with sudo for completion + 2016-09-11 Daniel Shahaf * 39252: Src/Zle/compcore.c, Src/Zle/compctl.c, diff --git a/Completion/BSD/Command/_jexec b/Completion/BSD/Command/_jexec index 279812bbc..85829d10e 100644 --- a/Completion/BSD/Command/_jexec +++ b/Completion/BSD/Command/_jexec @@ -2,6 +2,7 @@ _jexec_normal() { local PATH=$PATH + local -a _comp_priv_prefix # relative paths are relative to the jail's root path=( "$(command jls -j $words[1] path)"/$^path ) shift 1 words; (( CURRENT-- )) diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 9c4cfac85..c292ce7d7 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -38,6 +38,7 @@ local func funcs ret=1 tmp _compskip format nm call match min max i num\ _saved_colors="$ZLS_COLORS" \ _saved_colors_set=${+ZLS_COLORS} \ _ambiguous_color='' +local -a _comp_priv_prefix # _precommand sets this to indicate we are following a precommand modifier local -a precommands diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program index 010e09476..95c761e65 100644 --- a/Completion/Base/Utility/_call_program +++ b/Completion/Base/Utility/_call_program @@ -1,6 +1,13 @@ #autoload +X local tmp err_fd=-1 +local -a prefix + +if [[ "$1" = -p ]]; then + shift + zstyle -t ":completion:${curcontext}:${1}" gain-privileges && + prefix=( $_comp_priv_prefix ) +fi if (( ${debug_fd:--1} > 2 )) || [[ ! -t 2 ]] then exec {err_fd}>&2 # debug_fd is saved stderr, 2 is trace or redirect @@ -13,10 +20,10 @@ if zstyle -s ":completion:${curcontext}:${1}" command tmp; then if [[ "$tmp" = -* ]]; then eval "$tmp[2,-1]" "$argv[2,-1]" else - eval "$tmp" + eval $prefix "$tmp" fi else - eval "$argv[2,-1]" + eval $prefix "$argv[2,-1]" fi 2>&$err_fd } always { diff --git a/Completion/Debian/Command/_dchroot b/Completion/Debian/Command/_dchroot index c26e5691a..2a6f5d808 100644 --- a/Completion/Debian/Command/_dchroot +++ b/Completion/Debian/Command/_dchroot @@ -2,6 +2,7 @@ local expl context state line typeset -A opt_args +local -a _comp_priv_prefix _arguments -S \ '(-h --help)'{-h,--help}'[help]' \ diff --git a/Completion/Debian/Command/_dchroot-dsa b/Completion/Debian/Command/_dchroot-dsa index d4668b553..e8e981b84 100644 --- a/Completion/Debian/Command/_dchroot-dsa +++ b/Completion/Debian/Command/_dchroot-dsa @@ -2,6 +2,7 @@ local expl context state line typeset -A opt_args +local -a _comp_priv_prefix _arguments -S \ '(-h --help)'{-h,--help}'[help]' \ diff --git a/Completion/Debian/Command/_schroot b/Completion/Debian/Command/_schroot index 06117be88..117df45ef 100644 --- a/Completion/Debian/Command/_schroot +++ b/Completion/Debian/Command/_schroot @@ -2,6 +2,7 @@ local expl context state line typeset -A opt_args +local -a _comp_priv_prefix _arguments -S \ '(-h --help)'{-h,--help}'[help]' \ diff --git a/Completion/Mandriva/Command/_rebootin b/Completion/Mandriva/Command/_rebootin index 3f30b2591..284ff08f1 100644 --- a/Completion/Mandriva/Command/_rebootin +++ b/Completion/Mandriva/Command/_rebootin @@ -2,7 +2,7 @@ local context state line expl typeset -A opt_args -local loader=$(sudo detectloader -q) +local loader=${$(_call_program -p entries detectloader -q):-GRUB} _arguments -s \ '-n[no immediate reboot just set the flags for next reboot]' \ diff --git a/Completion/Solaris/Command/_pfexec b/Completion/Solaris/Command/_pfexec index 227336223..3f1f3e733 100644 --- a/Completion/Solaris/Command/_pfexec +++ b/Completion/Solaris/Command/_pfexec @@ -25,7 +25,7 @@ _pfexec() { _arguments \ '-P[privileges to acquire]:privspec:_privset' \ '(-):command name: _command_names -e' \ - '*::arguments: _normal' + '*::arguments:{ _comp_priv_prefix=( $words[1] ${(kv)opt_args[-P]} ) ; _normal }' } _pfexec "$@" diff --git a/Completion/Solaris/Command/_zlogin b/Completion/Solaris/Command/_zlogin index 04018eb87..065f55b03 100644 --- a/Completion/Solaris/Command/_zlogin +++ b/Completion/Solaris/Command/_zlogin @@ -1,6 +1,8 @@ #compdef zlogin # Synced with the Nevada build 162 man page +local -a _comp_priv_prefix + _zlogin() { _arguments -s \ '-E[Disable escape character]' \ diff --git a/Completion/Unix/Command/_dsh b/Completion/Unix/Command/_dsh index 688e024ce..8c5c23208 100644 --- a/Completion/Unix/Command/_dsh +++ b/Completion/Unix/Command/_dsh @@ -2,6 +2,7 @@ local curcontext="$curcontext" state line expl typeset -A opt_args +local -a _comp_priv_prefix _arguments -s -C -S \ '(-v --verbose -q --quiet)'{-v,--verbose}'[verbose output]' \ diff --git a/Completion/Unix/Command/_fsh b/Completion/Unix/Command/_fsh index d9ced5feb..c39373117 100644 --- a/Completion/Unix/Command/_fsh +++ b/Completion/Unix/Command/_fsh @@ -1,6 +1,7 @@ #compdef fsh local curcontext="$curcontext" state line ret=1 +local -a _comp_priv_prefix _arguments -C \ '(- : *)'{-h,--help}'[display help information]' \ diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index 658e197dc..17b02be81 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -155,7 +155,7 @@ case $state in return 1 ;; --device) - values; values=( $(_call_program nodedevs "virsh $conn_opt nodedev-list") ) + values; values=( $(_call_program devices "virsh $conn_opt nodedev-list") ) [[ -n $values ]] && _wanted devices expl device compadd ${=values} && return 0 return 1 ;; @@ -204,7 +204,7 @@ case $state in fi fi [[ -z $_cache_virsh_cmd_opts[$cmd] ]] && \ - _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program options virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n ${=_cache_virsh_cmd_opts[$cmd]} ]] && \ _values -w option ${(u)=_cache_virsh_cmd_opts[$cmd]} && ret=0 ;; @@ -218,16 +218,16 @@ case $state in done [[ -z $cmd ]] && return 1 if [[ $words[CURRENT-1] == --server ]]; then - _wanted servers expl server compadd ${=${(S)${${(f)$(sudo virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 + _wanted servers expl server compadd ${=${(S)${${(f)$(_call_program -p servers virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 fi if [[ $words[CURRENT-1] == --client ]]; then local srv ; (( ${(k)words[(I)--server]} > 0 )) && srv=${words[1+${(k)words[(I)--server]}]} [[ -z $srv ]] && return 1 [[ -n ${srv//[[:alnum:]]} ]] && return 1 - _wanted clients expl client compadd ${=${${(f):-"$(sudo virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 + _wanted clients expl client compadd ${=${${(f):-"$(_call_program -p clients virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 fi [[ -z $_cache_virt_admin_cmd_opts[$cmd] ]] && \ - _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virt-admin virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program options virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n $_cache_virt_admin_cmd_opts[$cmd] ]] && \ _values -w option ${(u)=_cache_virt_admin_cmd_opts[$cmd]} && ret=0 ;; diff --git a/Completion/Unix/Command/_mosh b/Completion/Unix/Command/_mosh index c19f6ebde..431fdbf9e 100644 --- a/Completion/Unix/Command/_mosh +++ b/Completion/Unix/Command/_mosh @@ -1,6 +1,7 @@ #compdef mosh local curcontext="$curcontext" state line +local -a _comp_priv_prefix _arguments -C \ '(-)--help[display help information]' \ diff --git a/Completion/Unix/Command/_rlogin b/Completion/Unix/Command/_rlogin index a04c6d068..8f74939fd 100644 --- a/Completion/Unix/Command/_rlogin +++ b/Completion/Unix/Command/_rlogin @@ -12,6 +12,7 @@ _rlogin () { rsh|remsh) local context state line ret=1 typeset -A opt_args + local -a _comp_priv_prefix _arguments -s \ '-n[ignore stdin]' \ diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh index 7b2cdd8e1..5ee4fd2ad 100644 --- a/Completion/Unix/Command/_ssh +++ b/Completion/Unix/Command/_ssh @@ -605,6 +605,7 @@ _ssh () { hmac-sha2-256-96 hmac-sha2-512 hmac-sha2-512-96 && ret=0 ;; command) + local -a _comp_priv_prefix shift 1 words (( CURRENT-- )) _normal diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo index 63ac37f62..21b1ef4c6 100644 --- a/Completion/Unix/Command/_sudo +++ b/Completion/Unix/Command/_sudo @@ -48,7 +48,7 @@ else '(-H --set-home -i --login -s --shell -e --edit)'{-H,--set-home}"[set HOME variable to target user's home dir]" \ '(-P --preserve-groups -i -login -s --shell -e --edit)'{-P,--preserve-groups}"[preserve group vector instead of setting to target's]" \ '(-)1:command: _command_names -e' - '*::arguments: _normal' + '*::arguments:{ _comp_priv_prefix=( $words[1] -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }' ) fi diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index ecf17e728..bc036ada5 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1842,6 +1842,15 @@ In the case of the tt(_match) completer, the style may also be set to the string `tt(pattern)'. Then the pattern on the line is left unchanged if it does not match unambiguously. ) +kindex(gain-privileges, completion style) +item(tt(gain-privileges))( +If set to tt(true), this style enables the use of commands like tt(sudo) +or tt(doas) to gain extra privileges when retrieving information for +completion. This is only done when a command such as tt(sudo) appears on +the command-line. To force the use of, e.g. tt(sudo) or to override any +prefix that might be added due to tt(gain-privileges), the tt(command) +style can be used with a value that begins with a hyphen. +) kindex(keep-prefix, completion style) item(tt(keep-prefix))( This style is used by the tt(_expand) completer. If it is `true', the @@ -3471,12 +3480,6 @@ generating matches all follow the convention of returning status zero if they generated completions and non-zero if no matching completions could be added. -Two more features are offered by the tt(_main_complete) function. The -arrays tt(compprefuncs) and tt(comppostfuncs) may contain -names of functions that are to be called immediately before or after -completion has been tried. A function will only be called once unless -it explicitly reinserts itself into the array. - startitem() findex(_absolute_command_paths) item(tt(_absolute_command_paths))( @@ -4173,7 +4176,7 @@ The return status of tt(_call_function) itself is zero if the function var(name) exists and was called and non-zero otherwise. ) findex(_call_program) -item(tt(_call_program) var(tag) var(string) ...)( +item(tt(_call_program) [ tt(-p) ] var(tag) var(string) ...)( This function provides a mechanism for the user to override the use of an external command. It looks up the tt(command) style with the supplied var(tag). If the style is set, its value is used as the command to @@ -4181,6 +4184,13 @@ execute. The var(string)s from the call to tt(_call_program), or from the style if set, are concatenated with spaces between them and the resulting string is evaluated. The return status is the return status of the command called. + +If the option `tt(-p)' is supplied it indicates that the command +output is influenced by the permissions it is run with. If the +tt(gain-privileges) style is set to true, tt(_call_program) will make +use of commands such as tt(sudo), if present on the command-line, to +match the permissions to whatever the final command is likely to run +under. ) findex(_combination) item(tt(_combination) [ tt(-s) var(pattern) ] var(tag) var(style) var(spec) ... var(field) var(opts) ...)( @@ -5073,7 +5083,40 @@ ifnzman(noderef(The zsh/zleparameter Module)). ) enditem() -texinode(Completion Directories)()(Completion Functions)(Completion System) +texinode(Completion System Variables)(Completion Directories)(Completion Functions)(Completion System) +sect(Completion System Variables) +cindex(completion system, variables) + +There are some standard variables, initialised by the tt(_main_complete) +function and then used from other functions. + +The standard variables are: + +startitem() +item(tt(_comp_caller_options))( +The completion system uses tt(setopt) to set a number of options. This +allows functions to be written without concern for compatibility with +every possible combination of user options. However, sometimes completion +needs to know what the user's option preferences are. These are saved +in the tt(_comp_caller_options) associative array. Option names, spelled +in lowercase without underscores, are mapped to one or other of the +strings `tt(on)' and `tt(off)'. +) + +item(tt(_comp_priv_prefix))( +Completion functions such as tt(_sudo) can set the tt(_comp_priv_prefix) +array to a command prefix that may then be used by tt(_call_program) to +match the privileges when calling programs to generate matches. +) +enditem() + +Two more features are offered by the tt(_main_complete) function. The +arrays tt(compprefuncs) and tt(comppostfuncs) may contain +names of functions that are to be called immediately before or after +completion has been tried. A function will only be called once unless +it explicitly reinserts itself into the array. + +texinode(Completion Directories)()(Completion System Variables)(Completion System) sect(Completion Directories) cindex(completion system, directory structure) -- cgit v1.2.3 From ef019506aeab44d830efccef27a7c9727156300c Mon Sep 17 00:00:00 2001 From: Vin Shelton Date: Sun, 11 Sep 2016 16:48:06 -0400 Subject: 39284: Added Completion System Variables as a menu item --- ChangeLog | 6 ++++++ Doc/Zsh/compsys.yo | 1 + 2 files changed, 7 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 78931adbb..c806955f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-11 Vin Shelton + + * 39284: Doc/Zsh/compsys.yo: + Added Completion System Variables as a menu item + 2016-09-11 Oliver Kiddle * 39261 (tweaked cf. Daniel: 39275): Doc/Zsh/compsys.yo: @@ -17,6 +22,7 @@ * 39252: Src/Zle/compcore.c, Src/Zle/compctl.c, Src/Zle/computil.c, Src/Zle/zle_misc.c, Src/Zle/zle_tricky.c, + Src/builtin.c, Src/subst.c, Src/text.c, Src/utils.c: internal: quotestring: Drop the 'e' parameter, which no caller uses. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index bc036ada5..87be0fc59 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -91,6 +91,7 @@ menu(Control Functions) menu(Bindable Commands) menu(Completion Functions) menu(Completion Directories) +menu(Completion System Variables) endmenu() texinode(Initialization)(Completion System Configuration)()(Completion System) -- cgit v1.2.3 From 1fc4e6dcac82388e71643330063a02c1d15f9a20 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 12 Sep 2016 14:57:59 +0100 Subject: 39255: = in conditions is not going anywhere --- Doc/Zsh/cond.yo | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo index 3d369fb83..474baa1ec 100644 --- a/Doc/Zsh/cond.yo +++ b/Doc/Zsh/cond.yo @@ -103,8 +103,10 @@ true if var(file1) and var(file2) exist and refer to the same file. xitem(var(string) tt(=) var(pattern)) item(var(string) tt(==) var(pattern))( true if var(string) matches var(pattern). -The `tt(==)' form is the preferred one. The `tt(=)' form is for -backward compatibility and should be considered obsolete. +The two forms are exactly equivalent. The `tt(=)' form is +the traditional shell syntax (and hence the only one generally used +with the tt(test) and tt([) builtins); the `tt(==)' form provides +compatibility with other sorts of computer language. ) item(var(string) tt(!=) var(pattern))( true if var(string) does not match var(pattern). -- cgit v1.2.3 From 5456cab86f3720109e3f47915267ed43dc511271 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Mon, 12 Sep 2016 09:50:25 -0700 Subject: 39297: more of 39284, it's painful to add texi nodes in yodl Also fix some inconsequential ChangeLog typos. --- ChangeLog | 11 ++++++++--- Doc/Zsh/compsys.yo | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2febfef09..17e0dd00f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-12 Barton E. Schaefer + + * 39297: Doc/Zsh/compsys.yo: more of 39284, it's painful to add + texi nodes in yodl + 2016-09-12 Peter Stephenson * 39255: Doc/Zsh/cond.yo: = in conditions is not actually going @@ -10,8 +15,8 @@ 2016-09-11 Vin Shelton - * 39284: Doc/Zsh/compsys.yo: - Added Completion System Variables as a menu item + * 39284: Doc/Zsh/compsys.yo: Added Completion System Variables as + a menu item 2016-09-11 Oliver Kiddle @@ -734,7 +739,7 @@ * 38692: Doc/Zsh/restricted.yo, Src/params.c: IFS can't be changed in restricted mode. -2016-06-19 Barton E. Schaefer +2016-06-19 Barton E. Schaefer * 38715: Doc/Zsh/contrib.yo, Functions/Zle/add-zle-hook-widget: assorted ksharrays fixes; assign an index to any hook that is diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 87be0fc59..cab665b1c 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -3468,7 +3468,7 @@ emacs and vi respectively. ) enditem() -texinode(Completion Functions)(Completion Directories)(Bindable Commands)(Completion System) +texinode(Completion Functions)(Completion System Variables)(Bindable Commands)(Completion System) sect(Utility Functions) cindex(completion system, utility functions) -- cgit v1.2.3 From 43137b8e8f9ce8a3c9d6b0cd530102813fc6b5a6 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Mon, 12 Sep 2016 09:52:23 -0700 Subject: unposted: reference use of widgets to effect editor changes from a sched command --- ChangeLog | 3 +++ Doc/Zsh/mod_sched.yo | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 17e0dd00f..88a508268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-09-12 Barton E. Schaefer + * unposted: Doc/Zsh/mod_sched.yo: reference use of widgets to + effect editor changes from a sched command + * 39297: Doc/Zsh/compsys.yo: more of 39284, it's painful to add texi nodes in yodl diff --git a/Doc/Zsh/mod_sched.yo b/Doc/Zsh/mod_sched.yo index 1350b9e4c..30b08a3ff 100644 --- a/Doc/Zsh/mod_sched.yo +++ b/Doc/Zsh/mod_sched.yo @@ -40,6 +40,11 @@ afterwards. This should be used with any scheduled event that produces visible output to the terminal; it is not needed, for example, with output that updates a terminal emulator's title bar. +To effect changes to the editor buffer when an event executes, use the +`tt(zle)' command with no arguments to test whether the editor is active, +and if it is, then use `tt(zle )var(widget)' to access the editor via +the named var(widget). + The tt(sched) builtin is not made available by default when the shell starts in a mode emulating another shell. It can be made available with the command `tt(zmodload -F zsh/sched b:sched)'. -- cgit v1.2.3 From d0f9150530a872f04c88e7039646d18e3eaca135 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 14 Sep 2016 12:17:38 +0100 Subject: unposted: small documentation tweaks --- ChangeLog | 2 ++ Doc/Zsh/expn.yo | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 357782c2b..5ef7678a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2016-09-14 Peter Stephenson + * unposted: Doc/Zsh/expn.yo: small documentation tweaks. + * zsh-users/21903: Src/subst.c, Src/zsh.h, Test/D04parameter.ztst: ${...?...} in interactive shell should abort to top level, not just current command. diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index ecb1877a2..b73151698 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -745,7 +745,7 @@ character of tt($foo) if the substitution would otherwise return a scalar, or the array starting at the fourth element if tt($foo) would return an array. Note that with the option tt(KSH_ARRAYS) tt($foo) always returns a scalar (regardless of the use of the offset syntax) and a form -such as tt($foo[*]:3) is required to extract elements of an array named +such as tt(${foo[*]:3}) is required to extract elements of an array named tt(foo). If var(offset) is negative, the tt(-) may not appear immediately @@ -761,8 +761,8 @@ expression tt(${var: offs}) does work, retrieving the offset from tt($offs). For further compatibility with other shells there is a special case -for array offset 0. This usually accesses to the -first element of the array. However, if the substitution refers the +for array offset 0. This usually accesses the +first element of the array. However, if the substitution refers to the positional parameter array, e.g. tt($@) or tt($*), then offset 0 instead refers to tt($0), offset 1 refers to tt($1), and so on. In other words, the positional parameter array is effectively extended by -- cgit v1.2.3 From fbafc5b509e311efee064bbd12396a2e207f3393 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 16 Sep 2016 00:00:28 +0200 Subject: 39332: support ksh's [[ -v varname ]] condition for checking if variables are set --- ChangeLog | 4 ++++ Completion/Zsh/Context/_condition | 3 +++ Doc/Zsh/cond.yo | 3 +++ Src/cond.c | 2 ++ Src/params.c | 30 ++++++++++++++++++++++++++++++ Src/parse.c | 4 ++-- Test/C02cond.ztst | 19 +++++++++++++++++++ 7 files changed, 63 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 1c749ae64..f54d78ca3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-09-15 Oliver Kiddle + * 39332: Doc/Zsh/cond.yo, Src/cond.c, Src/params.c, Src/parse.c, + Completion/Zsh/Context/_condition, Test/C02cond.ztst: support + ksh's [[ -v varname ]] condition for checking if variables are set + * unposted: Src/parse.c: remove duplicated assignment 2016-09-14 Peter Stephenson diff --git a/Completion/Zsh/Context/_condition b/Completion/Zsh/Context/_condition index 6f5e601f0..0285911ac 100644 --- a/Completion/Zsh/Context/_condition +++ b/Completion/Zsh/Context/_condition @@ -8,6 +8,8 @@ elif [[ "$prev" = -([a-hkprsuwxLOGSN]|[no]t|ef) ]]; then _tags -C "$prev" files && _files elif [[ "$prev" = -t ]]; then _file_descriptors +elif [[ "$prev" = -v ]]; then + _parameters -r "\= \t\n\[\-" else if [[ "$PREFIX" = -* ]] || ! zstyle -T ":completion:${curcontext}:options" prefix-needed; then @@ -30,6 +32,7 @@ else -s:non-empty\ file -t:terminal\ file\ descriptor -u:setuid\ bit + -v:set\ variable -w:writable\ file -x:executable\ file -z:empty\ string diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo index 474baa1ec..e08fc0d36 100644 --- a/Doc/Zsh/cond.yo +++ b/Doc/Zsh/cond.yo @@ -63,6 +63,9 @@ is open and associated with a terminal device. item(tt(-u) var(file))( true if var(file) exists and has its setuid bit set. ) +item(tt(-v) var(varname))( +true if shell variable var(varname) is set. +) item(tt(-w) var(file))( true if var(file) exists and is writable by current process. ) diff --git a/Src/cond.c b/Src/cond.c index f25ebd4a3..42e9de30f 100644 --- a/Src/cond.c +++ b/Src/cond.c @@ -351,6 +351,8 @@ evalcond(Estate state, char *fromtest) return (!S_ISSOCK(dostat(left))); case 'u': return (!(dostat(left) & S_ISUID)); + case 'v': + return (!issetvar(left)); case 'w': return (!doaccess(left, W_OK)); case 'x': diff --git a/Src/params.c b/Src/params.c index 842b2f0d1..384c30a1a 100644 --- a/Src/params.c +++ b/Src/params.c @@ -626,6 +626,36 @@ getvaluearr(Value v) return NULL; } +/* Return whether the variable is set * + * checks that array slices are within range * + * used for [[ -v ... ]] condition test */ + +/**/ +int +issetvar(char *name) +{ + struct value vbuf; + Value v; + int slice; + char **arr; + + if (!(v = getvalue(&vbuf, &name, 1)) || *name) + return 0; /* no value or more chars after the variable name */ + if (v->isarr & ~SCANPM_ARRONLY) + return v->end > 1; /* for extracted elements, end gives us a count */ + + slice = v->start != 0 || v->end != -1; + if (PM_TYPE(v->pm->node.flags) != PM_ARRAY || !slice) + return !slice && !(v->pm->node.flags & PM_UNSET); + + if (!v->end) /* empty array slice */ + return 0; + /* get the array and check end is within range */ + if (!(arr = getvaluearr(v))) + return 0; + return arrlen_ge(arr, v->end < 0 ? - v->end : v->end); +} + /* * Split environment string into (name, value) pair. * this is used to avoid in-place editing of environment table diff --git a/Src/parse.c b/Src/parse.c index d3c418184..24b8cd97f 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -2385,7 +2385,7 @@ par_cond_2(void) s1 = tokstr; dble = (s1 && *s1 == '-' && (!n_testargs - || strspn(s1+1, "abcdefghknoprstuwxzLONGS") == 1) + || strspn(s1+1, "abcdefghknoprstuvwxzLONGS") == 1) && !s1[2]); if (tok != STRING) { /* Check first argument for [[ STRING ]] re-interpretation */ @@ -2464,7 +2464,7 @@ par_cond_double(char *a, char *b) { if (a[0] != '-' || !a[1]) COND_ERROR("parse error: condition expected: %s", a); - else if (!a[2] && strspn(a+1, "abcdefgknoprstuwxzhLONGS") == 1) { + else if (!a[2] && strspn(a+1, "abcdefgknoprstuvwxzhLONGS") == 1) { ecadd(WCB_COND(a[1], 0)); ecstr(b); } else { diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 78e644a72..40e4dfb0b 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -269,6 +269,25 @@ F:Failures in these cases do not indicate a problem in the shell. 0:-nt shouldn't abort on non-existent files >status = 1 + str='string' empty='' + [[ -v IFS && -v str && -v empty && ! -v str[3] && ! -v not_a_variable ]] +0:-v cond + + arr=( 1 2 3 4 ) empty=() + [[ -v arr && -v arr[1,4] && -v arr[1] && -v arr[4] && -v arr[-4] && + -v arr[(i)3] && ! -v arr[(i)x] && + ! -v arr[0] && ! -v arr[5] && ! -v arr[-5] && ! -v arr[2][1] && + ! -v arr[3]extra && -v empty && ! -v empty[1] ]] +0:-v cond with array + + typeset -A assoc=( key val num 4 ) + [[ -v assoc && -v assoc[key] && -v assoc[(i)*] && -v assoc[(I)*] && + ! -v assoc[x] && ! -v assoc[key][1] ]] +0:-v cond with association + + () { [[ -v 0 && -v 1 && -v 2 && ! -v 3 ]] } arg '' +0:-v cond with positional parameters + # core dumps on failure if zmodload zsh/regex 2>/dev/null; then echo >regex_test.sh 'if [[ $# = 1 ]]; then -- cgit v1.2.3 From b870ff85a0bcda9d38a734aa86bb6aee3d76983e Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 16 Sep 2016 00:05:10 +0200 Subject: 39333: include name of command used to gain priviliges in context for command and gain-priviliges styles --- ChangeLog | 5 +++++ Completion/Base/Utility/_call_program | 9 ++++++--- Completion/Solaris/Command/_pfexec | 2 +- Completion/Unix/Command/_sudo | 5 +++-- Doc/Zsh/compsys.yo | 4 +++- 5 files changed, 18 insertions(+), 7 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f54d78ca3..0faf7b9ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2016-09-15 Oliver Kiddle + * 39333: Completion/Base/Utility/_call_program, + Doc/Zsh/compsys.yo, Completion/Solaris/Command/_pfexec, + Completion/Unix/Command/_sudo: include name of command used to + gain priviliges in context for command and gain-priviliges styles + * 39332: Doc/Zsh/cond.yo, Src/cond.c, Src/params.c, Src/parse.c, Completion/Zsh/Context/_condition, Test/C02cond.ztst: support ksh's [[ -v varname ]] condition for checking if variables are set diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program index 95c761e65..9a44f2d8e 100644 --- a/Completion/Base/Utility/_call_program +++ b/Completion/Base/Utility/_call_program @@ -1,12 +1,15 @@ #autoload +X -local tmp err_fd=-1 +local curcontext="${curcontext}" tmp err_fd=-1 local -a prefix if [[ "$1" = -p ]]; then shift - zstyle -t ":completion:${curcontext}:${1}" gain-privileges && - prefix=( $_comp_priv_prefix ) + if (( $#_comp_priv_prefix )); then + curcontext="${curcontext%:*}/${${(@M)_comp_priv_prefix:#^*[^\\]=*}[1]}:" + zstyle -t ":completion:${curcontext}:${1}" gain-privileges && + prefix=( $_comp_priv_prefix ) + fi fi if (( ${debug_fd:--1} > 2 )) || [[ ! -t 2 ]] diff --git a/Completion/Solaris/Command/_pfexec b/Completion/Solaris/Command/_pfexec index 3f1f3e733..2afaf317b 100644 --- a/Completion/Solaris/Command/_pfexec +++ b/Completion/Solaris/Command/_pfexec @@ -25,7 +25,7 @@ _pfexec() { _arguments \ '-P[privileges to acquire]:privspec:_privset' \ '(-):command name: _command_names -e' \ - '*::arguments:{ _comp_priv_prefix=( $words[1] ${(kv)opt_args[-P]} ) ; _normal }' + '*::arguments:{ _comp_priv_prefix=( pfexec ${(kv)opt_args[-P]} ) ; _normal }' } _pfexec "$@" diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo index 21b1ef4c6..0a212b723 100644 --- a/Completion/Unix/Command/_sudo +++ b/Completion/Unix/Command/_sudo @@ -2,7 +2,7 @@ setopt localoptions extended_glob -local environ e +local environ e cmd local -a args zstyle -a ":completion:${curcontext}:" environ environ @@ -39,6 +39,7 @@ args=( if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] )) ; then args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' ) else + cmd="$words[1]" args+=( '(-e --edit 1 *)'{-e,--edit}'[edit files instead of running a command]' \ '(-s --shell)'{-s,--shell}'[run shell as the target user; a command may also be specified]' \ @@ -48,7 +49,7 @@ else '(-H --set-home -i --login -s --shell -e --edit)'{-H,--set-home}"[set HOME variable to target user's home dir]" \ '(-P --preserve-groups -i -login -s --shell -e --edit)'{-P,--preserve-groups}"[preserve group vector instead of setting to target's]" \ '(-)1:command: _command_names -e' - '*::arguments:{ _comp_priv_prefix=( $words[1] -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }' + '*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }' ) fi diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index cab665b1c..260ace4ac 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4191,7 +4191,9 @@ output is influenced by the permissions it is run with. If the tt(gain-privileges) style is set to true, tt(_call_program) will make use of commands such as tt(sudo), if present on the command-line, to match the permissions to whatever the final command is likely to run -under. +under. When looking up the tt(gain-privileges) and tt(command) styles, +the command component of the zstyle context will end with a slash +(`tt(/)') followed by the command that would be used to gain privileges. ) findex(_combination) item(tt(_combination) [ tt(-s) var(pattern) ] var(tag) var(style) var(spec) ... var(field) var(opts) ...)( -- cgit v1.2.3 From 736eb433bae71a162f8b5adbd42710bb718a3c91 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 29 Sep 2016 14:55:49 -0700 Subject: 39507: TMPSUFFIX for =(...) --- ChangeLog | 2 ++ Doc/Zsh/params.yo | 9 +++++++++ Src/exec.c | 9 +++++++++ 3 files changed, 20 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f93bdb10a..3fe3165ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2016-09-29 Barton E. Schaefer + * 39507: Doc/Zsh/params.yo, Src/exec.c: TMPSUFFIX for =(...) + * 39470: Src/exec.c, Src/utils.c: failure to open a supposedly unique temp file name should result in an error; band-aid for signal-related race conditions in temp file name generation diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 03625ce24..c7d84b9a8 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1547,6 +1547,15 @@ A pathname prefix which the shell will use for all temporary files. Note that this should include an initial part for the file name as well as any directory names. The default is `tt(/tmp/zsh)'. ) +vindex(TMPSUFFIX) +item(tt(TMPSUFFIX))( +A filename suffix which the shell will use for temporary files created +by process substitutions (e.g., `tt(=LPAR()var(list)RPAR())'). +Note that the value should include a leading dot `tt(.)' if intended +to be interpreted as a file extension. The default is not to append +any suffix, thus this parameter should be assigned only when needed +and then unset again. +) vindex(watch) vindex(WATCH) item(tt(watch) (tt(WATCH) ))( diff --git a/Src/exec.c b/Src/exec.c index 04868bd37..e253d7b9e 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -4421,6 +4421,15 @@ getoutputfile(char *cmd, char **eptr) if (!s) child_unblock(); return NULL; + } else { + char *suffix = getsparam("TMPSUFFIX"); + if (suffix && *suffix && !strstr(suffix, "/")) { + suffix = dyncat(nam, unmeta(suffix)); + if (link(nam, suffix) == 0) { + addfilelist(nam, 0); + nam = ztrdup(suffix); + } + } } addfilelist(nam, 0); -- cgit v1.2.3 From 0a5bf8e767a9c9239824f98f39bb983c436a00d6 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Fri, 30 Sep 2016 15:57:15 -0700 Subject: unposted: update or remove references to typeset behavior obsoleted by 35586. --- ChangeLog | 3 +++ Doc/Zsh/builtins.yo | 12 ++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2ed7dcc22..d1a83b4ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-09-30 Barton E. Schaefer + * unposted: Doc/Zsh/builtins.yo: update or remove references to + typeset behavior obsoleted by 35586. + * 39509: Src/builtins.c: in the event the current directory has been removed, use chasedots semantics for "cd ..". diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index ac4441c64..dfbbaa034 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1918,11 +1918,6 @@ If the tt(-p) option is given, parameters and values are printed in the form of a typeset command with an assignment, regardless of other flags and options. Note that the tt(-H) flag on parameters is respected; no value will be shown for these parameters. - -As the intention of this option is to produce output that can restore -the current state, readonly specials (whose values cannot be -changed) are not shown and assignments to arrays are shown before -the tt(typeset) rendering the array readonly. ) item(tt(-T) [ var(scalar)[tt(=)var(value)] var(array)[tt(=LPAR())var(value) ...tt(RPAR())] [ var(sep) ] ])( This flag has a different meaning when used with tt(-f); see below. @@ -2019,9 +2014,10 @@ place in the output. ) item(tt(-a))( The names refer to array parameters. An array parameter may be -created this way, but it may not be assigned to in the tt(typeset) -statement. When displaying, both normal and associative arrays are -shown. +created this way, but it may be assigned to in the tt(typeset) +statement only if the reserved word form of tt(typeset) is enabled +(as it is by default). When displaying, both normal and associative +arrays are shown. ) item(tt(-f))( The names refer to functions rather than parameters. No assignments -- cgit v1.2.3 From 4f2a1810f2fa1d74008e03a09d66eaff3e5edc9e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 29 Sep 2016 09:50:09 +0000 Subject: 39495: add-zle-hook-widget: Add end-of-options guard to hook invocation. Currently, the only special widget that takes arguments is zle-keymap-select. --- ChangeLog | 3 +++ Doc/Zsh/contrib.yo | 2 +- Functions/Misc/add-zle-hook-widget | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 9df255631..b1b000025 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-09-30 Daniel Shahaf + * 39495: Doc/Zsh/contrib.yo, Functions/Misc/add-zle-hook-widget: + add-zle-hook-widget: Add end-of-options guard to hook invocation. + * 39480: Completion/Debian/Command/_bug: _reportbug: Complete absolute filenames, too. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 63df292ac..189a084ba 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -346,7 +346,7 @@ as the var(hook) argument. var(widgetname) is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. Note that the hooks are called as widgets, that is, with -example(tt(zle )var(widgetname)tt( -Nw "$@")) +example(tt(zle )var(widgetname)tt( -Nw -- "$@")) vindex(WIDGET, in hooks) Note that this means that the `tt(WIDGET)' special parameter tracks the diff --git a/Functions/Misc/add-zle-hook-widget b/Functions/Misc/add-zle-hook-widget index 572de2561..d8a3950fb 100644 --- a/Functions/Misc/add-zle-hook-widget +++ b/Functions/Misc/add-zle-hook-widget @@ -47,9 +47,9 @@ function azhw:${^hooktypes} { for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do if [[ "$hook" = user:* ]]; then # Preserve $WIDGET within the renamed widget - zle "$hook" -N "$@" + zle "$hook" -N -- "$@" else - zle "$hook" -Nw "$@" + zle "$hook" -Nw -- "$@" fi || return done return 0 -- cgit v1.2.3 From dc517212caf3a8263cea9587bc6e96f7ff129b59 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 5 Oct 2016 12:14:43 +0100 Subject: 39566: Improve usefulness of command_not_found_handler. Don't behave as if command not found if return status is non-zero as this may simply be the return status of the replacement command. Let the function report a command not found instead. --- Doc/Zsh/exec.yo | 15 ++++++++------- README | 9 +++++++++ Src/exec.c | 13 ++++++++----- Test/C04funcdef.ztst | 5 ++--- 4 files changed, 27 insertions(+), 15 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/exec.yo b/Doc/Zsh/exec.yo index 30e4a61a2..5f79967de 100644 --- a/Doc/Zsh/exec.yo +++ b/Doc/Zsh/exec.yo @@ -28,10 +28,11 @@ not handle this executable format in the kernel. If no external command is found but a function tt(command_not_found_handler) exists the shell executes this function with all -command line arguments. The function should return status zero if it -successfully handled the command, or non-zero status if it failed. -In the latter case the standard handling is applied: `command not -found' is printed to standard error and the shell exits with status 127. -Note that the handler is executed in a subshell forked to execute -an external command, hence changes to directories, shell parameters, -etc. have no effect on the main shell. +command line arguments. The return status of the function becomes the +status of the command. If the function wishes to mimic the +behaviour of the shell when the command is not found, it should +print the message `tt(command not found:) var(cmd)' to standard error +and return status 127. Note that the handler is executed in a +subshell forked to execute an external command, hence changes to +directories, shell parameters, etc. have no effect on the main shell. + diff --git a/README b/README index d146d4b16..ed2183d8d 100644 --- a/README +++ b/README @@ -101,6 +101,15 @@ For the more common case of non-repeatable options that take a single argument, completion functions now have to unescape not only colons but also backslashes when obtaining the option's argument from $opt_args. +6) Previously, if the function command_not_found_handler was run +in place of a command-not-found error, and the function returned +non-zero status, zsh set the status to 127 and printed an error message +anyway. Now, the status from the handler is retained and no additional +message is printed. The main reasons for this change are that it was not +possible to return a non-zero status to the parent shell from a command +executed as a replacement, and the new implementation is more consistent +with other shells. + Incompatibilities between 5.0.8 and 5.2 --------------------------------------- diff --git a/Src/exec.c b/Src/exec.c index 9890286b2..f248ca288 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -568,11 +568,14 @@ commandnotfound(char *arg0, LinkList args) Shfunc shf = (Shfunc) shfunctab->getnode(shfunctab, "command_not_found_handler"); - if (!shf) - return 127; + if (!shf) { + lastval = 127; + return 1; + } pushnode(args, arg0); - return doshfunc(shf, args, 1); + lastval = doshfunc(shf, args, 1); + return 0; } /* @@ -703,7 +706,7 @@ execute(LinkList args, int flags, int defpath) if (!search_defpath(arg0, pbuf, PATH_MAX)) { if (commandnotfound(arg0, args) == 0) - _exit(0); + _exit(lastval); zerr("command not found: %s", arg0); _exit(127); } @@ -767,7 +770,7 @@ execute(LinkList args, int flags, int defpath) if (eno) zerr("%e: %s", eno, arg0); else if (commandnotfound(arg0, args) == 0) - _exit(0); + _exit(lastval); else zerr("command not found: %s", arg0); _exit((eno == EACCES || eno == ENOEXEC) ? 126 : 127); diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 9f15e04ff..ab7b42928 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -120,14 +120,13 @@ print "Your command:" >&2 print "$1" >&2 print "has gone down the tubes. Sorry." >&2 - return 1 + return 42 } ThisCommandDoesNotExistEither -127:Command not found handler, failure +42:Command not found handler, failure ?Your command: ?ThisCommandDoesNotExistEither ?has gone down the tubes. Sorry. -?(eval):7: command not found: ThisCommandDoesNotExistEither local variable=outside print "I am $variable" -- cgit v1.2.3 From b4cc190db9a8419ca8c5a39ae45c95cb9db0ff84 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 Sep 2016 15:26:27 +0000 Subject: 39522: add-zsh-hook/add-zle-hook-widget: Promise append semantics. The sentence about "as widgets" is removed since there is a whole paragraph about that later on. --- ChangeLog | 3 +++ Doc/Zsh/contrib.yo | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 06efc60b2..a1699ac24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-10-07 Daniel Shahaf + * 39522: Doc/Zsh/contrib.yo: add-zsh-hook/add-zle-hook-widget: + Promise append semantics. + * 39489: Completion/Unix/Type/_path_files: Interpret -P as literally, rather than as a pattern. diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 189a084ba..653d1bc98 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -311,6 +311,7 @@ still be manipulated as a hook. var(function) is name of an ordinary shell function. If no options are given this will be added to the array of functions to be executed in the given context. +Functions are invoked in the order they were added. If the option tt(-L) is given, the current values for the hook arrays are listed with tt(typeset). @@ -345,7 +346,7 @@ as the var(hook) argument. var(widgetname) is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. -Note that the hooks are called as widgets, that is, with +Widgets are invoked in the order they were added, with example(tt(zle )var(widgetname)tt( -Nw -- "$@")) vindex(WIDGET, in hooks) -- cgit v1.2.3 From 13cfa036c8f9dd02688d3cb860abc75bcc64827d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 16 Oct 2016 17:14:48 +0000 Subject: 39657: Make a helper function global. --- ChangeLog | 6 ++++++ Completion/Zsh/Command/_zstyle | 16 ---------------- Completion/Zsh/Type/_completers | 14 ++++++++++++++ Doc/Zsh/compsys.yo | 10 ++++++++++ 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 Completion/Zsh/Type/_completers (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2d638dfdb..9e1beba1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-10-18 Daniel Shahaf + + * 39657: Completion/Zsh/Command/_zstyle, + Completion/Zsh/Type/_completers, Doc/Zsh/compsys.yo: Make a + helper function global. + 2016-10-16 Daniel Shahaf * 39500: Src/Zle/computil.c: compdescribe: perform diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 20ff47f87..dcebc6faf 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -4,22 +4,6 @@ local state context ostate line expl ctop suf local nm=$compstate[nmatches] taglist patterns pstyles contexts typeset -A opt_args styles -(( $+functions[_completers] )) || -_completers() { - # option: -p - needs a `_' prefix - local us - local -a disp list expl - - list=( complete approximate correct match expand list menu oldlist - ignored prefix history ) - zparseopts -D -K -E 'p=us' - [[ -n "$us" ]] && us='_' - zstyle -t ":completion:${curcontext}:completers" prefix-hidden && - disp=(-d list) - _wanted completers expl 'completer' \ - compadd "$@" "$disp[@]" - "$us${^list[@]}" -} - _vcs_info_hooks() { compadd - ${functions[(I)+vi-*]#+vi-} } diff --git a/Completion/Zsh/Type/_completers b/Completion/Zsh/Type/_completers new file mode 100644 index 000000000..87c986a17 --- /dev/null +++ b/Completion/Zsh/Type/_completers @@ -0,0 +1,14 @@ +#autoload + +# option: -p - needs a `_' prefix +local us +local -a disp list expl + +list=( complete approximate correct match expand list menu oldlist + ignored prefix history ) +zparseopts -D -K -E 'p=us' +[[ -n "$us" ]] && us='_' +zstyle -t ":completion:${curcontext}:completers" prefix-hidden && + disp=(-d list) +_wanted completers expl 'completer' \ + compadd "$@" "$disp[@]" - "$us${^list[@]}" diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 260ace4ac..a56ca6721 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4246,6 +4246,16 @@ This function completes words that are valid at command position: names of aliases, builtins, hashed commands, functions, and so on. With the tt(-e) flag, only hashed commands are completed. The tt(-) flag is ignored. ) +findex(_completers) +item(tt(_completers) [ tt(-p) ])( +This function completes names of completers. + +startitem() +item(tt(-p))( +Include the leading underscore (`tt(_)') in the matches. +) +enditem() +) findex(_describe) redef(SPACES)(0)(tt(ifztexi(NOTRANS(@ @ @ @ @ @ @ @ @ @ ))ifnztexi( ))) xitem(tt(_describe )[tt(-12JVx)] [ tt(-oO) | tt(-t) var(tag) ] var(descr) var(name1) [ var(name2) ] [ var(opt) ... ]) -- cgit v1.2.3 From f1c0480afc49ce2accc70c69cf0aa3a975c1563c Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Oct 2016 21:54:05 +0000 Subject: 39707: Document _dir_list. --- ChangeLog | 4 ++++ Doc/Zsh/compsys.yo | 15 +++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index f63ffa6fa..0fac01a90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-10-24 Daniel Shahaf + + * 39707: Doc/Zsh/compsys.yo: Document _dir_list. + 2016-10-23 Peter Stephenson * 39715: Src/Zle/complist.c: handle multibyte characters when diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index a56ca6721..f56daa459 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4357,6 +4357,21 @@ matches. Almost all calls to tt(compadd) within the completion system use a similar format; this ensures that user-specified styles are correctly passed down to the builtins which implement the internals of completion. ) +findex(_dir_list) +item(tt(_dir_list) [ tt(-s) var(sep) ] [ tt(-S) ])( +Complete a list of directory names separated by colons +(the same format as tt($PATH)). + +startitem() +item(tt(-s) var(sep))( +Use var(sep) as separator between items. +var(sep) defaults to a colon (`tt(:)'). +) +item(tt(-S))( +Add var(sep) instead of slash (`tt(/)') as an autoremoveable suffix. +) +enditem() +) findex(_dispatch) item(tt(_dispatch) var(context string) ...)( This sets the current context to var(context) and looks for completion -- cgit v1.2.3 From 4eef3e6f0e2f7e258c961b30cef7f4d463fb8b2f Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Oct 2016 21:54:06 +0000 Subject: 39708: Document _email_addresses. --- ChangeLog | 3 +++ Completion/Unix/Type/_email_addresses | 2 ++ Doc/Zsh/compsys.yo | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 0fac01a90..7debe2d83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-10-24 Daniel Shahaf + * 39708: Completion/Unix/Type/_email_addresses, + Doc/Zsh/compsys.yo: Document _email_addresses. + * 39707: Doc/Zsh/compsys.yo: Document _dir_list. 2016-10-23 Peter Stephenson diff --git a/Completion/Unix/Type/_email_addresses b/Completion/Unix/Type/_email_addresses index 7d5c942de..8a5877a9c 100644 --- a/Completion/Unix/Type/_email_addresses +++ b/Completion/Unix/Type/_email_addresses @@ -5,6 +5,8 @@ # -s sep - complete a list of addresses separated by specified character # -c - e-mail address must be of form user@host (no comments or aliases) # +# TODO: with -n, have the named plugin complete not only aliases but also addresses? +# # Plugins are written as separate functions with names starting `_email-'. # They should either do their own completion or return the addresses in the # reply array in the form 'alias:address' and return 300. The -c option is diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index f56daa459..33ba92c16 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -826,6 +826,10 @@ kindex(domains, completion tag) item(tt(domains))( for network domains ) +kindex(email-*, completion tag) +item(tt(email-)var(plugin))( +for email addresses from the `tt(_email-)var(plugin)' backend of tt(_email_addresses) +) kindex(expansions, completion tag) item(tt(expansions))( used by the tt(_expand) completer for individual words (as opposed to @@ -4387,6 +4391,44 @@ tt($service) to the var(string) being tried, and sets the var(context/command) field (the fourth) of the tt($curcontext) parameter to the var(context) given as the first argument. ) +findex(_email_addresses) +item(tt(_email_addresses) [ tt(-c) ] [ tt(-n) var(plugin) ])( +Complete email addresses. Addresses are provided by plugins. + +startitem() +item(tt(-c))( +Complete bare tt(localhost@domain.tld) addresses, without a name part or +a comment. +Without this option, RFC822 `var(Firstname Lastname) tt(<)var(address)tt(>)' +strings are completed. +) +item(tt(-n) var(plugin))( +Complete aliases from var(plugin). +) +COMMENT(Intentionally leaving tt(-s) undocumented: new code should use +tt(_sequence) instead.)\ +enditem() + +The following plugins are available by default: +tt(_email-ldap) (see the tt(filter) style), +tt(_email-local) (completes var(user)tt(@)var(hostname) Unix addresses), +tt(_email-mail) (completes aliases from tt(~/.mailrc)), +tt(_email-mush), +tt(_email-mutt), +and +tt(_email-pine). + +Addresses from the tt(_email-)var(foo) plugin are added under the +tag `tt(email-)var(foo)'. + +em(Writing plugins) + +Plugins are written as separate functions with names starting with `tt(_email-)'. +They are invoked with the tt(-c) option and tt(compadd) options. +They should either do their own completion or +set the tt($reply) array to a list of `var(alias)tt(:)var(address)' elements and return tt(300). +New plugins will be picked up and run automatically. +) findex(_files) item(tt(_files))( The function tt(_files) calls tt(_path_files) with all the arguments it -- cgit v1.2.3 From 71dd0ab62ecf67e3a4a60749e9f5b1cfc9ac0ec4 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 22 Oct 2016 21:54:07 +0000 Subject: 39706: _tilde_files: Offer named directories. Document. --- ChangeLog | 3 +++ Completion/Unix/Type/_tilde_files | 3 ++- Doc/Zsh/compsys.yo | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 7debe2d83..717f25e76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-10-24 Daniel Shahaf + * 39706: Completion/Unix/Type/_tilde_files, Doc/Zsh/compsys.yo: + _tilde_files: Offer named directories. Document. + * 39708: Completion/Unix/Type/_email_addresses, Doc/Zsh/compsys.yo: Document _email_addresses. diff --git a/Completion/Unix/Type/_tilde_files b/Completion/Unix/Type/_tilde_files index ee6b18088..b1b3b37f0 100644 --- a/Completion/Unix/Type/_tilde_files +++ b/Completion/Unix/Type/_tilde_files @@ -30,7 +30,8 @@ case "$PREFIX" in ;; \~*) compset -P '?' - _users "$@" + local -a expl=( "$@" ) + _alternative -O expl users:user:_users named-directories:'named directory':'compadd -k nameddirs' ;; *) _files "$@" diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 33ba92c16..42482760b 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -5019,6 +5019,12 @@ allows tt(_tags) to use a more specific context without having to change and reset the tt(curcontext) parameter (which has the same effect). ) +findex(_tilde_files) +item(tt(_tilde_files))( +Like tt(_files), but resolve leading tildes according to the rules of +filename expansion, so the suggested completions don't start with +a `tt(~)' even if the filename on the command-line does. +) findex(_values) item(tt(_values) [ tt(-O) var(name) ] [ tt(-s) var(sep) ] [ tt(-S) var(sep) ] [ tt(-wC) ] var(desc) var(spec) ...)( This is used to complete arbitrary keywords (values) and their arguments, -- cgit v1.2.3 From 5dbfbd8bd016832c46c63b095cb60d043b37d379 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 21 Sep 2016 03:54:41 +0000 Subject: unposted: Minor documentation fixes (markup, grammar, etc). --- ChangeLog | 3 +++ Doc/Zsh/compsys.yo | 7 ++++--- Doc/Zsh/contrib.yo | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 0592589fc..5caf8735f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-10-27 Daniel Shahaf + * unposted: Doc/Zsh/compsys.yo, Doc/Zsh/contrib.yo: Minor + documentation fixes (markup, grammar, etc). + * 39739: Completion/Unix/Command/_head, Completion/Unix/Command/_tail: Complete negative integers for -n/-c in the GNU variant. (after 39479) diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 42482760b..ceb98c7bc 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1115,14 +1115,14 @@ tt(default) tag. The most notable styles of this type are tt(menu), tt(list-colors) and styles controlling completion listing such as tt(list-packed) and tt(last-prompt). When tested for the tt(default) tag, only the var(function) field of the context will be set so that -a style using the default tag will normally be defined along the lines of: +a style using the tt(default) tag will normally be defined along the lines of: example(zstyle ':completion:*:default' menu ...) startitem() kindex(accept-exact, completion style) item(tt(accept-exact))( -This is tested for the default tag in addition to the tags valid for +This is tested for the tt(default) tag in addition to the tags valid for the current context. If it is set to `true' and any of the trial matches is the same as the string on the command line, this match will immediately be accepted (even if it would otherwise be considered @@ -3252,6 +3252,7 @@ for the current context; remember that the context for completers is less specific than that for contextual completion as the full context has not yet been determined. Elements of the array may have one of the following forms: + startsitem() sitem(tt($)var(hash))( var(hash) is the name of an associative array. Note this is not a full @@ -5013,7 +5014,7 @@ particular tag is to be tried, the tt(_requested) function should be called (see above). If `tt(-C) var(name)' is given, var(name) is temporarily stored in the -argument field (the fifth) of the context in the tt(curcontext) parameter +var(argument) field (the fifth) of the context in the tt(curcontext) parameter during the call to tt(_tags); the field is restored on exit. This allows tt(_tags) to use a more specific context without having to change and reset the diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 653d1bc98..623507283 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1051,7 +1051,7 @@ tt(:vcs_info:-init-:*:-all-) context. Say, tt(~/.zsh) is a directory under version control, in which you do not want tt(vcs_info) to be active, do: -example(zstyle ':vcs_info:*' disable-patterns "$HOME/.zsh+LPAR()|/*+RPAR()") +example(zstyle ':vcs_info:*' disable-patterns "${+LPAR()b+RPAR()HOME}/.zsh+LPAR()|/*+RPAR()") ) kindex(use-quilt) item(tt(use-quilt))( @@ -1070,7 +1070,7 @@ tt(Quilt Support) for details. ) kindex(quiltcommand) item(tt(quiltcommand))( -When tt(quilt) itself is called in quilt support the value of this style +When tt(quilt) itself is called in quilt support, the value of this style is used as the command name. ) kindex(check-for-changes) -- cgit v1.2.3 From 3881c6b9a4b5bb7863090c2650ce404def657886 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 27 Oct 2016 12:59:07 +0000 Subject: users/22036: bracketed-paste: Document cutbuffer behaviour; clarify. --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 5caf8735f..45ab87de5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-10-28 Daniel Shahaf + + * users/22036: Doc/Zsh/zle.yo: bracketed-paste: Document + cutbuffer behaviour; clarify. + 2016-10-27 Daniel Shahaf * unposted: Doc/Zsh/compsys.yo, Doc/Zsh/contrib.yo: Minor diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 0102cb0e6..64bfcc2d3 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2175,10 +2175,13 @@ item(tt(bracketed-paste))( This widget is invoked when text is pasted to the terminal emulator. It is not intended to be bound to actual keys but instead to the special sequence generated by the terminal emulator when text is pasted. +The pasted text is inserted to the buffer and placed in the cutbuffer. If a numeric argument is given, shell quoting will be applied to the -pasted text before it is inserted. When called from a widget function, -an argument can be given to specify a variable to which pasted text is -assigned. +pasted text before it is inserted. + +When called from a widget function as `tt(bracketed-paste) var(name)`, the +pasted text is assigned to the variable var(name) and no other processing is +done. See also the tt(zle_bracketed_paste) parameter. ) -- cgit v1.2.3 From 0e9faf67aa44e5de814d25925320d9e7dcfdaf09 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 1 Nov 2016 17:03:28 +0000 Subject: users/22063: bracketed-paste: Document ability to specify a vi register. (after users/22036) --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 659b4d1a9..4a08d2664 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-03 Daniel Shahaf + + * users/22063: Doc/Zsh/zle.yo: bracketed-paste: Document ability + to specify a vi register. (after users/22036) + 2016-11-03 Daniel Hahler * 39822: Completion/Unix/Command/_git: remove "-A '-*'" with _arguments for some commands. diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 64bfcc2d3..63f673ba3 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2175,9 +2175,12 @@ item(tt(bracketed-paste))( This widget is invoked when text is pasted to the terminal emulator. It is not intended to be bound to actual keys but instead to the special sequence generated by the terminal emulator when text is pasted. -The pasted text is inserted to the buffer and placed in the cutbuffer. + +When invoked interactively, the pasted text is inserted to the buffer. If a numeric argument is given, shell quoting will be applied to the pasted text before it is inserted. +The text is also placed in the cutbuffer, or in the specified register +(tt("x) in vi mode). When called from a widget function as `tt(bracketed-paste) var(name)`, the pasted text is assigned to the variable var(name) and no other processing is -- cgit v1.2.3 From fe023d8bac1912e96a4d982ba84a0621fde616d2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 3 Nov 2016 19:45:33 +0000 Subject: users/22080: bracketed-paste: Third time's a charm. vi-set-buffer: Eliminate the sole use of the term "register". --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 1b1ecd75d..d1ac1cd45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-04 Daniel Shahaf + + * users/22080: Doc/Zsh/zle.yo: bracketed-paste: Third time's + a charm. + 2016-11-04 Peter Stephenson * Sebastian: 39825: Src/utils.c: Optimise mb_metastrlenend() for diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 63f673ba3..b7bb23bbc 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2176,11 +2176,13 @@ This widget is invoked when text is pasted to the terminal emulator. It is not intended to be bound to actual keys but instead to the special sequence generated by the terminal emulator when text is pasted. -When invoked interactively, the pasted text is inserted to the buffer. +When invoked interactively, the pasted text is inserted to the buffer +and placed in the cutbuffer. If a numeric argument is given, shell quoting will be applied to the pasted text before it is inserted. -The text is also placed in the cutbuffer, or in the specified register -(tt("x) in vi mode). + +When a named buffer is specified with tt(vi-set-buffer) (tt("x)), +the pasted text is stored in that named buffer but not inserted. When called from a widget function as `tt(bracketed-paste) var(name)`, the pasted text is assigned to the variable var(name) and no other processing is @@ -2410,7 +2412,7 @@ concerned replaces the previous contents of the specified buffer. If a named buffer is specified using a capital, the newly cut text is appended to the buffer instead of overwriting it. When using the tt("_) buffer, nothing happens. This can be useful for deleting text without -affecting the normal registers. +affecting any buffers. If no buffer is specified for a cut or change command, tt("1) is used, and the contents of tt("1) to tt("8) are each shifted along one buffer; -- cgit v1.2.3 From 4b41e33cbcf8027b53ecae4467dc9232becb0420 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 5 Nov 2016 00:27:47 +0100 Subject: 39389: when printf -v is used with an array use separate elements each time the format is reused --- ChangeLog | 7 ++++++ Completion/Zsh/Command/_print | 17 +++++++++----- Completion/Zsh/Type/_globquals | 3 +-- Doc/Zsh/builtins.yo | 4 +++- Src/builtin.c | 51 +++++++++++++++++++++++++++++++----------- Test/B03print.ztst | 6 +++++ 6 files changed, 66 insertions(+), 22 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index d1ac1cd45..1ebcc3725 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-11-04 Oliver Kiddle + + * 39389: Src/builtin.c, Test/B03print.ztst, Doc/Zsh/builtins.yo, + Completion/Zsh/Type/_globquals, Completion/Zsh/Command/_print: + when printf -v is used with an array use separate elements each + time the format is reused + 2016-11-04 Daniel Shahaf * users/22080: Doc/Zsh/zle.yo: bracketed-paste: Third time's diff --git a/Completion/Zsh/Command/_print b/Completion/Zsh/Command/_print index 38f17ab8e..8df094107 100644 --- a/Completion/Zsh/Command/_print +++ b/Completion/Zsh/Command/_print @@ -1,15 +1,18 @@ #compdef print printf -local state expl line eflag pflag rest ret=1 +local state expl line eflag pflag rflag rest ret=1 if [[ $service = print ]]; then # -e flag available only after -R eflag="${words[1,CURRENT-1][(r)-*R*]:+-e[enable escapes]}" + rflag='-r[ignore escape conventions of echo]' # -p flag only relevant if we have a coprocess (:>&p) 2>/dev/null && pflag='(-s -u -z)-p[print arguments to input of coprocess]' + [[ -n ${words[(r)-*f]} ]] && rflag='-r[disable reuse of format string]' + if [[ -n ${words[1,CURRENT][(r)-*P*]} ]]; then rest='*: :->prompt' else @@ -17,11 +20,11 @@ if [[ $service = print ]]; then fi _arguments -C -s -A "-*" -S \ - '(-f)-r[ignore escape conventions of echo]' \ + '-r[ignore escape conventions of echo]' \ '(-r -b -f -m -s -l -N -o -O -i -c -u -p -z -D -P)-R[emulate BSD echo (no escapes, -n & -e flags only)]' \ '-b[recognise bindkey escape sequences]' \ - '-m[remove arguments matching specified pattern]' \ - '(-r -n -R -l -N -c)-f+[print arguments as for the printf builtin]:format:->printfformat' \ + '-m[remove arguments not matching specified pattern]:pattern' \ + '(-n -R -l -N -c)-f+[print arguments as for the printf builtin]:format:->printfformat' \ '(-u -p -z)-s[place results in the history list]' \ '(-c -f)-n[do not add a newline to the result]' \ '(-N -c -f)-l[print arguments separated by newlines]' \ @@ -33,11 +36,13 @@ if [[ $service = print ]]; then '(-n -l -N -f -C -s -z)-c[print arguments in columns]' \ '(-n -l -N -f -c -s -z)-C+[print arguments in specified number of columns]:columns' \ '(-s -p -z)-u+[specify file descriptor to print arguments to]:file descriptor:_file_descriptors' \ - '-v[store output in named parameter]:parameter:_parameters' \ + '(-s -z -p -u)-v[store output in named parameter]:parameter:_parameters' \ '(-s -p -u)-z[push arguments onto editing buffer stack]' \ '-D[substitute any arguments which are named directories using ~ notation]' \ '-P[perform prompt expansion]' \ - $pflag $eflag $rest && ret=0 + '(-X -f -a -C -c -z)-x+[expand leading tabs]:tab width' \ + '(-x -f -a -C -c -z)-X+[expand all tabs]:tab width' \ + $pflag $eflag $rflag $rest && ret=0 elif [[ $service = printf ]]; then state=printf fi diff --git a/Completion/Zsh/Type/_globquals b/Completion/Zsh/Type/_globquals index 6eef16877..a904bdf0d 100644 --- a/Completion/Zsh/Type/_globquals +++ b/Completion/Zsh/Type/_globquals @@ -121,8 +121,7 @@ while [[ -n $PREFIX ]]; do tmatch=( s m h d w M ) if zstyle -t ":completion:${curcontext}:time-specifiers" verbose; then zstyle -s ":completion:${curcontext}:time-specifiers" list-separator sep || sep=-- - print -v tdisp -f "%s ${sep//(#m)[%\\]/$MATCH$MATCH} %s\0" ${tmatch:^^tdisp} - tdisp=( ${(0)tdisp} ) + print -v tdisp -f "%s ${sep//(#m)[%\\]/$MATCH$MATCH} %s" ${tmatch:^^tdisp} fi alts+=( "time-specifiers:time specifier:compadd -E 0 -d tdisp -S '' -a tmatch" ) fi diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index dfbbaa034..169a31ea3 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1289,7 +1289,9 @@ required by the format than have been specified, the behaviour is as if zero or an empty string had been specified as the argument. The tt(-v) option causes the output to be stored as the value of the -parameter var(name), instead of printed. +parameter var(name), instead of printed. If var(name) is an array and +the format string is reused when consuming arguments then one +array element will be used for each use of the format string. ) findex(pushd) pindex(PUSHD_TO_HOME, use of) diff --git a/Src/builtin.c b/Src/builtin.c index 986ace238..083a3aeb3 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4087,10 +4087,11 @@ bin_print(char *name, char **args, Options ops, int func) { int flen, width, prec, type, argc, n, narg, curlen = 0; int nnl = 0, fmttrunc = 0, ret = 0, maxarg = 0, nc = 0; - int flags[6], *len; + int flags[6], *len, visarr = 0; char *start, *endptr, *c, *d, *flag, *buf = NULL, spec[14], *fmt = NULL; char **first, **argp, *curarg, *flagch = "'0+- #", save = '\0', nullstr = '\0'; size_t rcount = 0, count = 0; + size_t *cursplit, *splits = 0; FILE *fout = stdout; #ifdef HAVE_OPEN_MEMSTREAM size_t mcount; @@ -4122,7 +4123,7 @@ bin_print(char *name, char **args, Options ops, int func) return 1; \ } \ unlink(tmpf); \ - if ((fout = fdopen(tempfd, "w+")) == NULL) { \ + if ((FOUT = fdopen(tempfd, "w+")) == NULL) { \ close(tempfd); \ zwarnnam(name, "can't open temp file: %e", errno); \ return 1; \ @@ -4647,11 +4648,23 @@ bin_print(char *name, char **args, Options ops, int func) * special cases of printing to a ZLE buffer or the history, however. */ + if (OPT_ISSET(ops,'v')) { + struct value vbuf; + char* s = OPT_ARG(ops,'v'); + Value v = getvalue(&vbuf, &s, 0); + visarr = v && PM_TYPE(v->pm->node.flags) == PM_ARRAY; + } /* printf style output */ *spec = '%'; argp = args; do { rcount = count; + if (argp > args && visarr) { /* reusing format string */ + if (!splits) + cursplit = splits = (size_t *)zhalloc(sizeof(size_t) * + (arrlen(args) / (argp - args) + 1)); + *cursplit++ = count; + } if (maxarg) { first += maxarg; argc -= maxarg; @@ -5019,18 +5032,30 @@ bin_print(char *name, char **args, Options ops, int func) if (buf) free(buf); } else { - stringval = metafy(buf, rcount, META_REALLOC); - if (OPT_ISSET(ops,'z')) { - zpushnode(bufstack, stringval); - } else if (OPT_ISSET(ops,'v')) { - setsparam(OPT_ARG(ops, 'v'), stringval); + if (visarr) { + char **arrayval = zshcalloc((cursplit - splits + 2) * sizeof(char *)); + for (;cursplit >= splits; cursplit--) { + int start = cursplit == splits ? 0 : cursplit[-1]; + arrayval[cursplit - splits] = + metafy(buf + start, count - start, META_DUP); + count = start; + } + setaparam(OPT_ARG(ops, 'v'), arrayval); + free(buf); } else { - ent = prepnexthistent(); - ent->node.nam = stringval; - ent->stim = ent->ftim = time(NULL); - ent->node.flags = 0; - ent->words = (short *)NULL; - addhistnode(histtab, ent->node.nam, ent); + stringval = metafy(buf, rcount, META_REALLOC); + if (OPT_ISSET(ops,'z')) { + zpushnode(bufstack, stringval); + } else if (OPT_ISSET(ops,'v')) { + setsparam(OPT_ARG(ops, 'v'), stringval); + } else { + ent = prepnexthistent(); + ent->node.nam = stringval; + ent->stim = ent->ftim = time(NULL); + ent->node.flags = 0; + ent->words = (short *)NULL; + addhistnode(histtab, ent->node.nam, ent); + } } } unqueue_signals(); diff --git a/Test/B03print.ztst b/Test/B03print.ztst index a4431cbc8..6ee2a09c6 100644 --- a/Test/B03print.ztst +++ b/Test/B03print.ztst @@ -310,3 +310,9 @@ 0:print and printf into a variable >typeset -g foo='once more' >typeset -g foo=$'into\C-@the-breach\C-@-' + + typeset -a foo + print -f '%2$d %4s' -v foo one 1 two 2 three 3 + typeset -p foo +0:printf into an array variable +>typeset -a foo=( '1 one' '2 two' '3 three' ) -- cgit v1.2.3 From 33b34890922b4f8ba47b68692d155611c0fc0f67 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 7 Nov 2016 10:04:14 +0000 Subject: zsh-users/22083: attempt to explain what a word is in parameter substitution. --- ChangeLog | 5 +++++ Doc/Zsh/expn.yo | 12 ++++++++++++ 2 files changed, 17 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index a3a8c00fa..c31db78a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-07 Peter Stephenson + + * zsh-users/22083: Doc/Zsh/expn.yo: attempt to explain a bit + better what a "word" is in parameter substitution. + 2016-11-07 Daniel Shahaf * 39840: Completion/Unix/Command/_cpio: Declare variable's diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index b73151698..f465b2f60 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -572,6 +572,18 @@ noderef(Modifiers) in noderef(History Expansion) can be applied: for example, tt(${i:s/foo/bar/}) performs string substitution on the expansion of parameter tt($i). +In the following descriptions, `word' refers to a single word +substituted on the command line, not necessarily a space delimited word. +With default options, after the assignments: + +example(array=("first word" "second word") +scalar="only word") + +then tt($array) substitutes two words, `tt(first word)' and `tt(second +word)', and tt($scalar) substitutes a single word `tt(only word)'. This +may be modified by explicit or implicit word-splitting, however. The +full rules are complicated and are noted at the end. + startitem() item(tt(${)var(name)tt(}))( The value, if any, of the parameter var(name) is substituted. -- cgit v1.2.3 From dae3116026529790588295241b5a7e57fa96b200 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Wed, 9 Nov 2016 07:50:06 -0800 Subject: 39882: mention ${name:/pattern/replacement} in the itemized synopsis with the related forms; clarify doc. --- ChangeLog | 5 +++++ Doc/Zsh/expn.yo | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 320ee3fca..9a223e1f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-09 Barton E. Schaefer + + * 39882: Doc/Zsh/expn.yo: mention ${name:/pattern/replacement} + in the itemized synopsis with the related forms; clarify doc. + 2016-11-09 Peter Stephenson * 39887: Src/params.c: no need to conditionalise assignment of diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index f465b2f60..87ca7905d 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -782,12 +782,14 @@ prepending tt($0). Hence tt(${*:0:1}) substitutes tt($0) and tt(${*:1:1}) substitutes tt($1). ) xitem(tt(${)var(name)tt(/)var(pattern)tt(/)var(repl)tt(})) -item(tt(${)var(name)tt(//)var(pattern)tt(/)var(repl)tt(}))( +xitem(tt(${)var(name)tt(//)var(pattern)tt(/)var(repl)tt(})) +item(tt(${)var(name)tt(:/)var(pattern)tt(/)var(repl)tt(}))( Replace the longest possible match of var(pattern) in the expansion of parameter var(name) by string var(repl). The first form -replaces just the first occurrence, the second form all occurrences. +replaces just the first occurrence, the second form all occurrences, +and the third form replaces only if var(pattern) matches the entire string. Both var(pattern) and var(repl) are subject to double-quoted substitution, -so that expressions like tt(${name/$opat/$npat}) will work, but note the +so that expressions like tt(${name/$opat/$npat}) will work, but obey the usual rule that pattern characters in tt($opat) are not treated specially unless either the option tt(GLOB_SUBST) is set, or tt($opat) is instead substituted as tt(${~opat}). @@ -803,8 +805,8 @@ single backslash; this is not necessary if the `tt(%)' and `tt(#%) are not active if they occur inside a substituted parameter, even at the start. -The first `tt(/)' may be preceded by a `tt(:)', in which case the match -will only succeed if it matches the entire word. Note also the +If, after quoting rules apply, tt(${)var(name)tt(}) expands to an array, +the replacements act on each element individually. Note also the effect of the tt(I) and tt(S) parameter expansion flags below; however, the flags tt(M), tt(R), tt(B), tt(E) and tt(N) are not useful. -- cgit v1.2.3 From 33052104e11b04ac57ff02cee1f5bb1ef0289641 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 13 Nov 2016 11:00:16 -0800 Subject: 39929: clarify execute{,-last}-named-cmd --- ChangeLog | 4 ++++ Doc/Zsh/zle.yo | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 686bf41cc..e8740b8c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-11-13 Barton E. Schaefer + + * 39929: Doc/Zsh/zle.yo: clarify execute{,-last}-named-cmd + 2016-11-12 Barton E. Schaefer * unposted: Etc/zsh-development-guide: add list of standard diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index b7bb23bbc..21681e5e7 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -2224,8 +2224,12 @@ point and mark are not swapped. ) tindex(execute-named-cmd) item(tt(execute-named-cmd) (tt(ESC-x)) (tt(:)) (unbound))( -Read the name of an editor command and -execute it. A restricted set of editing functions is available in the +Read the name of an editor command and execute it. Aliasing this +widget with `tt(zle -A)' or replacing it with `tt(zle -N)' has no +effect when interpreting key bindings, but `tt(zle execute-named-cmd)' +will invoke such an alias or replacement. + +A restricted set of editing functions is available in the mini-buffer. Keys are looked up in the special tt(command) keymap, and if not found there in the main keymap. An interrupt signal, as defined by the stty setting, will @@ -2266,7 +2270,8 @@ tindex(execute-last-named-cmd) item(tt(execute-last-named-cmd) (tt(ESC-z)) (unbound) (unbound))( Redo the last function executed with tt(execute-named-cmd). -Currently this command may not be redefined or called by name. +Like tt(execute-named-cmd), this command may not be redefined, +but it may be called by name. ) tindex(get-line) item(tt(get-line) (tt(ESC-G ESC-g)) (unbound) (unbound))( -- cgit v1.2.3 From 6d991ce177d8821592b27158d4a96343a63e6745 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 17 Nov 2016 12:27:52 +0100 Subject: 39952: add registers special parameter to provide access to the vi register buffers from a zle widget function --- ChangeLog | 6 ++++ Doc/Zsh/zle.yo | 6 ++++ Src/Zle/zle_params.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index cdc89a86d..973414520 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-11-17 Oliver Kiddle + + * 39952: Src/Zle/zle_params.c, Doc/Zsh/zle.yo: add registers + special parameter to provide access to the vi register + buffers from a zle widget function + 2016-11-16 Oliver Kiddle * 39945: Src/Zle/compcore.c, Completion/Base/Core/_message, diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 21681e5e7..fe6a7e93b 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -991,6 +991,12 @@ and tt(zle_highlight); see ifzman(the section CHARACTER HIGHLIGHTING below)\ ifnzman(noderef(Character Highlighting)) for details. ) +vindex(registers) +item(tt(registers) (associative array))( +The contents of each of the `named' vi register buffers. These are +typically set using tt(vi-set-buffer) followed by a delete, change or +yank command. +) vindex(SUFFIX_ACTIVE) vindex(SUFFIX_START) vindex(SUFFIX_END) diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index c6387bfc7..2400bfb00 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -118,6 +118,12 @@ static const struct gsu_integer suffixactive_gsu = static const struct gsu_array killring_gsu = { get_killring, set_killring, unset_killring }; + +static const struct gsu_scalar register_gsu = +{ strgetfn, set_register, unset_register }; +static const struct gsu_hash registers_gsu = +{ hashgetfn, set_registers, zleunsetfn }; + /* implementation is in zle_refresh.c */ static const struct gsu_array region_highlight_gsu = { get_region_highlight, set_region_highlight, unset_region_highlight }; @@ -181,6 +187,7 @@ mod_export void makezleparams(int ro) { struct zleparam *zp; + Param reg_param; for(zp = zleparams; zp->name; zp++) { Param pm = createparam(zp->name, (zp->type |PM_SPECIAL|PM_REMOVABLE| @@ -206,6 +213,11 @@ makezleparams(int ro) if ((zp->type & PM_UNSET) && (zmod.flags & (MOD_MULT|MOD_TMULT))) pm->node.flags &= ~PM_UNSET; } + + reg_param = createspecialhash("registers", get_registers, &scan_registers, + PM_LOCAL|PM_REMOVABLE); + reg_param->gsu.h = ®isters_gsu; + reg_param->level = locallevel + 1; } /* Special unset function for ZLE special parameters: act like the standard * @@ -712,6 +724,93 @@ unset_killring(Param pm, int exp) } } +/**/ +static void +set_register(Param pm, char *value) +{ + int n = 0; + + if (!pm->node.nam || *pm->node.nam < 'a' || *pm->node.nam > 'z' || + pm->node.nam[1]) { + zerr("invalid zle register: %s", pm->node.nam); + return; + } + + Cutbuffer reg = &vibuf[*pm->node.nam - 'a']; + if (*value) + reg->buf = stringaszleline(value, 0, &n, NULL, NULL); + reg->len = n; +} + +/**/ +static void +unset_register(Param pm, UNUSED(int exp)) +{ + set_register(pm, ""); +} + +/**/ +static void +scan_registers(UNUSED(HashTable ht), ScanFunc func, int flags) +{ + int i; + struct param pm; + + memset((void *)&pm, 0, sizeof(struct param)); + pm.node.flags = PM_SCALAR | PM_READONLY; + pm.gsu.s = &nullsetscalar_gsu; + + for (i = 0; i < 26; i++) { + pm.node.nam = zhalloc(2); + *pm.node.nam = 'a' + i; + pm.node.nam[1] = '\0'; + pm.u.str = zlelineasstring(vibuf[i].buf, vibuf[i].len, 0, NULL, NULL, 1); + func(&pm.node, flags); + } +} + +/**/ +static HashNode +get_registers(UNUSED(HashTable ht), const char *name) +{ + Param pm = (Param) hcalloc(sizeof(struct param)); + pm->node.nam = dupstring(name); + pm->node.flags = PM_SCALAR; + pm->gsu.s = ®ister_gsu; + + if (*name < 'a' || *name > 'z' || name[1]) { + pm->u.str = dupstring(""); + pm->node.flags |= (PM_UNSET|PM_SPECIAL); + } else { + int reg = *name - 'a'; + pm->u.str = zlelineasstring(vibuf[reg].buf, vibuf[reg].len, 0, NULL, NULL, 1); + } + return &pm->node; +} + +/**/ +static void +set_registers(UNUSED(Param pm), HashTable ht) +{ + int i; + HashNode hn; + + if (!ht) + return; + + for (i = 0; i < ht->hsize; i++) + for (hn = ht->nodes[i]; hn; hn = hn->next) { + struct value v; + v.isarr = v.flags = v.start = 0; + v.end = -1; + v.arr = NULL; + v.pm = (Param) hn; + + set_register(v.pm, getstrvalue(&v)); + } + deleteparamtable(ht); +} + static void set_prepost(ZLE_STRING_T *textvar, int *lenvar, char *x) { -- cgit v1.2.3 From 968a59bfd0dd0b35aa82ac8fe86af65a5456baa7 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 19 Nov 2016 12:21:19 +0000 Subject: 39985: Document the [nyae] answers to the spelling correction prompt, $SPROMPT. --- ChangeLog | 5 +++++ Doc/Zsh/params.yo | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 9415eefae..01a9d2cf9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-20 Daniel Shahaf + + * 39985: Doc/Zsh/params.yo: Document the [nyae] answers to the + spelling correction prompt, $SPROMPT. + 2016-11-18 Daniel Shahaf * 39916 + 39930 + tweak: Completion/Unix/Command/_git: Complete diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index c7d84b9a8..0db8a1c0e 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1458,6 +1458,14 @@ The prompt used for spelling correction. The sequence `tt(%R)' expands to the string which presumably needs spelling correction, and `tt(%r)' expands to the proposed correction. All other prompt escapes are also allowed. + +The actions available at the prompt are tt([nyae]): +startsitem() +sitem(tt(n) +LPAR()`no'+RPAR() +LPAR()default+RPAR())(Discard the correction and run the command.) +sitem(tt(y) +LPAR()`yes'+RPAR())(Make the correction and run the command.) +sitem(tt(a) +LPAR()`abort'+RPAR())(Discard the entire command line without running it.) +sitem(tt(e) +LPAR()`edit'+RPAR())(Resume editing the command line.) +endsitem() ) vindex(STTY) item(tt(STTY))( -- cgit v1.2.3 From a2426747dabd72b8bf6fef73e4c1b229c7325385 Mon Sep 17 00:00:00 2001 From: Mikel Ward Date: Fri, 18 Nov 2016 12:11:40 -0800 Subject: 39978: more accurate doc for finding job by string --- ChangeLog | 5 +++++ Doc/Zsh/jobs.yo | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 13e52e51b..3a917f59c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-20 Peter Stephenson + + * Mikel Ward: 39978: Doc/Zsh/jobs.yo: more accurate + documentation of searching for job by string. + 2016-11-20 Daniel Shahaf * 39992: Src/params.c: setarrvalue: Allocate a correctly-sized diff --git a/Doc/Zsh/jobs.yo b/Doc/Zsh/jobs.yo index d9395010a..6262dd244 100644 --- a/Doc/Zsh/jobs.yo +++ b/Doc/Zsh/jobs.yo @@ -74,8 +74,8 @@ or by one of the following: startsitem() sitem(tt(%)var(number))(The job with the given number.) -sitem(tt(%)var(string))(Any job whose command line begins with var(string).) -sitem(tt(%?)var(string))(Any job whose command line contains var(string).) +sitem(tt(%)var(string))(The last job whose command line begins with var(string).) +sitem(tt(%?)var(string))(The last job whose command line contains var(string).) sitem(tt(%%))(Current job.) sitem(tt(%PLUS()))(Equivalent to `tt(%%)'.) sitem(tt(%-))(Previous job.) -- cgit v1.2.3 From dae21874d498ccd3f947f6f47e5ec23feb2bdcb4 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Wed, 9 Nov 2016 17:14:33 +0100 Subject: 39900: Add TERMINFO_DIRS special like TERMINFO. Although this is a colon-separated array there is no tied array. --- ChangeLog | 4 ++++ Doc/Zsh/params.yo | 18 ++++++++++++++---- Src/params.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 7b05d39d3..e21a269e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-11-20 Peter Stephenson + * Guillaume Maudoux: 39900 (doc slightly tweaked): Src/params.c, + Doc/Zsh/params.yo: Add TERMINFO_DIRS special colon-separated + array, not tied. + * 39995 (from 39977): Src/params.c, Test/A06assign.ztst: optimisation of string assignment if length is unchanged. diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 0db8a1c0e..905e92d22 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1493,10 +1493,20 @@ take effect. ) vindex(TERMINFO) item(tt(TERMINFO) )( -A reference to a compiled description of the terminal, used by the -`terminfo' library when the system has it; see manref(terminfo)(5). -If set, this causes the shell to reinitialise the terminal, making -the workaround `tt(TERM=$TERM)' unnecessary. +A reference to your terminfo database, used by the `terminfo' library when the +system has it; see manref(terminfo)(5). +If set, this causes the shell to reinitialise the terminal, making the +workaround `tt(TERM=$TERM)' unnecessary. +) +vindex(TERMINFO_DIRS) +item(tt(TERMINFO_DIRS) )( +A colon-seprarated list of terminfo databases, used by the `terminfo' library +when the system has it; see manref(terminfo)(5). This variable is only +used by certain terminal libraries, in particular ncurses; see +manref(terminfo)(5) to check support on your system. If set, this +causes the shell to reinitialise the terminal, making the workaround +`tt(TERM=$TERM)' unnecessary. Note that unlike other colon-separated +arrays this is not tied to a zsh array. ) vindex(TIMEFMT) item(tt(TIMEFMT))( diff --git a/Src/params.c b/Src/params.c index a79debc93..45f398a27 100644 --- a/Src/params.c +++ b/Src/params.c @@ -87,6 +87,7 @@ char *ifs, /* $IFS */ *postedit, /* $POSTEDIT */ *term, /* $TERM */ *zsh_terminfo, /* $TERMINFO */ + *zsh_terminfodirs, /* $TERMINFO_DIRS */ *ttystrname, /* $TTY */ *pwd; /* $PWD */ @@ -208,6 +209,8 @@ static const struct gsu_scalar term_gsu = { termgetfn, termsetfn, stdunsetfn }; static const struct gsu_scalar terminfo_gsu = { terminfogetfn, terminfosetfn, stdunsetfn }; +static const struct gsu_scalar terminfodirs_gsu = +{ terminfodirsgetfn, terminfodirssetfn, stdunsetfn }; static const struct gsu_scalar wordchars_gsu = { wordcharsgetfn, wordcharssetfn, stdunsetfn }; static const struct gsu_scalar ifs_gsu = @@ -283,6 +286,7 @@ IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT), IPDEF2("HOME", home_gsu, PM_UNSET), IPDEF2("TERM", term_gsu, PM_UNSET), IPDEF2("TERMINFO", terminfo_gsu, PM_UNSET), +IPDEF2("TERMINFO_DIRS", terminfodirs_gsu, PM_UNSET), IPDEF2("WORDCHARS", wordchars_gsu, 0), IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT | PM_RESTRICTED), IPDEF2("_", underscore_gsu, PM_DONTIMPORT), @@ -4548,6 +4552,33 @@ terminfosetfn(Param pm, char *x) term_reinit_from_pm(); } +/* Function to get value of special parameter `TERMINFO_DIRS' */ + +/**/ +char * +terminfodirsgetfn(UNUSED(Param pm)) +{ + return zsh_terminfodirs ? zsh_terminfodirs : dupstring(""); +} + +/* Function to set value of special parameter `TERMINFO_DIRS' */ + +/**/ +void +terminfodirssetfn(Param pm, char *x) +{ + zsfree(zsh_terminfodirs); + zsh_terminfodirs = x; + + /* + * terminfo relies on the value being exported before + * we reinitialise the terminal. This is a bit inefficient. + */ + if ((pm->node.flags & PM_EXPORTED) && x) + addenv(pm, x); + + term_reinit_from_pm(); +} /* Function to get value for special parameter `pipestatus' */ /**/ -- cgit v1.2.3 From cb5f100bd38a3b21739897fb4236db0700b39477 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 20 Nov 2016 23:54:45 +0100 Subject: 39986, 39989: improve handling of vi-repeat-change Save previous vi change and throw away a new change that fails. Add zle -f vichange to allow shell widget to be a single change. Fix repeat of command where numeric arguments were multiplied. --- ChangeLog | 7 +++ Doc/Zsh/zle.yo | 7 +++ Functions/Zle/vi-pipe | 3 ++ Src/Zle/zle.h | 14 ++++++ Src/Zle/zle_keymap.c | 2 +- Src/Zle/zle_main.c | 34 +++++++++++-- Src/Zle/zle_misc.c | 8 ++- Src/Zle/zle_thingy.c | 11 +++- Src/Zle/zle_utils.c | 1 + Src/Zle/zle_vi.c | 137 +++++++++++++++++++++++--------------------------- Test/X02zlevi.ztst | 10 ++-- 11 files changed, 147 insertions(+), 87 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 1095a1e5c..24fb8a3f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2016-11-20 Oliver Kiddle + * 39986, 39989: Src/Zle/zle.h, Src/Zle/zle_keymap.c, + Src/Zle/zle_main.c, Src/Zle/zle_misc.c, Src/Zle/zle_thingy.c, + Src/Zle/zle_utils.c, Src/Zle/zle_vi.c, Test/X02zlevi.ztst, + Doc/Zsh/zle.yo, Functions/Zle/vi-pipe: make vi-repeat-change + work better with shell based widgets and save old change + when recording a new change in case the new one fails + * 39974: Completion/Unix/Command/_ssh: complete shared libraries for -e and -s options to ssh-add diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index fe6a7e93b..ff3144802 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -479,6 +479,13 @@ tt(kill) for indicating that text has been killed into the cutbuffer. When repeatedly invoking a kill widget, text is appended to the cutbuffer instead of replacing it, but when wrapping such widgets, it is necessary to call `tt(zle -f kill)' to retain this effect. + +tt(vichange) for indicating that the widget represents a vi change that +can be repeated as a whole with `tt(vi-repeat-change)'. The flag should be set +early in the function before inspecting the value of tt(NUMERIC) or invoking +other widgets. This has no effect for a widget invoked from insert mode. If +insert mode is active when the widget finishes, the change extends until next +returning to command mode. ) cindex(completion widgets, creating) item(tt(-C) var(widget) var(completion-widget) var(function))( diff --git a/Functions/Zle/vi-pipe b/Functions/Zle/vi-pipe index c32e64a59..1729cb6e1 100644 --- a/Functions/Zle/vi-pipe +++ b/Functions/Zle/vi-pipe @@ -12,6 +12,9 @@ setopt localoptions noksharrays autoload -Uz read-from-minibuffer local _save_cut="$CUTBUFFER" REPLY +# mark this widget as a vi change so it can be repeated as a whole +zle -f vichange + # force movement to default to line mode (( REGION_ACTIVE )) || zle -U V # Use the standard vi-change to accept a vi motion. diff --git a/Src/Zle/zle.h b/Src/Zle/zle.h index e9b14281d..8f92e5611 100644 --- a/Src/Zle/zle.h +++ b/Src/Zle/zle.h @@ -284,6 +284,20 @@ struct change { #define CH_NEXT (1<<0) /* next structure is also part of this change */ #define CH_PREV (1<<1) /* previous structure is also part of this change */ +/* vi change handling for vi-repeat-change */ + +/* + * Examination of the code suggests vichgbuf is consistently tied + * to raw byte input, so it is left as a character array rather + * than turned into wide characters. In particular, when we replay + * it we use ungetbytes(). + */ +struct vichange { + struct modifier mod; /* value of zmod associated with vi change */ + char *buf; /* bytes for keys that make up the vi command */ + int bufsz, bufptr; /* allocated and in use sizes of buf */ +}; + /* known thingies */ #define Th(X) (&thingies[X]) diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 24e8d1964..04eb70675 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1634,7 +1634,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) unmetafy(keybuf + lastlen, &keybuflen); ungetbytes(keybuf+lastlen, keybuflen); if(vichgflag) - vichgbufptr -= keybuflen; + curvichg.bufptr -= keybuflen; keybuf[keybuflen = lastlen] = 0; } *funcp = func; diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 1652b7cd4..938dc0e29 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -924,13 +924,13 @@ getbyte(long do_keytmout, int *timeout) ret = STOUC(cc); } /* - * vichgbuf is raw bytes, not wide characters, so is dealt + * curvichg.buf is raw bytes, not wide characters, so is dealt * with here. */ if (vichgflag) { - if (vichgbufptr == vichgbufsz) - vichgbuf = realloc(vichgbuf, vichgbufsz *= 2); - vichgbuf[vichgbufptr++] = ret; + if (curvichg.bufptr == curvichg.bufsz) + curvichg.buf = realloc(curvichg.buf, curvichg.bufsz *= 2); + curvichg.buf[curvichg.bufptr++] = ret; } errno = old_errno; return lastchar = ret; @@ -1260,6 +1260,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) *zleline = ZWC('\0'); virangeflag = lastcmd = done = zlecs = zlell = mark = yankb = yanke = 0; vichgflag = 0; + viinrepeat = 0; viinsbegin = 0; statusline = NULL; selectkeymap("main", 1); @@ -1389,6 +1390,8 @@ int execzlefunc(Thingy func, char **args, int set_bindk) { int r = 0, ret = 0, remetafy = 0; + int nestedvichg = vichgflag; + int isrepeat = (viinrepeat == 3); Widget w; Thingy save_bindk = bindk; @@ -1398,6 +1401,8 @@ execzlefunc(Thingy func, char **args, int set_bindk) unmetafy_line(); remetafy = 1; } + if (isrepeat) + viinrepeat = 2; if (func->flags & DISABLED) { /* this thingy is not the name of a widget */ @@ -1523,6 +1528,25 @@ execzlefunc(Thingy func, char **args, int set_bindk) CCRIGHT(); if (remetafy) metafy_line(); + + /* if this widget constituted the vi change, end it */ + if (vichgflag == 2 && !nestedvichg) { + if (invicmdmode()) { + if (ret) { + free(curvichg.buf); + } else { + if (lastvichg.buf) + free(lastvichg.buf); + lastvichg = curvichg; + } + vichgflag = 0; + curvichg.buf = NULL; + } else + vichgflag = 1; /* vi change continues while in insert mode */ + } + if (isrepeat) + viinrepeat = !invicmdmode(); + return ret; } @@ -2230,7 +2254,7 @@ finish_(UNUSED(Module m)) cleanup_keymaps(); deletehashtable(thingytab); - zfree(vichgbuf, vichgbufsz); + zfree(lastvichg.buf, lastvichg.bufsz); zfree(kungetbuf, kungetsz); free_isrch_spots(); if (rdstrs) diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index fbd40cd03..898b552de 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -609,8 +609,10 @@ viputbefore(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0 || zmod.flags & MOD_NULL) + if (n < 0) return 1; + if (zmod.flags & MOD_NULL) + return 0; if (zmod.flags & MOD_VIBUF) kctbuf = &vibuf[zmod.vibuf]; else @@ -630,8 +632,10 @@ viputafter(UNUSED(char **args)) int n = zmult; startvichange(-1); - if (n < 0 || zmod.flags & MOD_NULL) + if (n < 0) return 1; + if (zmod.flags & MOD_NULL) + return 0; if (zmod.flags & MOD_VIBUF) kctbuf = &vibuf[zmod.vibuf]; else diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index 2d4674785..c7092854a 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -678,7 +678,16 @@ bin_zle_flags(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) else if (!strcmp(*flag, "keepsuffix")) w->flags |= ZLE_KEEPSUFFIX; */ - else { + else if (!strcmp(*flag, "vichange")) { + if (invicmdmode()) { + startvichange(-1); + if (zmod.flags & (MOD_MULT|MOD_TMULT)) { + Param pm = (Param) paramtab->getnode(paramtab, "NUMERIC"); + if (pm && pm->node.flags & PM_SPECIAL) + pm->node.flags &= ~PM_UNSET; + } + } + } else { zwarnnam(name, "invalid flag `%s' given to zle -f", *flag); ret = 1; } diff --git a/Src/Zle/zle_utils.c b/Src/Zle/zle_utils.c index 4007c1112..c6df3d89c 100644 --- a/Src/Zle/zle_utils.c +++ b/Src/Zle/zle_utils.c @@ -1704,6 +1704,7 @@ mergeundo(void) current->flags |= CH_PREV; current->prev->flags |= CH_NEXT; } + vistartchange = -1; } /* diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index fc0e49b32..e0923db3e 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -45,46 +45,41 @@ int wordflag; /**/ int vilinerange; -/* last vi change buffer, for vi change repetition */ +/* + * lastvichg: last vi change buffer, for vi change repetition + * curvichg: current incomplete vi change + */ + +/**/ +struct vichange lastvichg, curvichg; /* - * vichgbufsz: Allocated size of vichgbuf. - * vichgbufptr: Length in use. - * vichgflag: true whilst inputting a vi normal mode; causes it to be - * accumulated in vichgbuf, incrementing vichgbufptr. + * true whilst a vi change is active causing keys to be + * accumulated in curvichg.buf + * first set to 2 and when the initial widget finishes, reduced to 1 if + * in insert mode implying that the change continues until returning to + * normal mode */ /**/ -int vichgbufsz, vichgbufptr, vichgflag; +int vichgflag; /* - * The bytes that make up the current vi command. See vichgbuf* above. - * - * Examination of the code suggests vichgbuf is consistently tied - * to raw byte input, so it is left as a character array rather - * than turned into wide characters. In particular, when we replay - * it we use ungetbytes(). + * analogous to vichgflag for a repeated change with the value following + * a similar pattern (is 3 until first repeated widget starts) */ + /**/ -char *vichgbuf; +int viinrepeat; /* point where vi insert mode was last entered */ /**/ int viinsbegin; -/* value of zmod associated with vi change */ -static struct modifier lastmod; - -/* - * inrepeat: current widget is the vi change being repeated - * vichgrepeat: nested widget call within a repeat - */ -static int inrepeat, vichgrepeat; - /** * im: >= 0: is an insertmode - * -1: skip setting insert mode + * -1: skip setting insert/overwrite mode * -2: entering viins at start of editing from clean --- don't use * inrepeat or keybuf, synthesise an entry to insert mode. * Note that zmult is updated so this should be called before zmult is used. @@ -94,30 +89,27 @@ static int inrepeat, vichgrepeat; void startvichange(int im) { - if (im != -1) { - vichgflag = 1; - if (im > -1) - insmode = im; - } - if (inrepeat && im != -2) { - zmod = lastmod; - inrepeat = vichgflag = 0; - vichgrepeat = 1; - } else { - lastmod = zmod; - if (vichgbuf) - free(vichgbuf); - vichgbuf = (char *)zalloc(vichgbufsz = 16 + keybuflen); + if (im > -1) + insmode = im; + if (viinrepeat && im != -2) { + zmod = lastvichg.mod; + vichgflag = 0; + } else if (!vichgflag) { + curvichg.mod = zmod; + if (curvichg.buf) + free(curvichg.buf); + curvichg.buf = (char *)zalloc(curvichg.bufsz = 16 + keybuflen); if (im == -2) { - vichgbuf[0] = + vichgflag = 1; + curvichg.buf[0] = zlell ? (insmode ? (zlecs < zlell ? 'i' : 'a') : 'R') : 'o'; - vichgbuf[1] = '\0'; - vichgbufptr = 1; + curvichg.buf[1] = '\0'; + curvichg.bufptr = 1; } else { - strcpy(vichgbuf, keybuf); - unmetafy(vichgbuf, &vichgbufptr); + vichgflag = 2; + strcpy(curvichg.buf, keybuf); + unmetafy(curvichg.buf, &curvichg.bufptr); } - vichgrepeat = 0; } } @@ -226,10 +218,13 @@ getvirange(int wf) */ if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs, 1)) ret = -1; - if(vichgrepeat) + if (viinrepeat) zmult = mult1; - else + else { zmult = mult1 * zmod.tmult; + if (vichgflag == 2) + curvichg.mod.mult = zmult; + } } while(prefixflag && !ret); wordflag = 0; selectlocalmap(NULL); @@ -401,7 +396,6 @@ videlete(UNUSED(char **args)) vifirstnonblank(zlenoargs); } } - vichgflag = 0; return ret; } @@ -518,7 +512,6 @@ viyank(UNUSED(char **args)) cut(zlecs, c2 - zlecs, CUT_YANK); ret = 0; } - vichgflag = 0; /* cursor now at the start of the range yanked. For line mode * restore the column position */ if (vilinerange && lastcol != -1) { @@ -593,8 +586,7 @@ vireplace(UNUSED(char **args)) * a change, we always read the argument normally, even if the count * * was bad. When recording a change for repeating, and a bad count is * * given, we squash the repeat buffer to avoid repeating the partial * - * command; we've lost the previous change, but that can't be avoided * - * without a rewrite of the repeat code. */ + * command. */ /**/ int @@ -644,18 +636,12 @@ vireplacechars(UNUSED(char **args)) /* check argument range */ if (n < 1 || fail) { - if(vichgrepeat) + if (viinrepeat) vigetkey(); - if(vichgflag) { - free(vichgbuf); - vichgbuf = NULL; - vichgflag = 0; - } return 1; } /* get key */ if((ch = vigetkey()) == ZLEEOF) { - vichgflag = 0; return 1; } /* do change */ @@ -682,7 +668,6 @@ vireplacechars(UNUSED(char **args)) zleline[zlecs++] = ch; zlecs--; } - vichgflag = 0; return 0; } @@ -693,7 +678,16 @@ vicmdmode(UNUSED(char **args)) if (invicmdmode() || selectkeymap("vicmd", 0)) return 1; mergeundo(); - vichgflag = 0; + insmode = unset(OVERSTRIKE); + if (vichgflag == 1) { + vichgflag = 0; + if (lastvichg.buf) + free(lastvichg.buf); + lastvichg = curvichg; + curvichg.buf = NULL; + } + if (viinrepeat == 1) + viinrepeat = 0; if (zlecs != findbol()) DECCS(); return 0; @@ -748,7 +742,6 @@ vioperswapcase(UNUSED(char **args)) vifirstnonblank(); #endif } - vichgflag = 0; return ret; } @@ -771,7 +764,6 @@ viupcase(UNUSED(char **args)) zlecs = oldcs; ret = 0; } - vichgflag = 0; return ret; } @@ -794,7 +786,6 @@ vidowncase(UNUSED(char **args)) zlecs = oldcs; ret = 0; } - vichgflag = 0; return ret; } @@ -803,23 +794,23 @@ int virepeatchange(UNUSED(char **args)) { /* make sure we have a change to repeat */ - if (!vichgbuf || vichgflag || virangeflag) + if (!lastvichg.buf || vichgflag || virangeflag) return 1; /* restore or update the saved count and buffer */ if (zmod.flags & MOD_MULT) { - lastmod.mult = zmod.mult; - lastmod.flags |= MOD_MULT; + lastvichg.mod.mult = zmod.mult; + lastvichg.mod.flags |= MOD_MULT; } if (zmod.flags & MOD_VIBUF) { - lastmod.vibuf = zmod.vibuf; - lastmod.flags = (lastmod.flags & ~MOD_VIAPP) | + lastvichg.mod.vibuf = zmod.vibuf; + lastvichg.mod.flags = (lastvichg.mod.flags & ~MOD_VIAPP) | MOD_VIBUF | (zmod.flags & MOD_VIAPP); - } else if (lastmod.flags & MOD_VIBUF && - lastmod.vibuf >= 27 && lastmod.vibuf <= 34) - lastmod.vibuf++; /* for "1 to "8 advance to next buffer */ + } else if (lastvichg.mod.flags & MOD_VIBUF && + lastvichg.mod.vibuf >= 27 && lastvichg.mod.vibuf <= 34) + lastvichg.mod.vibuf++; /* for "1 to "8 advance to next buffer */ /* repeat the command */ - inrepeat = 1; - ungetbytes(vichgbuf, vichgbufptr); + viinrepeat = 3; + ungetbytes(lastvichg.buf, lastvichg.bufptr); return 0; } @@ -835,10 +826,8 @@ viindent(UNUSED(char **args)) region_active = 2; /* get the range */ if ((c2 = getvirange(0)) == -1) { - vichgflag = 0; return 1; } - vichgflag = 0; /* must be a line range */ if (!vilinerange) { zlecs = oldcs; @@ -873,10 +862,8 @@ viunindent(UNUSED(char **args)) region_active = 2; /* get the range */ if ((c2 = getvirange(0)) == -1) { - vichgflag = 0; return 1; } - vichgflag = 0; /* must be a line range */ if (!vilinerange) { zlecs = oldcs; diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index c19573241..d3b533490 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -140,6 +140,12 @@ >BUFFER: xxe xxx xxxee >CURSOR: 10 + zletest $'one two three four five six seven eight\e.03d2wk.1.' +0:numeric args to both action and movement are multiplied (and saved for any repeat) +>BUFFER: eight +>seven eight +>CURSOR: 0 + zletest $'yankee doodle\ebhDyy0"1P' 0:paste register 1 to get last deletion >BUFFER: doodleyankee @@ -262,10 +268,8 @@ print -u $ZTST_fd 'This test may hang the shell when it fails...' zletest $'worm\erdhd..' 0:use of vi-repeat as the motion and repeat after a failed change ->BUFFER: word +>BUFFER: wodd >CURSOR: 2 -F:For vi compatibility, "." should repeat the "rd" change after "d." -F:Update result to ">BUFFER: wodd" if compatibility is repaired. zpty_run 'bindkey "^_" undo' zletest $'undoc\037e' -- cgit v1.2.3 From 3570172d3be4e10549a9966b39f8cae762975bcd Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 24 Nov 2016 16:05:00 +0100 Subject: 40003: include "0-"9 vi buffers in the registers associative array --- ChangeLog | 3 +++ Doc/Zsh/zle.yo | 2 +- Src/Zle/zle_params.c | 35 ++++++++++++++++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 007b05457..0bf059098 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * 40003: Src/Zle/zle_params.c, Doc/Zsh/zle.yo: include "0-"9 + vi buffers in the registers associative array + 2016-11-24 Jun-ichi Takimoto * 40005: Completion/Unix/Command/_date, diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index ff3144802..d68365b94 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -1000,7 +1000,7 @@ ifnzman(noderef(Character Highlighting)) for details. ) vindex(registers) item(tt(registers) (associative array))( -The contents of each of the `named' vi register buffers. These are +The contents of each of the vi register buffers. These are typically set using tt(vi-set-buffer) followed by a delete, change or yank command. ) diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index cb8dac867..78e78354f 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -729,15 +729,22 @@ static void set_register(Param pm, char *value) { int n = 0; + int offset = -1; Cutbuffer reg; - if (!pm->node.nam || *pm->node.nam < 'a' || *pm->node.nam > 'z' || - pm->node.nam[1]) { + if (!pm->node.nam || pm->node.nam[1]) + ; + else if (*pm->node.nam >= '0' && *pm->node.nam <= '9') + offset = '0' - 26; + else if (*pm->node.nam >= 'a' && *pm->node.nam <= 'z') + offset = 'a'; + + if (offset == -1) { zerr("invalid zle register: %s", pm->node.nam); return; } - reg = &vibuf[*pm->node.nam - 'a']; + reg = &vibuf[*pm->node.nam - offset]; if (*value) reg->buf = stringaszleline(value, 0, &n, NULL, NULL); reg->len = n; @@ -755,18 +762,21 @@ static void scan_registers(UNUSED(HashTable ht), ScanFunc func, int flags) { int i; + char ch; struct param pm; memset((void *)&pm, 0, sizeof(struct param)); pm.node.flags = PM_SCALAR | PM_READONLY; pm.gsu.s = &nullsetscalar_gsu; - for (i = 0; i < 26; i++) { + for (i = 0, ch = 'a'; i < 36; i++) { pm.node.nam = zhalloc(2); - *pm.node.nam = 'a' + i; + *pm.node.nam = ch; pm.node.nam[1] = '\0'; pm.u.str = zlelineasstring(vibuf[i].buf, vibuf[i].len, 0, NULL, NULL, 1); func(&pm.node, flags); + if (ch++ == 'z') + ch = '0'; } } @@ -775,17 +785,24 @@ static HashNode get_registers(UNUSED(HashTable ht), const char *name) { Param pm = (Param) hcalloc(sizeof(struct param)); + int reg = -1; pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR; pm->gsu.s = ®ister_gsu; - if (*name < 'a' || *name > 'z' || name[1]) { + if (name[1]) + ; + else if (*name >= '0' && *name <= '9') + reg = *name - '0' + 26; + else if (*name >= 'a' && *name <= 'z') + reg = *name - 'a'; + + if (reg == -1) { pm->u.str = dupstring(""); pm->node.flags |= (PM_UNSET|PM_SPECIAL); - } else { - int reg = *name - 'a'; + } else pm->u.str = zlelineasstring(vibuf[reg].buf, vibuf[reg].len, 0, NULL, NULL, 1); - } + return &pm->node; } -- cgit v1.2.3 From 110ffae9fefa1367af4fdcc90a456de23b92436c Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Mon, 28 Nov 2016 22:53:24 -0800 Subject: 40035: Cosmetic fixes for comments and documentation. Mostly fixes to doubled words. --- ChangeLog | 7 +++++-- Completion/Base/Utility/_arguments | 2 +- Completion/Unix/Command/_git | 2 +- Completion/Unix/Type/_zfs_dataset | 2 +- Completion/Zsh/Command/_zstyle | 2 +- Completion/Zsh/Function/_zargs | 2 +- Doc/Zsh/builtins.yo | 2 +- Doc/Zsh/compsys.yo | 4 ++-- Doc/Zsh/contrib.yo | 2 +- Etc/ChangeLog-4.3 | 2 +- Src/Zle/zle_refresh.c | 2 +- Src/glob.c | 2 +- Src/hist.c | 2 +- Src/input.c | 2 +- Src/subst.c | 2 +- Src/zsh.h | 2 +- Util/helpfiles | 2 +- 17 files changed, 22 insertions(+), 19 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index a016ce0e6..0d5f61198 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-11-29 Peter Stephenson + * 40035: Eitan Adler: Cosmetic fixes mostly for duplication in + comments and documentation. + * 40026: Src/Zle/zle_tricky.c: More care with redirection completion. Fixes for completion after > in "!> ." that should add to sanity. @@ -3523,7 +3526,7 @@ 2015-09-28 Barton E. Schaefer - * 36669: Src/lex.c: fix ${(z)...} of an an incomplete math + * 36669: Src/lex.c: fix ${(z)...} of an incomplete math expression by restoring "((" at the front of the token 2015-09-28 Daniel Shahaf @@ -9517,7 +9520,7 @@ 2013-07-20 Peter Stephenson * 31545: Src/exec.c, Src/parse.c: if FD_CLOEXEC is available, - so mark dump file file descriptors, avoiding possible + so mark dump file descriptors, avoiding possible multiple use of file descriptors. 2013-07-19 Peter Stephenson diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments index 82c969629..d2c0d33de 100644 --- a/Completion/Base/Utility/_arguments +++ b/Completion/Base/Utility/_arguments @@ -105,7 +105,7 @@ if (( long )); then continue else # Still no comment, add the previous options anyway. - # Add a ':' after the option anyways, to make the the matching of + # Add a ':' after the option anyways, to make the matching of # the options lateron work as intended. # It will be removed again later. lopts+=("${^tmp[@]}":) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 283c50cc0..da049bd23 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -6114,7 +6114,7 @@ __git_recent_branches() { local -aU valid_ref_names_munged=( ${"${(f)"$(_call_program valid-ref-names 'git for-each-ref --format="%(refname)" refs/heads/')"}"#refs/heads/} ) # 1. Obtain names of recently-checked-out branches from the reflog. - # 2. Remove ref names that that no longer exist from the list. + # 2. Remove ref names that no longer exist from the list. # (We must do this because #3 would otherwise croak on them.) __git_recent_branches__names; branches=( ${(@)reply:*valid_ref_names_munged} ) diff --git a/Completion/Unix/Type/_zfs_dataset b/Completion/Unix/Type/_zfs_dataset index 6c625e9ec..6bef04e45 100644 --- a/Completion/Unix/Type/_zfs_dataset +++ b/Completion/Unix/Type/_zfs_dataset @@ -4,7 +4,7 @@ local -a type expl_type_arr rsrc rdst paths_allowed local -a typearg datasetlist expl mlist local expl_type -# -e takes an argument which is passed as as the "descr" argument to _wanted +# -e takes an argument which is passed as the "descr" argument to _wanted # -p indicates that filesystem paths, not just dataset names, are allowed # -r1 indicates that we're completing the source of a rename # -r2 indicates that we're completing the destination of a rename diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index d6f285271..0e828225e 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -266,7 +266,7 @@ while (( $#state )); do _wanted contexts expl "$state_descr" compadd -a patterns ;; - # 'metapatterns': patterns that are are matched not against contexts, but + # 'metapatterns': patterns that are matched not against contexts, but # against patterns. (metapatterns) zstyle -g patterns diff --git a/Completion/Zsh/Function/_zargs b/Completion/Zsh/Function/_zargs index c24b276f2..f974ab646 100644 --- a/Completion/Zsh/Function/_zargs +++ b/Completion/Zsh/Function/_zargs @@ -4,7 +4,7 @@ local arguments eofstr pos=$((CURRENT)) numeofs=0 ret=1 cmdpos=1 #this doesn't handle '--' on the command line, only -- #it also by extension doesn't handle eofstr being the empty string -#it also also doesn't handle eofstr being -e or --eof, and everything will +#it also doesn't handle eofstr being -e or --eof, and everything will # probably also be confused if the command at the end takes a -e, --eof= or -- eofstr=${${${${words[(r)(--eof=*|-e*)]}#--eof=}#-e}:---} while { diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 169a31ea3..7b04d0648 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -570,7 +570,7 @@ with emulations to be set to their values in tt(sh). tt(fno) then calls tt(fni); because tt(fni) is also marked for sticky tt(sh) emulation, no option changes take place on entry to or exit from it. Hence the option tt(cshnullglob), turned off by tt(sh) emulation, will -be turned on within tt(fni) and remain on on return to tt(fno). On exit +be turned on within tt(fni) and remain on return to tt(fno). On exit from tt(fno), the emulation mode and all options will be restored to the state they were in before entry to the temporary emulation. diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index ceb98c7bc..60ef9ee2c 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -144,8 +144,8 @@ directory mentioned in the tt(fpath) parameter, and should be autoloaded few utility functions, arrange for all the necessary shell functions to be autoloaded, and will then re-define all widgets that do completion to use the new system. If you use the tt(menu-select) widget, which is part of the -tt(zsh/complist) module, you should make sure that that module is loaded -before the call to tt(compinit) so that that widget is also +tt(zsh/complist) module, you should make sure that the module is loaded +before the call to tt(compinit) so that the widget is also re-defined. If completion styles (see below) are set up to perform expansion as well as completion by default, and the TAB key is bound to tt(expand-or-complete), tt(compinit) will rebind it to tt(complete-word); diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 623507283..f764eb7c6 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3854,7 +3854,7 @@ The expression tt(<) followed (with no space) by a shell identifier causes the value of the variable with that name to be pushed onto the stack. var(ident) may be an integer, in which case the previous result with that number (as shown before -the tt(>) in th standard standard tt(zcalc) prompt) is put on the stack. +the tt(>) in the standard tt(zcalc) prompt) is put on the stack. ) item(Exchange: tt(xy))( The pseudo-function tt(xy) causes the most recent two elements of diff --git a/Etc/ChangeLog-4.3 b/Etc/ChangeLog-4.3 index 1be618b48..6d85e40af 100644 --- a/Etc/ChangeLog-4.3 +++ b/Etc/ChangeLog-4.3 @@ -1182,7 +1182,7 @@ 2011-08-16 Wayne Davison - * 29650: Src/jobs.c: don't lose the the time info after a + * 29650: Src/jobs.c: don't lose the time info after a suspend+restore. 2011-08-15 Peter Stephenson diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index e78f1e562..8d173cda1 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -946,7 +946,7 @@ addmultiword(REFRESH_ELEMENT *base, ZLE_STRING_T tptr, int ichars) /* * Swap the old and new video buffers, plus any associated multiword - * buffers. The new buffer becomes the old one; the new new buffer + * buffers. The new buffer becomes the old one; the new buffer * will be filled with the command line next time. */ static void diff --git a/Src/glob.c b/Src/glob.c index 33bf2ae18..623e6f1d6 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -1174,7 +1174,7 @@ checkglobqual(char *str, int sl, int nobareglob, char **sp) } /* Main entry point to the globbing code for filename globbing. * - * np points to a node in the list list which will be expanded * + * np points to a node in the list which will be expanded * * into a series of nodes. */ /**/ diff --git a/Src/hist.c b/Src/hist.c index 5be7d2524..97fd34039 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -1038,7 +1038,7 @@ hbegin(int dohist) /* * pws: We used to test for "|| (inbufflags & INP_ALIAS)" * in this test, but at this point we don't have input - * set up up so this can trigger unnecessarily. + * set up so this can trigger unnecessarily. * I don't see how the test at this point could ever be * useful, since we only get here when we're initialising * the history mechanism, before we've done any input. diff --git a/Src/input.c b/Src/input.c index eb968ea72..fe94b8ef7 100644 --- a/Src/input.c +++ b/Src/input.c @@ -51,7 +51,7 @@ * Note that the input string is itself used as the input buffer: it is not * copied, nor is it every written back to, so using a constant string * should work. Consequently, when passing areas of memory from the heap - * it is necessary that that heap last as long as the operation of reading + * it is necessary that the heap last as long as the operation of reading * the string. After the string is read, the stack should be popped with * inpop(), which effectively flushes any unread input as well as restoring * the previous input state. diff --git a/Src/subst.c b/Src/subst.c index c7c552257..a26ebb1d6 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2368,7 +2368,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * This is the inner handling for the case referred to above * where we have something like ${${(P)name}...}. * - * Treat this as as a normal value here; all transformations on + * Treat this as a normal value here; all transformations on * result are in outer instance. */ aspar = 0; diff --git a/Src/zsh.h b/Src/zsh.h index a5d4455e3..63cada827 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1589,7 +1589,7 @@ struct zpc_disables_save { /* * Bit vector of ZPC_COUNT disabled characters. * We'll live dangerously and assumed ZPC_COUNT is no greater - * than the number of bits an an unsigned int. + * than the number of bits an unsigned int. */ unsigned int disables; }; diff --git a/Util/helpfiles b/Util/helpfiles index 699ca8321..9e837fe2d 100755 --- a/Util/helpfiles +++ b/Util/helpfiles @@ -19,7 +19,7 @@ # This script is called automatically during `make install' # unless specified otherwise. -# For usage and and more information see zshcontrib(1). +# For usage and more information see zshcontrib(1). sub Usage { print(STDERR "Usage: helpfiles zshbuiltins.1 dest-dir [link-file]\n"); -- cgit v1.2.3