From f1667d2c62ebd47b0e8bd48b2c64912b733066eb Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Wed, 1 Jun 2011 15:06:17 +0000 Subject: 29416: Fix (mis-)uses of var() in vcs_info documentation. --- Doc/Zsh/contrib.yo | 271 +++++++++++++++++++++++++++-------------------------- 1 file changed, 136 insertions(+), 135 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index cf42e28a9..9bb7dcf45 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -614,7 +614,7 @@ There is also support for the patch management system tt(quilt) (http://savannah.nongnu.org/projects/quilt). See tt(Quilt Support) below for details. -To load var(vcs_info): +To load tt(vcs_info): example(autoload -Uz vcs_info) @@ -624,21 +624,21 @@ tt($psvar) entries to be left available. subsect(Quickstart) To get this feature working quickly (including colors), you can do the -following (assuming, you loaded var(vcs_info) properly - see above): +following (assuming, you loaded tt(vcs_info) properly - see above): -example(zstyle ':vcs_info:*' actionformats \ +example(zstyle ':vcs_info:*' actionformats \ '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f ' -zstyle ':vcs_info:*' formats \ +zstyle ':vcs_info:*' formats \ '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f ' zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r' precmd () { vcs_info } PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg_0_}%f%# ') Obviously, the last two lines are there for demonstration. You need to -call var(vcs_info) from your var(precmd) function. Once that is done you need -a tt(single quoted) var('${vcs_info_msg_0_}') in your prompt. +call tt(vcs_info) from your tt(precmd) function. Once that is done you need +a tt(single quoted) tt('${vcs_info_msg_0_}') in your prompt. -To be able to use var('${vcs_info_msg_0_}') directly in your prompt like +To be able to use tt('${vcs_info_msg_0_}') directly in your prompt like this, you will need to have the tt(PROMPT_SUBST) option enabled. Now call the tt(vcs_info_printsys) utility from the command line: @@ -678,54 +678,55 @@ You may also pick a few from that list and enable only those: example(zstyle ':vcs_info:*' enable git cvs svn) If you rerun tt(vcs_info_printsys) after one of these commands, you will -see the backends listed in the var(disable) style (or backends not in the -var(enable) style - if you used that) marked as disabled by a hash sign. -That means the detection of these systems is skipped tt(completely). No +see the backends listed in the tt(disable) style (or backends not in the +tt(enable) style - if you used that) marked as disabled by a hash sign. +That means the detection of these systems is skipped em(completely). No wasted time there. subsect(Configuration) -The var(vcs_info) feature can be configured via var(zstyle). +The tt(vcs_info) feature can be configured via tt(zstyle). First, the context in which we are working: -example(:vcs_info:::) +example(:vcs_info:var(vcs-string):var(user-context):var(repo-root-name)) startitem() -item(tt())( -is one of: git, git-svn, git-p4, hg, hg-git, hg-hgsubversion, hg-hgsvn, -darcs, bzr, cdv, mtn, svn, cvs, svk, tla, p4 or fossil. When hooks are -active the hooks name is added after a `+'. (See tt(Hooks in vcs_info) +item(var(vcs-string))( +is one of: bf(git), bf(git-svn), bf(git-p4), bf(hg), bf(hg-git), +bf(hg-hgsubversion), bf(hg-hgsvn), bf(darcs), bf(bzr), bf(cdv), bf(mtn), +bf(svn), bf(cvs), bf(svk), bf(tla), bf(p4) or bf(fossil). When hooks are +active the hooks name is added after a `+'. (See bf(Hooks in vcs_info) below.) ) -item(tt())( +item(var(user-context))( is a freely configurable string, assignable by -the user as the first argument to var(vcs_info) (see its description +the user as the first argument to tt(vcs_info) (see its description below). ) -item(tt())( +item(var(repo-root-name))( is the name of a repository in which you want a -style to match. So, if you want a setting specific to var(/usr/src/zsh), -with that being a CVS checkout, you can set tt() to -var(zsh) to make it so. +style to match. So, if you want a setting specific to tt(/usr/src/zsh), +with that being a CVS checkout, you can set var(repo-root-name) to +tt(zsh) to make it so. ) enditem() -There are three special values for tt(): The first is named -var(-init-), that is in effect as long as there was no decision what VCS -backend to use. The second is var(-preinit-); it is used tt(before) -var(vcs_info) is run, when initializing the data exporting variables. The -third special value is var(formats) and is used by the tt(vcs_info_lastmsg) +There are three special values for var(vcs-string): The first is named +tt(-init-), that is in effect as long as there was no decision what VCS +backend to use. The second is tt(-preinit-); it is used em(before) +tt(vcs_info) is run, when initializing the data exporting variables. The +third special value is tt(formats) and is used by the tt(vcs_info_lastmsg) for looking up its styles. -The initial value of tt() is var(-all-) and it is replaced +The initial value of var(repo-root-name) is tt(-all-) and it is replaced with the actual name, as soon as it is known. Only use this part of the -context for defining the var(formats), var(actionformats) or -var(branchformat) styles, as it is guaranteed that tt() is +context for defining the tt(formats), tt(actionformats) or +tt(branchformat) styles, as it is guaranteed that var(repo-root-name) is set up correctly for these only. For all other styles, just use tt('*') instead. -There are two pre-defined values for tt(): +There are two pre-defined values for var(user-context): startsitem() sitem(tt(default))(the one used if none is specified) sitem(tt(command))(used by vcs_info_lastmsg to lookup its styles) @@ -750,15 +751,15 @@ a merge conflict. ) kindex(branchformat) item(tt(branchformat))( -Some backends replace var(%b) in the formats and +Some backends replace tt(%b) in the formats and actionformats styles above, not only by a branch name but also by a revision number. This style lets you modify how that string should look. ) kindex(nvcsformats) item(tt(nvcsformats))( These "formats" are exported when we didn't detect a version control system -for the current directory or var(vcs_info) was disabled. This is useful if -you want var(vcs_info) to completely take over the generation of your +for the current directory or tt(vcs_info) was disabled. This is useful if +you want tt(vcs_info) to completely take over the generation of your prompt. You would do something like tt(PS1='${vcs_info_msg_0_}') to accomplish that. ) @@ -766,36 +767,36 @@ kindex(hgrevformat) item(tt(hgrevformat))( tt(hg) uses both a hash and a revision number to reference a specific changeset in a repository. With this style you can format the revision -string (see var(branchformat)) to include either or both. It's only -useful when var(get-revision) is true. +string (see tt(branchformat)) to include either or both. It's only +useful when tt(get-revision) is true. ) kindex(max-exports) item(tt(max-exports))( Defines the maximum number of -var(vcs_info_msg_*_) variables var(vcs_info) will export. +tt(vcs_info_msg_*_) variables tt(vcs_info) will export. ) kindex(enable) item(tt(enable))( -A list of backends you want to use. Checked in the var(-init-) context. If +A list of backends you want to use. Checked in the tt(-init-) context. If this list contains an item called tt(NONE) no backend is used at all and -var(vcs_info) will do nothing. If this list contains tt(ALL) var(vcs_info) +tt(vcs_info) will do nothing. If this list contains tt(ALL), tt(vcs_info) will use all known backends. Only with tt(ALL) in tt(enable) will the tt(disable) style have any effect. tt(ALL) and tt(NONE) are case insensitive. ) kindex(disable) item(tt(disable))( -A list of VCSs you don't want var(vcs_info) to test for -repositories (checked in the var(-init-) context, too). Only used if +A list of VCSs you don't want tt(vcs_info) to test for +repositories (checked in the tt(-init-) context, too). Only used if tt(enable) contains tt(ALL). ) kindex(disable-patterns) item(tt(disable-patterns))( A list of patterns that are checked against tt($PWD). If a pattern -matches, var(vcs_info) will be disabled. This style is checked in the -var(:vcs_info:-init-:*:-all-) context. +matches, tt(vcs_info) will be disabled. This style is checked in the +tt(:vcs_info:-init-:*:-all-) context. Say, tt(~/.zsh) is a directory under version control, in which you do -not want var(vcs_info) to be active, do: +not want tt(vcs_info) to be active, do: example(zstyle ':vcs_info:*' disable-patterns "$HOME/.zsh+LPAR()|/*+RPAR()") ) kindex(use-quilt) @@ -810,7 +811,7 @@ in a given directory. See tt(Quilt Support) for details. ) kindex(quilt-patch-dir) item(tt(quilt-patch-dir))( -Overwrite the value of the var($QUILT_PATCHES) environment variable. See +Overwrite the value of the tt($QUILT_PATCHES) environment variable. See tt(Quilt Support) for details. ) kindex(quiltcommand) @@ -822,12 +823,12 @@ kindex(check-for-changes) item(tt(check-for-changes))( If enabled, this style causes the tt(%c) and tt(%u) format escapes to show when the working directory has uncommitted changes. The strings displayed by -these escapes can be controlled via the var(stagedstr) and var(unstagedstr) +these escapes can be controlled via the tt(stagedstr) and tt(unstagedstr) styles. The only backends that currently support this option are tt(git) and tt(hg) (tt(hg) only supports unstaged). -For this style to be evaluated with the tt(hg) backend, the var(get-revision) -style needs to be set and the var(use-simple) style needs to be unset. The +For this style to be evaluated with the tt(hg) backend, the tt(get-revision) +style needs to be set and the tt(use-simple) style needs to be unset. The latter is the default; the former is not. Note, the actions taken if this style is enabled are potentially expensive @@ -846,19 +847,19 @@ in the repository. ) kindex(command) item(tt(command))( -This style causes var(vcs_info) to use the supplied string as the command +This style causes tt(vcs_info) to use the supplied string as the command to use as the VCS's binary. Note, that setting this in ':vcs_info:*' is not a good idea. If the value of this style is empty (which is the default), the used binary -name is the name of the backend in use (e.g. var(svn) is used in an var(svn) +name is the name of the backend in use (e.g. tt(svn) is used in an tt(svn) repository). -The var(repo-root-name) part in the context is always the default tt(-all-) +The tt(repo-root-name) part in the context is always the default tt(-all-) when this style is looked up. For example, this style can be used to use binaries from non-default -installation directories. Assume, var(git) is installed in /usr/bin but +installation directories. Assume, tt(git) is installed in /usr/bin but your sysadmin installed a newer version in /usr/bin/local. Instead of changing the order of your tt($PATH) parameter, you can do this: example(zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git) @@ -869,7 +870,7 @@ This is used by the Perforce backend (tt(p4)) to decide if it should contact the Perforce server to find out if a directory is managed by Perforce. This is the only reliable way of doing this, but runs the risk of a delay if the server name cannot be found. If the -server (more specifically, the var(host)tt(:)var(port) pair describing the +server (more specifically, the tt(host)tt(:)tt(port) pair describing the server) cannot be contacted, its name is put into the associative array tt(vcs_info_p4_dead_servers) and is not contacted again during the session until it is removed by hand. If you do not set this style, the tt(p4) @@ -910,17 +911,17 @@ bookmarks. They will be available via the `tt(%m)' replacement. kindex(use-prompt-escapes) item(tt(use-prompt-escapes))( Determines if we assume that the assembled -string from var(vcs_info) includes prompt escapes. (Used by +string from tt(vcs_info) includes prompt escapes. (Used by tt(vcs_info_lastmsg).) ) kindex(debug) item(tt(debug))( Enable debugging output to track possible problems. Currently this style -is only used by var(vcs_info)'s hooks system. +is only used by tt(vcs_info)'s hooks system. ) kindex(hooks) item(tt(hooks))( -A list style that defines hook-function names. See tt(Hooks in vcs_info) +A list style that defines hook-function names. See bf(Hooks in vcs_info) below for details. ) enditem() @@ -951,7 +952,7 @@ sitem(tt(debug))(false) sitem(tt(hooks))((empty list)) sitem(tt(use-quilt))(false) sitem(tt(quilt-standalone))(false) -sitem(tt(quilt-patch-dir))(empty - use var($QUILT_PATCHES)) +sitem(tt(quilt-patch-dir))(empty - use tt($QUILT_PATCHES)) sitem(tt(quiltcommand))(quilt) endsitem() @@ -962,18 +963,18 @@ startsitem() sitem(tt(%s))(The VCS in use (git, hg, svn, etc.).) sitem(tt(%b))(Information about the current branch.) sitem(tt(%a))(An identifier that describes the action. Only makes sense in -var(actionformats).) +tt(actionformats).) sitem(tt(%i))(The current revision number or identifier. For tt(hg) -the var(hgrevformat) style may be used to customize the output.) -sitem(tt(%c))(The string from the var(stagedstr) style if there are staged +the tt(hgrevformat) style may be used to customize the output.) +sitem(tt(%c))(The string from the tt(stagedstr) style if there are staged changes in the repository.) -sitem(tt(%u))(The string from the var(unstagedstr) style if there are +sitem(tt(%u))(The string from the tt(unstagedstr) style if there are unstaged changes in the repository.) sitem(tt(%R))(The base directory of the repository.) -sitem(tt(%r))(The repository name. If tt(%R) is var(/foo/bar/repoXY), tt(%r) -is var(repoXY).) +sitem(tt(%r))(The repository name. If tt(%R) is tt(/foo/bar/repoXY), tt(%r) +is tt(repoXY).) sitem(tt(%S))(A subdirectory within a repository. If tt($PWD) is -var(/foo/bar/repoXY/beer/tasty), tt(%S) is var(beer/tasty).) +tt(/foo/bar/repoXY/beer/tasty), tt(%S) is tt(beer/tasty).) sitem(tt(%m))(A "misc" replacement. It is at the discretion of the backend to decide what this replacement expands to. It is currently used by the tt(hg) and tt(git) backends to display patch information from the tt(mq) and @@ -984,7 +985,7 @@ In tt(branchformat) these replacements are done: startsitem() sitem(tt(%b))(The branch name.) -sitem(tt(%r))(The current revision number or the var(hgrevformat) style for +sitem(tt(%r))(The current revision number or the tt(hgrevformat) style for tt(hg).) endsitem() @@ -1011,18 +1012,18 @@ no replacements are performed at all, it is just a string. subsect(Oddities) -If you want to use the tt(%b) (bold off) prompt expansion in var(formats), -which expands tt(%b) itself, use tt(%%b). That will cause the var(vcs_info) +If you want to use the tt(%b) (bold off) prompt expansion in tt(formats), +which expands tt(%b) itself, use tt(%%b). That will cause the tt(vcs_info) expansion to replace tt(%%b) with tt(%b), so that zsh's prompt expansion mechanism can handle it. Similarly, to hand down tt(%b) from -var(branchformat), use tt(%%%%b). Sorry for this inconvenience, but it +tt(branchformat), use tt(%%%%b). Sorry for this inconvenience, but it cannot be easily avoided. Luckily we do not clash with a lot of prompt expansions and this only needs to be done for those. subsect(Quilt Support) -tt(Quilt) is not a version control system, therefore this is not implemented +bf(Quilt) is not a version control system, therefore this is not implemented as a backend. It can help keeping track of a series of patches. People use it to keep a set of changes they want to use on top of software packages (which is tightly integrated into the package build process - the Debian project @@ -1030,63 +1031,63 @@ does this for a large number of packages). Quilt can also help individual developers keep track of their own patches on top of real version control systems. -The var(vcs_info) integration tries to support both ways of using quilt by +The tt(vcs_info) integration tries to support both ways of using quilt by having two slightly different modes of operation: `addon' mode and `standalone' mode). -For `addon' mode to become active var(vcs_info) must have already detected a +For `addon' mode to become active tt(vcs_info) must have already detected a real version control system controlling the directory. If that is the case, a directory that holds quilt's patches needs to be found. That directory is -configurable via the var(`QUILT_PATCHES') environment variable. If that -variable exists its value is used, otherwise the value tt(`patches') is -assumed. The value from var($QUILT_PATCHES) can be overwritten using the -tt(`quilt-patches') style. (Note: you can use var(vcs_info) to keep the value -of var($QUILT_PATCHES) correct all the time via the tt(post-quilt) hook). +configurable via the `tt(QUILT_PATCHES)' environment variable. If that +variable exists its value is used, otherwise the value `tt(patches)' is +assumed. The value from tt($QUILT_PATCHES) can be overwritten using the +tt(`quilt-patches') style. (Note: you can use tt(vcs_info) to keep the value +of tt($QUILT_PATCHES) correct all the time via the tt(post-quilt) hook). When the directory in question is found, quilt is assumed to be active. To -gather more information, var(vcs_info) looks for a directory called `.pc'; +gather more information, tt(vcs_info) looks for a directory called `.pc'; Quilt uses that directory to track its current state. If this directory does not exist we know that quilt has not done anything to the working directory (read: no patches have been applied yet). -If patches are applied, var(vcs_info) will try to find out which. If you want +If patches are applied, tt(vcs_info) will try to find out which. If you want to know which patches of a series are not yet applied, you need to activate the tt(get-unapplied) style in the appropriate context. -var(vcs_info) allows for very detailed control over how the gathered -information is presented (see the below sections, tt(Styles) and tt(Hooks in +tt(vcs_info) allows for very detailed control over how the gathered +information is presented (see the below sections, bf(Styles) and bf(Hooks in vcs_info)), all of which are documented below. Note there are a number of other patch tracking systems that work on top of a certain version control -system (like tt(stgit) for tt(git), or tt(mq) for tt(hg)); the configuration -for systems like that are generally configured the same way as the tt(quilt) +system (like tt(stgit) for bf(git), or tt(mq) for bf(hg)); the configuration +for systems like that are generally configured the same way as the bf(quilt) support. -If the tt(quilt) support is working in `addon' mode, the produced string is -available as a simple format replacement (var(%Q) to be precise), which can +If the bf(quilt) support is working in `addon' mode, the produced string is +available as a simple format replacement (tt(%Q) to be precise), which can be used in tt(formats) and tt(actionformats); see below for details). If, on the other hand, the support code is working in `standalone' mode, -var(vcs_info) will pretend as if tt(quilt) were an actual version control +tt(vcs_info) will pretend as if tt(quilt) were an actual version control system. That means that the version control system identifier (which otherwise would be something like `svn' or `cvs') will be set to `tt(-quilt-)'. This has implications on the used style context where this -identifier is the second element. var(vcs_info) will have filled in a proper +identifier is the second element. tt(vcs_info) will have filled in a proper value for the "repository's" root directory and the string containing the information about quilt's state will be available as the `misc' replacement -(and var(%Q) for compatibility with `addon' mode. +(and tt(%Q) for compatibility with `addon' mode. What is left to discuss is how `standalone' mode is detected. The detection itself is a series of searches for directories. You can have this detection enabled all the time in every directory that is not otherwise under version control. If you know there is only a limited set of trees where you would -like var(vcs_info) to try and look for Quilt in `standalone' mode to minimise -the amount of searching on every call to var(vcs_info), there are a number of +like tt(vcs_info) to try and look for Quilt in `standalone' mode to minimise +the amount of searching on every call to tt(vcs_info), there are a number of ways to do that: Essentially, `standalone' mode detection is controlled by a style called `tt(quilt-standalone)'. It is a string style and its value can have different effects. The simplest values are: `tt(always)' to run detection every time -var(vcs_info) is run, and `tt(never)' to turn the detection off entirely. +tt(vcs_info) is run, and `tt(never)' to turn the detection off entirely. If the value of tt(quilt-standalone) is something else, it is interpreted differently. If the value is the name of a scalar variable the value of that @@ -1115,10 +1116,10 @@ startitem() findex(vcs_info) item(tt(vcs_info) [var(user-context)])( The main function, that runs all backends and assembles all data into -var(${vcs_info_msg_*_}). This is the function you want to call from +tt(${vcs_info_msg_*_}). This is the function you want to call from tt(precmd) if you want to include up-to-date information in your prompt (see tt(Variable description) below). If an argument is given, that string will be -used instead of tt(default) in the tt(user-context) field of the style +used instead of tt(default) in the var(user-context) field of the style context. ) findex(vcs_info_hookadd) @@ -1126,7 +1127,7 @@ item(tt(vcs_info_hookadd))( Statically registers a number of functions to a given hook. The hook needs to be given as the first argument; what follows is a list of hook-function names to register to the hook. The `tt(+vi-)' prefix needs to be left out -here. See tt(Hooks in vcs_info) below for details. +here. See bf(Hooks in vcs_info) below for details. ) findex(vcs_info_hookdel) item(tt(vcs_info_hookdel))( @@ -1136,24 +1137,24 @@ names to un-register from the hook. If `tt(-a)' is used as the first argument, tt(all) occurances of the functions are unregistered. Otherwise only the last occurance is removed (if a function was registered to a hook more than once) . The `tt(+vi-)' prefix needs to be left out here. See -tt(Hooks in vcs_info) below for details. +bf(Hooks in vcs_info) below for details. ) findex(vcs_info_lastmsg) item(tt(vcs_info_lastmsg))( -Outputs the last var(${vcs_info_msg_*_}) value. +Outputs the last tt(${vcs_info_msg_*_}) value. Takes into account the value of the tt(use-prompt-escapes) style in -var(':vcs_info:formats:command:-all-'). It also only prints tt(max-exports) +tt(':vcs_info:formats:command:-all-'). It also only prints tt(max-exports) values. ) findex(vcs_info_printsys) item(tt(vcs_info_printsys) [var(user-context)])( Prints a list of all supported version control systems. Useful to find out possible contexts -(and which of them are enabled) or values for the var(disable) style. +(and which of them are enabled) or values for the tt(disable) style. ) findex(vcs_info_setsys) item(tt(vcs_info_setsys))( -Initializes var(vcs_info)'s internal list of +Initializes tt(vcs_info)'s internal list of available backends. With this function, you can add support for new VCSs without restarting the shell. ) @@ -1164,15 +1165,15 @@ All functions named VCS_INFO_* are for internal use only. subsect(Variable Description) startitem() -item(tt(${vcs_info_msg_N_}) (Note the trailing underscore)) +item(tt(${vcs_info_msg_)var(N)tt(_}) (Note the trailing underscore)) ( -Where var(N) is an integer, e.g., var(vcs_info_msg_0_). These variables -are the storage for the informational message the last var(vcs_info) call +Where var(N) is an integer, e.g., tt(vcs_info_msg_0_). These variables +are the storage for the informational message the last tt(vcs_info) call has assembled. These are strongly connected to the tt(formats), tt(actionformats) and tt(nvcsformats) styles described above. Those styles are lists. The first member of that list gets expanded into -var(${vcs_info_msg_0_}), the second into var(${vcs_info_msg_1_}) -and the Nth into var(${vcs_info_msg_N-1_}). These parameters are +tt(${vcs_info_msg_0_}), the second into tt(${vcs_info_msg_1_}) +and the Nth into tt(${vcs_info_msg_N-1_}). These parameters are exported into the environment. (See the tt(max-exports) style above.) ) enditem() @@ -1181,12 +1182,12 @@ All variables named VCS_INFO_* are for internal use only. subsect(Hooks in vcs_info) -Hooks are places in var(vcs_info) where you can run your own code. That +Hooks are places in tt(vcs_info) where you can run your own code. That code can communicate with the code that called it and through that, change the system's behaviour. For configuration, hooks change the style context: -example(:vcs_info:+::) +example(:vcs_info:var(vcs-string)+var(hook-name):var(user-context):var(repo-root-name)) To register functions to a hook, you need to list them in the tt(hooks) style in the appropriate context. @@ -1200,8 +1201,8 @@ a `+vi-', so the actual functions called for the `foo' hook are `tt(+vi-bar)' and `tt(+vi-baz)'. If you would like to register a function to a hook regardless of the -current context, you may use the var(vcs_info_hookadd) function. To remove -a function that was added like that, the var(vcs_info_hookdel) function +current context, you may use the tt(vcs_info_hookadd) function. To remove +a function that was added like that, the tt(vcs_info_hookdel) function can be used. If something seems weird, you can enable the `debug' boolean style in @@ -1212,7 +1213,7 @@ When you register more than one function to a hook, all functions are executed one after another until one function returns non-zero or until all functions have been called. Context-sensitive hook functions are executed tt(before) statically registered ones (the ones added by -var(vcs_info_hookadd)). +tt(vcs_info_hookadd)). You may pass data between functions via an associative array, tt(user_data). For example: @@ -1251,10 +1252,10 @@ Finally, the full list of currently available hooks: startitem() item(tt(start-up))( -Called after starting var(vcs_info) but before the VCS in this directory is -determined. It can be used to deactivate var(vcs_info) temporarily if -necessary. When tt(ret) is set to var(1), var(vcs_info) aborts and does -nothing; when set to var(2), var(vcs_info) sets up everything as if no +Called after starting tt(vcs_info) but before the VCS in this directory is +determined. It can be used to deactivate tt(vcs_info) temporarily if +necessary. When tt(ret) is set to tt(1), tt(vcs_info) aborts and does +nothing; when set to tt(2), tt(vcs_info) sets up everything as if no version control were active and exits. ) item(tt(pre-get-data))( @@ -1265,40 +1266,40 @@ Called in the Mercurial backend when a bookmark string is generated; the tt(get-revision) and tt(get-bookmarks) styles must be true. This hook gets the names of the Mercurial bookmarks that -var(vcs_info) collected from `hg'. +tt(vcs_info) collected from `hg'. When setting tt(ret) to non-zero, the string in -tt(${hook_com[hg-bookmark-string]}) will be used in the var(%m) escape in +tt(${hook_com[hg-bookmark-string]}) will be used in the tt(%m) escape in tt(formats) and tt(actionformats) and will be availabe in the global -var(backend_misc) array as tt(${backend_misc[bookmarks]}). +tt(backend_misc) array as tt(${backend_misc[bookmarks]}). ) item(tt(gen-applied-string))( Called in the tt(git) (with tt(stgit)), and tt(hg) (with tt(mq)) backends -and in tt(quilt) support when the var(applied-string) is generated; the +and in tt(quilt) support when the tt(applied-string) is generated; the tt(use-quilt) zstyle must be true for tt(quilt) (the tt(mq) and tt(stgit) backends are active by default). -This hook gets the names of all applied patches which var(vcs_info) collected +This hook gets the names of all applied patches which tt(vcs_info) collected so far in the opposite order, which means that the first argument is the top-most patch and so forth. When setting tt(ret) to non-zero, the string in -tt(${hook_com[applied-string]}) will be used in the var(%m) escape in +tt(${hook_com[applied-string]}) will be used in the tt(%m) escape in tt(formats) and tt(actionformats); it will be available in the global -var(backend_misc) array as tt($backend_misc[patches]}); and it will be -available as var(%p) in the tt(patch-format) and tt(nopatch-format) styles. +tt(backend_misc) array as tt($backend_misc[patches]}); and it will be +available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles. ) item(tt(gen-unapplied-string))( Called in the tt(git) (with tt(stgit)), and tt(hg) (with tt(mq)) backend -and in tt(quilt) support when the var(unapplied-string) is generated; the +and in tt(quilt) support when the tt(unapplied-string) is generated; the tt(get-unapplied) style must be true. -This hook gets the names of all unapplied patches which var(vcs_info) +This hook gets the names of all unapplied patches which tt(vcs_info) collected so far in the opposite order, which mean that the first argument is the patch next-in-line to be applied and so forth. When setting tt(ret) to non-zero, the string in -tt(${hook_com[unapplied-string]}) will be available as var(%u) in the +tt(${hook_com[unapplied-string]}) will be available as tt(%u) in the tt(patch-format) and tt(nopatch-format) styles. ) item(tt(gen-mqguards-string))( @@ -1308,7 +1309,7 @@ tt(get-mq) style must be true (default). This hook gets the names of any active tt(mq) guards. When setting tt(ret) to non-zero, the string in -tt(${hook_com[guards-string]}) will be used in the var(%g) escape in the +tt(${hook_com[guards-string]}) will be used in the tt(%g) escape in the tt(patch-format) and tt(nopatch-format) styles. ) item(tt(no-vcs))( @@ -1330,24 +1331,24 @@ Called before `tt(branchformat)' is set. The only argument to the hook is the format that is configured at this point. The `tt(hook_com)' keys considered are `tt(branch)' and `tt(revision)'. -They are set to the values figured out so far by var(vcs_info) and any +They are set to the values figured out so far by tt(vcs_info) and any change will be used directly when the actual replacement is done. If tt(ret) is set to non-zero, the string in tt(${hook_com[branch-replace]}) will be used unchanged as the -`tt(%b)' replacement in the variables set by var(vcs_info). +`tt(%b)' replacement in the variables set by tt(vcs_info). ) item(tt(set-hgrev-format))( Called before a `tt(hgrevformat)' is set. The only argument to the hook is the format that is configured at this point. The `tt(hook_com)' keys considered are `tt(hash)' and `tt(localrev)'. -They are set to the values figured out so far by var(vcs_info) and any +They are set to the values figured out so far by tt(vcs_info) and any change will be used directly when the actual replacement is done. If tt(ret) is set to non-zero, the string in tt(${hook_com[rev-replace]}) will be used unchanged as the -`tt(%i)' replacement in the variables set by var(vcs_info). +`tt(%i)' replacement in the variables set by tt(vcs_info). ) item(tt(set-message))( Called each time before a `tt(vcs_info_msg_N_)' message is set. @@ -1360,7 +1361,7 @@ There are a number of `tt(hook_com)' keys, that are used here: `tt(staged)', `tt(unstaged)', `tt(revision)', `tt(misc)', `tt(vcs)' and one `tt(miscN)' entry for each backend-specific data field (tt(N) starting at zero). They are set to the values figured out so far by -var(vcs_info) and any change will be used directly when the actual +tt(vcs_info) and any change will be used directly when the actual replacement is done. Since this hook is triggered multiple times (once for each configured @@ -1372,7 +1373,7 @@ probably not a good idea. If tt(ret) is set to non-zero, the string in tt(${hook_com[message]}) will be used unchanged as the message by -var(vcs_info). +tt(vcs_info). ) enditem() @@ -1382,7 +1383,7 @@ They contain some explanatory code. subsect(Examples) -Don't use var(vcs_info) at all (even though it's in your prompt): +Don't use tt(vcs_info) at all (even though it's in your prompt): example(zstyle ':vcs_info:*' enable NONE) Disable the backends for tt(bzr) and tt(svk): @@ -1415,7 +1416,7 @@ Display the revision number in yellow for tt(bzr) and tt(svn): example(zstyle ':vcs_info:(svn|bzr):*' branchformat '%b%{'${fg[yellow]}'%}:%r') If you want colors, make sure you enclose the color codes in tt(%{...%}) -if you want to use the string provided by var(vcs_info) in prompts. +if you want to use the string provided by tt(vcs_info) in prompts. Here is how to print the VCS information as a command (not in a prompt): example(alias vcsi='vcs_info command; vcs_info_lastmsg') @@ -1425,9 +1426,9 @@ tt(vcs_info_lastmsg) in the ':vcs_info:*:command:*' namespace. Now as promised, some code that uses hooks: say, you'd like to replace the string `svn' by `subversion' in -var(vcs_info)'s tt(%s) tt(formats) replacement. +tt(vcs_info)'s tt(%s) tt(formats) replacement. -First, we will tell var(vcs_info) to call a function when populating +First, we will tell tt(vcs_info) to call a function when populating the message variables with the gathered information: example(zstyle ':vcs_info:*+set-message:*' hooks svn2subversion) @@ -1503,7 +1504,7 @@ Some longer examples and code snippets which might be useful are available in the examples file located at Misc/vcs_info-examples in the Zsh source directory. -This concludes our guided tour through zsh's var(vcs_info). +This concludes our guided tour through zsh's tt(vcs_info). texinode(Prompt Themes)(ZLE Functions)(Version Control Information)(User Contributions) -- cgit v1.2.3 From 42a260df99eabfc3ab34e0320670c36540c8d300 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Thu, 2 Jun 2011 16:15:23 +0000 Subject: 29434: contrib.yo: Use PLUS() to avoid a + being silently dropped. --- ChangeLog | 7 ++++++- Doc/Zsh/contrib.yo | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index a58e6cea9..2c9bed84c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-02 Frank Terbeck + + * 29434: Doc/Zsh/contrib.yo: Use PLUS() to avoid a + being + silently dropped. + 2011-06-01 Frank Terbeck * 29412: Completion/Unix/Command/_tmux: Disable sub-command @@ -14920,5 +14925,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5354 $ +* $Revision: 1.5355 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 9bb7dcf45..2b55b36f0 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1187,7 +1187,7 @@ code can communicate with the code that called it and through that, change the system's behaviour. For configuration, hooks change the style context: -example(:vcs_info:var(vcs-string)+var(hook-name):var(user-context):var(repo-root-name)) +example(:vcs_info:var(vcs-string)PLUS()var(hook-name):var(user-context):var(repo-root-name)) To register functions to a hook, you need to list them in the tt(hooks) style in the appropriate context. -- cgit v1.2.3 From 12e246495c2f40ca289b27a552d548318f255472 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 3 Jun 2011 19:54:43 +0000 Subject: 29413: "print -S" for saving to history with lexical word split --- ChangeLog | 8 +- Doc/Zsh/builtins.yo | 11 ++- Src/builtin.c | 44 +++++++--- Src/hist.c | 239 ++++++++++++++++++++++++++++++---------------------- 4 files changed, 187 insertions(+), 115 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2c9bed84c..abc2736e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-03 Peter Stephenson + + * 29413: Doc/Zsh/builtins.yo, Src/builtin.c, Src/hist.c: print + -S takes a single argument, applies lexical history word + splitting, and puts it on the history. + 2011-06-02 Frank Terbeck * 29434: Doc/Zsh/contrib.yo: Use PLUS() to avoid a + being @@ -14925,5 +14931,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5355 $ +* $Revision: 1.5356 $ ***************************************************** diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 7170b13b9..5d717479a 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -914,7 +914,7 @@ and the new directory stack is not printed. This is useful for calls to tt(popd) that do not change the environment seen by an interactive user. ) findex(print) -xitem(tt(print) [ tt(-abcDilmnNoOpPrsz) ] [ tt(-u) var(n) ] [ tt(-f) var(format) ] [ tt(-C) var(cols) ]) +xitem(tt(print) [ tt(-abcDilmnNoOpPrsSz) ] [ tt(-u) var(n) ] [ tt(-f) var(format) ] [ tt(-C) var(cols) ]) item( [ tt(-R) [ tt(-en) ]] [ var(arg) ... ])( With the `tt(-f)' option the arguments are printed as described by tt(printf). With no flags or with the flag `tt(-)', the arguments are printed on @@ -994,6 +994,15 @@ tt(-R); all other arguments and options are printed. ) item(tt(-s))( Place the results in the history list instead of on the standard output. +Each argument to the tt(print) command is treated as a single word in the +history, regardless of its content. +) +item(tt(-S))( +Place the results in the history list instead of on the standard output. +In this case only a single argument is allowed; it will be split into +words as if it were a full shell command line. The effect is +similar to reading the line from a history file with the +tt(HIST_LEX_WORDS) option active. ) item(tt(-u) var(n))( Print the arguments to file descriptor var(n). diff --git a/Src/builtin.c b/Src/builtin.c index fc98eb1b1..9b34ef7c0 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -99,7 +99,7 @@ static struct builtin builtins[] = #endif BUILTIN("popd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 1, BIN_POPD, "q", NULL), - BUILTIN("print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "abcC:Df:ilmnNoOpPrRsu:z-", NULL), + BUILTIN("print", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, "abcC:Df:ilmnNoOpPrRsSu:z-", NULL), BUILTIN("printf", 0, bin_print, 1, -1, BIN_PRINTF, NULL, NULL), BUILTIN("pushd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_PUSHD, "qsPL", NULL), BUILTIN("pushln", 0, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"), @@ -3965,25 +3965,45 @@ bin_print(char *name, char **args, Options ops, int func) return 0; } /* -s option -- add the arguments to the history list */ - if (OPT_ISSET(ops,'s')) { + if (OPT_ISSET(ops,'s') || OPT_ISSET(ops,'S')) { int nwords = 0, nlen, iwords; char **pargs = args; queue_signals(); - ent = prepnexthistent(); while (*pargs++) nwords++; - if ((ent->nwords = nwords)) { - ent->words = (short *)zalloc(nwords*2*sizeof(short)); - nlen = iwords = 0; - for (pargs = args; *pargs; pargs++) { - ent->words[iwords++] = nlen; - nlen += strlen(*pargs); - ent->words[iwords++] = nlen; - nlen++; + if (nwords) { + if (OPT_ISSET(ops,'S')) { + int wordsize; + short *words; + if (nwords > 1) { + zwarnnam(name, "option -S takes a single argument"); + return 1; + } + words = NULL; + wordsize = 0; + histsplitwords(*args, &words, &wordsize, &nwords, 1); + ent = prepnexthistent(); + ent->words = (short *)zalloc(nwords*sizeof(short)); + memcpy(ent->words, words, nwords*sizeof(short)); + free(words); + ent->nwords = nwords/2; + } else { + ent = prepnexthistent(); + ent->words = (short *)zalloc(nwords*2*sizeof(short)); + ent->nwords = nwords; + nlen = iwords = 0; + for (pargs = args; *pargs; pargs++) { + ent->words[iwords++] = nlen; + nlen += strlen(*pargs); + ent->words[iwords++] = nlen; + nlen++; + } } - } else + } else { + ent = prepnexthistent(); ent->words = (short *)NULL; + } ent->node.nam = zjoin(args, ' ', 0); ent->stim = ent->ftim = time(NULL); ent->node.flags = 0; diff --git a/Src/hist.c b/Src/hist.c index 01a97da2b..87bfde882 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2338,110 +2338,11 @@ readhistfile(char *fn, int err, int readflags) /* * Divide up the words. */ - nwordpos = 0; start = pt; uselex = isset(HISTLEXWORDS) && !(readflags & HFILE_FAST); - if (uselex) { - /* - * Attempt to do this using the lexer. - */ - LinkList wordlist = bufferwords(NULL, pt, NULL, - LEXFLAGS_COMMENTS_KEEP); - LinkNode wordnode; - int nwords_max; - nwords_max = 2 * countlinknodes(wordlist); - if (nwords_max > nwords) { - nwords = nwords_max; - words = (short *)realloc(words, nwords*sizeof(short)); - } - for (wordnode = firstnode(wordlist); - wordnode; - incnode(wordnode)) { - char *word = getdata(wordnode); - - for (;;) { - /* - * Not really an oddity: "\\\n" is - * removed from input as if whitespace. - */ - if (inblank(*pt)) - pt++; - else if (pt[0] == '\\' && pt[1] == '\n') - pt += 2; - else - break; - } - if (!strpfx(word, pt)) { - int bad = 0; - /* - * Oddity 1: newlines turn into semicolons. - */ - if (!strcmp(word, ";")) - continue; - while (*pt) { - if (!*word) { - bad = 1; - break; - } - /* - * Oddity 2: !'s turn into |'s. - */ - if (*pt == *word || - (*pt == '!' && *word == '|')) { - pt++; - word++; - } else { - bad = 1; - break; - } - } - if (bad) { -#ifdef DEBUG - dputs(ERRMSG("bad wordsplit reading history: " - "%s\nat: %s\nword: %s"), - start, pt, word); -#endif - pt = start; - nwordpos = 0; - uselex = 0; - break; - } - } else if (!strcmp(word, ";") && strpfx(";;", pt)) { - /* - * Don't get confused between a semicolon that's - * probably really a newline and a double - * semicolon that's terminating a case. - */ - continue; - } - words[nwordpos++] = pt - start; - pt += strlen(word); - words[nwordpos++] = pt - start; - } + histsplitwords(pt, &words, &nwords, &nwordpos, uselex); + if (uselex) freeheap(); - } - if (!uselex) { - do { - for (;;) { - if (inblank(*pt)) - pt++; - else if (pt[0] == '\\' && pt[1] == '\n') - pt += 2; - else - break; - } - if (*pt) { - if (nwordpos >= nwords) - words = (short *) - realloc(words, (nwords += 64)*sizeof(short)); - words[nwordpos++] = pt - start; - while (*pt && !inblank(*pt)) - pt++; - words[nwordpos++] = pt - start; - } - } while (*pt); - - } he->nwords = nwordpos/2; if (he->nwords) { @@ -3141,6 +3042,142 @@ bufferwords(LinkList list, char *buf, int *index, int flags) return list; } +/* + * Split up a line into words for use in a history file. + * + * lineptr is the line to be split. + * + * *wordsp and *nwordsp are an array already allocated to hold words + * and its length. The array holds both start and end positions, + * so *nwordsp actually counts twice the number of words in the + * original string. *nwordsp may be zero in which case the array + * will be allocated. + * + * *nwordposp returns the used length of *wordsp in the same units as + * *nwordsp, i.e. twice the number of words in the input line. + * + * If uselex is 1, attempt to do this using the lexical analyser. + * This is more accurate, but slower; for reading history files it's + * controlled by the option HISTLEXWORDS. If this failed (which + * indicates a bug in the shell) it falls back to whitespace-separated + * strings, printing a message if in debug mode. + * + * If uselex is 0, just look for whitespace-separated words; the only + * special handling is for a backslash-newline combination as used + * by the history file format to save multiline buffers. + */ +/**/ +mod_export void +histsplitwords(char *lineptr, short **wordsp, int *nwordsp, int *nwordposp, + int uselex) +{ + int nwords = *nwordsp, nwordpos = 0; + short *words = *wordsp; + char *start = lineptr; + + if (uselex) { + LinkList wordlist = bufferwords(NULL, lineptr, NULL, + LEXFLAGS_COMMENTS_KEEP); + LinkNode wordnode; + int nwords_max; + + nwords_max = 2 * countlinknodes(wordlist); + if (nwords_max > nwords) { + *nwordsp = nwords = nwords_max; + *wordsp = words = (short *)zrealloc(words, nwords*sizeof(short)); + } + for (wordnode = firstnode(wordlist); + wordnode; + incnode(wordnode)) { + char *word = getdata(wordnode); + + for (;;) { + /* + * Not really an oddity: "\\\n" is + * removed from input as if whitespace. + */ + if (inblank(*lineptr)) + lineptr++; + else if (lineptr[0] == '\\' && lineptr[1] == '\n') + lineptr += 2; + else + break; + } + if (!strpfx(word, lineptr)) { + int bad = 0; + /* + * Oddity 1: newlines turn into semicolons. + */ + if (!strcmp(word, ";")) + continue; + while (*lineptr) { + if (!*word) { + bad = 1; + break; + } + /* + * Oddity 2: !'s turn into |'s. + */ + if (*lineptr == *word || + (*lineptr == '!' && *word == '|')) { + lineptr++; + word++; + } else { + bad = 1; + break; + } + } + if (bad) { +#ifdef DEBUG + dputs(ERRMSG("bad wordsplit reading history: " + "%s\nat: %s\nword: %s"), + start, lineptr, word); +#endif + lineptr = start; + nwordpos = 0; + uselex = 0; + break; + } + } else if (!strcmp(word, ";") && strpfx(";;", lineptr)) { + /* + * Don't get confused between a semicolon that's + * probably really a newline and a double + * semicolon that's terminating a case. + */ + continue; + } + words[nwordpos++] = lineptr - start; + lineptr += strlen(word); + words[nwordpos++] = lineptr - start; + } + } + if (!uselex) { + do { + for (;;) { + if (inblank(*lineptr)) + lineptr++; + else if (lineptr[0] == '\\' && lineptr[1] == '\n') + lineptr += 2; + else + break; + } + if (*lineptr) { + if (nwordpos >= nwords) { + *nwordsp = nwords = nwords + 64; + *wordsp = words = (short *) + zrealloc(words, nwords*sizeof(*words)); + } + words[nwordpos++] = lineptr - start; + while (*lineptr && !inblank(*lineptr)) + lineptr++; + words[nwordpos++] = lineptr - start; + } + } while (*lineptr); + } + + *nwordposp = nwordpos; +} + /* Move the current history list out of the way and prepare a fresh history * list using hf for HISTFILE, hs for HISTSIZE, and shs for SAVEHIST. If * the hf value is an empty string, HISTFILE will be unset from the new -- cgit v1.2.3 From 4e556ac875effee0ecdbc1e0a35cba496d6e037c Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 14 Jun 2011 18:59:23 +0000 Subject: unposted: document change to brace parameter completion context in 29452/29459 --- ChangeLog | 15 ++++++++++----- Doc/Zsh/compwid.yo | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2230d696d..50b31765d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-06-14 Peter Stephenson + + * unposted: Doc/Zsh/compwid.yo: document change to brace + parameter context in 29452/29459. + 2011-06-12 Barton E. Schaefer * 29472: Src/jobs.c: findproc() needs at least to also return @@ -27,10 +32,10 @@ 2011-06-04 Peter Stephenson - * Completion/Zsh/Context/_brace_parameter, Src/Zle/compcore.c - (check_param): In shell function, check for ${( not at start - of match; in C code, check for untokenized parentheses when - in double quotes. + * 29459: Completion/Zsh/Context/_brace_parameter, + Src/Zle/compcore.c (check_param): In shell function, check for + ${( not at start of match; in C code, check for untokenized + parentheses when in double quotes. 2011-06-03 Peter Stephenson @@ -14985,5 +14990,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5368 $ +* $Revision: 1.5369 $ ***************************************************** diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo index 3042fa373..37a568f58 100644 --- a/Doc/Zsh/compwid.yo +++ b/Doc/Zsh/compwid.yo @@ -162,7 +162,10 @@ this case the tt(words) array contains the words inside the parentheses. ) item(tt(brace_parameter))( when completing the name of a parameter in a parameter expansion beginning -with tt(${). +with tt(${). This context will also be set when completing parameter +flags following tt(${LPAR()); the full command line argument is presented +and the handler must test the value to be completed to ascertain that +this is the case. ) item(tt(assign_parameter))( when completing the name of a parameter in a parameter assignment. -- cgit v1.2.3 From 6062529d3fc7c7d29c63d0726d2449d4b56f33ac Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 19 Jun 2011 20:12:00 +0000 Subject: 29492: add argument handling to anonymous functions --- ChangeLog | 5 +++- Doc/Zsh/func.yo | 14 +++++++---- Src/exec.c | 65 ++++++++++++++++++++++++++++++---------------------- Src/parse.c | 30 ++++++++++++++++++++++-- Src/text.c | 30 +++++++++++++++++++++--- Test/C04funcdef.ztst | 29 ++++++++++++++++++++++- 6 files changed, 133 insertions(+), 40 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 446bff14b..8eca2d9cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2011-06-19 Peter Stephenson + * 29492: Doc/Zsh/func.yo, Src/exec.c, Src/parse.c, Src/text.c, + Test/C04funcdef.ztst: add argument handling to anonymous functions. + * unposted: Src/Zle/zle_refresh.c: remove additional loop noticed by Mikael. @@ -15019,5 +15022,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5375 $ +* $Revision: 1.5376 $ ***************************************************** diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo index 28bc6329a..89b956cb4 100644 --- a/Doc/Zsh/func.yo +++ b/Doc/Zsh/func.yo @@ -158,9 +158,13 @@ If no name is given for a function, it is `anonymous' and is handled specially. Either form of function definition may be used: a `tt(())' with no preceding name, or a `tt(function)' with an immediately following open brace. The function is executed immediately at the point of definition and -is not stored for future use. The function name is set to `tt((anon))' and -the parameter list passed to the function is empty. Note that this means +is not stored for future use. The function name is set to `tt((anon))'. + +Arguments to the function may be specified as words following the +closing brace defining the function, hence if there are none no +arguments (other than tt($0)) are set. Note that this means the argument list of any enclosing script or function is hidden. + Redirections may be applied to the anonymous function in the same manner as to a current-shell structure enclosed in braces. The main use of anonymous functions is to provide a scope for local variables. This is particularly @@ -172,13 +176,13 @@ For example, example(variable=outside function { local variable=inside - print "I am $variable" -} + print "I am $variable with arguments $*" +} this and that print "I am $variable") outputs the following: -example(I am inside +example(I am inside with arguments this and that I am outside) Note that function definitions with arguments that expand to nothing, diff --git a/Src/exec.c b/Src/exec.c index 2558185c8..87a167ba6 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -50,20 +50,20 @@ int noerrexit; * noerrs = 1: suppress error messages * noerrs = 2: don't set errflag on parse error, either */ - + /**/ mod_export int noerrs; - + /* do not save history on exec and exit */ /**/ int nohistsave; - + /* error/break flag */ - + /**/ mod_export int errflag; - + /* * State of trap return value. Value is from enum trap_state. */ @@ -88,23 +88,23 @@ int trap_state; * - non-negative in a trap once it was triggered. It should remain * non-negative until restored after execution of the trap. */ - + /**/ int trap_return; - + /* != 0 if this is a subshell */ - + /**/ int subsh; - + /* != 0 if we have a return pending */ - + /**/ mod_export int retflag; /**/ long lastval2; - + /* The table of file descriptors. A table element is zero if the * * corresponding fd is not used by the shell. It is greater than * * 1 if the fd is used by a <(...) or >(...) substitution and 1 if * @@ -148,12 +148,12 @@ int fdtable_flocks; mod_export int zleactive; /* pid of process undergoing 'process substitution' */ - + /**/ pid_t cmdoutpid; - + /* exit status of process undergoing 'process substitution' */ - + /**/ int cmdoutval; @@ -166,7 +166,7 @@ int cmdoutval; /**/ int use_cmdoutval; -/* The context in which a shell function is called, see SFC_* in zsh.h. */ +/* The context in which a shell function is called, see SFC_* in zsh.h. */ /**/ mod_export int sfcontext; @@ -239,7 +239,7 @@ parse_string(char *s, int reset_lineno) /**/ mod_export struct rlimit current_limits[RLIM_NLIMITS], limits[RLIM_NLIMITS]; - + /**/ mod_export int zsetlimit(int limnum, char *nam) @@ -340,7 +340,7 @@ zfork(struct timeval *tv) * * (when waiting for the grep, ignoring execpline2 for now). At this time, * zsh has built two job-table entries for it: one for the cat and one for - * the grep. If the user hits ^Z at this point (and jobbing is used), the + * the grep. If the user hits ^Z at this point (and jobbing is used), the * shell is notified that the grep was suspended. The list_pipe flag is * used to tell the execpline where it was waiting that it was in a pipeline * with a shell construct at the end (which may also be a shell function or @@ -351,7 +351,7 @@ zfork(struct timeval *tv) * shell (its pid and the text for it) in the job entry of the cat. The pid * is passed down in the list_pipe_pid variable. * But there is a problem: the suspended grep is a child of the parent shell - * and can't be adopted by the sub-shell. So the parent shell also has to + * and can't be adopted by the sub-shell. So the parent shell also has to * keep the information about this process (more precisely: this pipeline) * by keeping the job table entry it created for it. The fact that there * are two jobs which have to be treated together is remembered by setting @@ -528,10 +528,10 @@ isgooderr(int e, char *dir) { /* * Maybe the directory was unreadable, or maybe it wasn't - * even a directory. + * even a directory. */ return ((e != EACCES || !access(dir, X_OK)) && - e != ENOENT && e != ENOTDIR); + e != ENOENT && e != ENOTDIR); } /* @@ -639,7 +639,7 @@ execute(LinkList args, int flags, int defpath) break; } - /* for command -p, search the default path */ + /* for command -p, search the default path */ if (defpath) { char *s, pbuf[PATH_MAX]; char *dptr, *pe, *ps = DEFAULT_PATH; @@ -676,7 +676,7 @@ execute(LinkList args, int flags, int defpath) eno = ee; } else { - + if ((cn = (Cmdnam) cmdnamtab->getnode(cmdnamtab, arg0))) { char nn[PATH_MAX], *dptr; @@ -1312,9 +1312,9 @@ sublist_done: donetrap = 1; } if (lastval) { - int errreturn = isset(ERRRETURN) && + int errreturn = isset(ERRRETURN) && (isset(INTERACTIVE) || locallevel || sourcelevel); - int errexit = isset(ERREXIT) || + int errexit = isset(ERREXIT) || (isset(ERRRETURN) && !errreturn); if (errexit) { if (sigtrapped[SIGEXIT]) @@ -1536,7 +1536,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) else if (pid) { char dummy; - lpforked = + lpforked = (killpg(jobtab[list_pipe_job].gleader, 0) == -1 ? 2 : 1); list_pipe_pid = pid; list_pipe_start = bgtime; @@ -3112,7 +3112,7 @@ execcmd(Estate state, int input, int output, int how, int last1) ESUB_PGRP | ESUB_FAKE; if (type != WC_SUBSH) flags |= ESUB_KEEPTRAP; - if ((do_exec || (type >= WC_CURSH && last1 == 1)) + if ((do_exec || (type >= WC_CURSH && last1 == 1)) && !forked) flags |= ESUB_REVERTPGRP; entersubsh(flags); @@ -4184,10 +4184,19 @@ execfuncdef(Estate state, UNUSED(int do_exec)) * Anonymous function, execute immediately. * Function name is "(anon)", parameter list is empty. */ - LinkList args = newlinklist(); + LinkList args; + + state->pc = end; + end += *state->pc++; + args = ecgetlist(state, *state->pc++, EC_DUPTOK, &htok); + + if (htok && args) + execsubst(args); + if (!args) + args = newlinklist(); shf->node.nam = "(anon)"; - addlinknode(args, shf->node.nam); + pushnode(args, shf->node.nam); execshfunc(shf, args); ret = lastval; diff --git a/Src/parse.c b/Src/parse.c index 4720dc3cf..5b6f09949 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1480,12 +1480,25 @@ par_funcdef(void) ecbuf[p + num + 4] = ecnpats; ecbuf[p + 1] = num; - lineno += oldlineno; ecnpats = onp; ecssub = oecssub; ecnfunc++; ecbuf[p] = WCB_FUNCDEF(ecused - 1 - p); + + if (num == 0) { + /* Unnamed function */ + int parg = ecadd(0); + ecadd(0); + while (tok == STRING) { + ecstr(tokstr); + num++; + zshlex(); + } + ecbuf[parg] = ecused - parg; /*?*/ + ecbuf[parg+1] = num; + } + lineno += oldlineno; } /* @@ -1730,13 +1743,26 @@ par_simple(int *complex, int nr) ecbuf[p + argc + 3] = ecsoffs - so; ecbuf[p + argc + 4] = ecnpats; - lineno += oldlineno; ecnpats = onp; ecssub = oecssub; ecnfunc++; ecbuf[p] = WCB_FUNCDEF(ecused - 1 - p); + if (argc == 0) { + /* Unnamed function */ + int parg = ecadd(0); + ecadd(0); + while (tok == STRING) { + ecstr(tokstr); + argc++; + zshlex(); + } + ecbuf[parg] = ecused - parg; /*?*/ + ecbuf[parg+1] = argc; + } + lineno += oldlineno; + isfunc = 1; isnull = 0; break; diff --git a/Src/text.c b/Src/text.c index 669037a2d..f55553ed0 100644 --- a/Src/text.c +++ b/Src/text.c @@ -253,6 +253,7 @@ struct tstack { struct { char *strs; Wordcode end; + int nargs; } _funcdef; struct { Wordcode end; @@ -456,19 +457,31 @@ gettext2(Estate state) if (!s) { Wordcode p = state->pc; Wordcode end = p + WC_FUNCDEF_SKIP(code); + int nargs = *state->pc++; - taddlist(state, *state->pc++); + taddlist(state, nargs); + if (nargs) + taddstr(" "); if (tjob) { - taddstr(" () { ... }"); + taddstr("() { ... }"); state->pc = end; + if (!nargs) { + /* + * Unnamed fucntion. + * We're not going to pull any arguments off + * later, so skip them now... + */ + state->pc += *end; + } stack = 1; } else { - taddstr(" () {"); + taddstr("() {"); tindent++; taddnl(1); n = tpush(code, 1); n->u._funcdef.strs = state->strs; n->u._funcdef.end = end; + n->u._funcdef.nargs = nargs; state->strs += *state->pc; state->pc += 3; } @@ -478,6 +491,17 @@ gettext2(Estate state) dec_tindent(); taddnl(0); taddstr("}"); + if (s->u._funcdef.nargs == 0) { + /* Unnamed function with post-arguments */ + int nargs; + s->u._funcdef.end += *state->pc++; + nargs = *state->pc++; + if (nargs) { + taddstr(" "); + taddlist(state, nargs); + } + state->pc = s->u._funcdef.end; + } stack = 1; } break; diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index f71e5ce77..0cc5e5a2f 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -26,7 +26,7 @@ print regress expansion of function names } f$$ -0:Regression test: `function f$$ () { ... }' +0:Regression test: 'function f$$ () { ... }' >regress expansion of function names function foo () print bar @@ -109,6 +109,8 @@ >really useful >args +# ' deconfuse emacs + command_not_found_handler() { print "Your command:" >&2 print "$1" >&2 @@ -201,6 +203,31 @@ >Da de da >Do be do + () { print This has arguments $*; } of all sorts; print After the function + function { print More stuff $*; } and why not; print Yet more +0:Anonymous function with arguments +>This has arguments of all sorts +>After the function +>More stuff and why not +>Yet more + + fn() { + (){ print Anonymous function 1 $*; } with args + function { print Anonymous function 2 $*; } with more args + print Following bit + } + functions fn +0:Text representation of anonymous function with arguments +>fn () { +> () { +> print Anonymous function 1 $* +> } with args +> () { +> print Anonymous function 2 $* +> } with more args +> print Following bit +>} + %clean rm -f file.in file.out -- cgit v1.2.3 From d8177def3f0cee762784e600b32f340952815fbd Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 25 Jun 2011 11:55:58 +0000 Subject: Axel Beckert: 29506: use form SINGLE_LINE_ZLE in manual --- Doc/Zsh/params.yo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 22a00f5c2..c46d85bcd 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1226,7 +1226,7 @@ vindex(RPS1) item(tt(RPS1) )( This prompt is displayed on the right-hand side of the screen when the primary prompt is being displayed on the left. -This does not work if the tt(SINGLELINEZLE) option is set. +This does not work if the tt(SINGLE_LINE_ZLE) option is set. It is expanded in the same way as tt(PS1). ) vindex(RPROMPT2) @@ -1235,7 +1235,7 @@ vindex(RPS2) item(tt(RPS2) )( This prompt is displayed on the right-hand side of the screen when the secondary prompt is being displayed on the left. -This does not work if the tt(SINGLELINEZLE) option is set. +This does not work if the tt(SINGLE_LINE_ZLE) option is set. It is expanded in the same way as tt(PS2). ) vindex(SAVEHIST) -- cgit v1.2.3 From 3dfa00a58368e623eb1985228e5a4b7e381986d9 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Sun, 3 Jul 2011 11:54:11 +0000 Subject: unposted: contrib.yo: Fix typo "paramter" to. Caught by debian's lintian. --- ChangeLog | 7 ++++++- Doc/Zsh/contrib.yo | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 29e0a6e3b..13cc12a83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-07-03 Frank Terbeck + + * unposted: Doc/Zsh/contrib.yo: Fix typo "paramter" to. Caught by + debian's lintian. + 2011-07-01 Peter Stephenson * 29530: Src/subst.c, Test/E01options.ztst: ${..?..} shouldn't @@ -15087,5 +15092,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5391 $ +* $Revision: 1.5392 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 2b55b36f0..05bbcd7ec 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2356,7 +2356,7 @@ This is similar to read-from-minibuffer in that it may be called as a function from a widget or as a widget of its own, and interactively reads input from the keyboard. However, the input being typed is concealed and a string of asterisks (`tt(*)') is shown instead. The value is saved in -the paramter tt($INVISIBLE) to which a reference is inserted into the +the parameter tt($INVISIBLE) to which a reference is inserted into the editing buffer at the restored cursor position. If the read was aborted by a keyboard break (typically tt(^G)) or another escape from editing such as tt(push-line), tt($INVISIBLE) is set to empty and the original buffer -- cgit v1.2.3 From 6844a63daf3e372e99dc6722304dc9cc4fcc5095 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 28 Jul 2011 09:18:34 +0000 Subject: 29602 etc. etc.: description of filename extension --- ChangeLog | 8 +++++++- Doc/Zsh/expn.yo | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 4e2eb33b2..4edc62b61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-07-28 Peter Stephenson + + * 29602 and subsequent changes: Doc/Zsh/expn.yo: clarify meaning + of filename extension in :r and :e modifiers (which were + slightly inconsistent). + 2011-07-27 Peter Stephenson * 29561: Test/A04redirect.ztst: this bit didn't get committed, @@ -15170,5 +15176,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5409 $ +* $Revision: 1.5410 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index ce122cade..7060a49b4 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -236,7 +236,10 @@ a glob qualifier unless a file of the same name is found in the current directory. ) item(tt(e))( -Remove all but the extension. +Remove all but the part of the filename extension following the `tt(.)'; +see the definition of the filename extension in the description of the +tt(r) modifier below. Note that according to that definition the result +will be empty if the string ends with a `tt(.)'. ) item(tt(h))( Remove a trailing pathname component, leaving the head. This works @@ -259,8 +262,12 @@ item(tt(Q))( Remove one level of quotes from the substituted words. ) item(tt(r))( -Remove a filename extension of the form `tt(.)var(xxx)', leaving -the root name. +Remove a filename extension leaving the root name. Strings with no +filename extension are not altered. A filename +extension is a `tt(.)' followed by any number of characters (including +zero) that are neither `tt(.)' nor `tt(/)' and that continue to the end +of the string. For example, the extension of +`tt(foo.orig.c)' is `tt(.c)', and `tt(dir.c/foo)' has no extension. ) item(tt(s/)var(l)tt(/)var(r)[tt(/)])( Substitute var(r) for var(l) as described below. -- cgit v1.2.3 From d48faef8cdff3c7c63c0a9164443e3d337aa1ec1 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 3 Aug 2011 18:45:17 +0000 Subject: 29633: more care with anonymous and other functions --- ChangeLog | 8 +++++++- Doc/Zsh/func.yo | 11 +++++++++-- Src/parse.c | 10 ++++++++-- Test/C04funcdef.ztst | 6 ++++++ 4 files changed, 30 insertions(+), 5 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 3c0265440..c6209fca0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-08-03 Peter Stephenson + + * 29633: Doc/Zsh/func.yo, Src/parse.c, Test/C04funcdef.ztst: be + more careful that anonymous function syntax doesn't mess up + working syntax with other functions. + 2011-08-03 Peter Stephenson * 29635: Completion/Base/Widget/_complete_debug: Improve file @@ -15189,5 +15195,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5413 $ +* $Revision: 1.5414 $ ***************************************************** diff --git a/Doc/Zsh/func.yo b/Doc/Zsh/func.yo index 89b956cb4..7c391f80d 100644 --- a/Doc/Zsh/func.yo +++ b/Doc/Zsh/func.yo @@ -162,8 +162,15 @@ is not stored for future use. The function name is set to `tt((anon))'. Arguments to the function may be specified as words following the closing brace defining the function, hence if there are none no -arguments (other than tt($0)) are set. Note that this means -the argument list of any enclosing script or function is hidden. +arguments (other than tt($0)) are set. This is a difference from the +way other functions are parsed: normal function definitions may be +followed by certain keywords such as `tt(else)' or `tt(fi)', which will +be treated as arguments to anonymous functions, so that a newline or +semicolon is needed to force keyword interpretation. + +Note also that the argument list of any enclosing script or function is +hidden (as would be the case for any other function called at this +point). Redirections may be applied to the anonymous function in the same manner as to a current-shell structure enclosed in braces. The main use of anonymous diff --git a/Src/parse.c b/Src/parse.c index 5b8f0af48..e4d038b6e 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1465,7 +1465,10 @@ par_funcdef(void) ecssub = oecssub; YYERRORV(oecused); } - incmdpos = 0; + if (num == 0) { + /* Anonymous function, possibly with arguments */ + incmdpos = 0; + } zshlex(); } else if (unset(SHORTLOOPS)) { lineno += oldlineno; @@ -1721,7 +1724,10 @@ par_simple(int *complex, int nr) ecssub = oecssub; YYERROR(oecused); } - incmdpos = 0; + if (argc == 0) { + /* Anonymous function, possibly with arguments */ + incmdpos = 0; + } zshlex(); } else { int ll, sl, c = 0; diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index 742d2d0a7..90f01e397 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -245,6 +245,12 @@ >empty >here + if true; then f() { echo foo1; } else f() { echo bar1; } fi; f + if false; then f() { echo foo2; } else f() { echo bar2; } fi; f +0:Compatibility with other shells when not anonymous functions +>foo1 +>bar2 + %clean rm -f file.in file.out -- cgit v1.2.3 From e7f198f26705b1d61292eb8a14a7b7e7ac246e42 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 9 Aug 2011 18:26:24 +0000 Subject: 29661: Improved documentation for {var}>... redirections --- ChangeLog | 7 ++++++- Doc/Zsh/redirect.yo | 58 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 26 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index dfc2b987e..ddef4f18e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-09 Peter Stephenson + + * 29661: Doc/Zsh/redirect.yo: Improve the documentation for + {var}>... redirections. + 2011-08-03 Peter Stephenson * 29644: Functions/Chpwd/zsh_directory_name_cdr, @@ -15199,5 +15204,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5415 $ +* $Revision: 1.5416 $ ***************************************************** diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo index 3877b2313..67bad66ee 100644 --- a/Doc/Zsh/redirect.yo +++ b/Doc/Zsh/redirect.yo @@ -149,13 +149,33 @@ file descriptor 2 would be associated with the terminal (assuming file descriptor 1 had been) and then file descriptor 1 would be associated with file var(fname). -If instead of a digit one of the operators above is preceded by -a valid identifier enclosed in braces, the shell will open a new -file descriptor that is guaranteed to be at least 10 and set the -parameter named by the identifier to the file descriptor opened. -No whitespace is allowed between the closing brace and the redirection -character. The option tt(IGNORE_BRACES) must not be set. -For example: +The `tt(|&)' command separator described in +ifzman(em(Simple Commands & Pipelines) in zmanref(zshmisc))\ +ifnzman(noderef(Simple Commands & Pipelines)) +is a shorthand for `tt(2>&1 |)'. + +The various forms of process substitution, `tt(LPAR())var(list)tt(RPAR())' for output, are often used together with +redirection. For example, if var(word) in an output redirection is of the +form `tt(>LPAR())var(list)tt(RPAR())' then the output is piped to the +command represented by var(list). See +ifzman(\ +em(Process Substitution) in zmanref(zshexpn))\ +ifnzman(\ +noderef(Process Substitution)). +sect(Opening file descriptors using parameters) +cindex(file descriptors, use with parameters) +cindex(parameters, for using file descriptors) + +When the shell is parsing arguments to a command, and the shell option +The option tt(IGNORE_BRACES) is not set, a different form of +redirection is allowed: instead of a digit before the operator +there is a valid shell identifier enclosed in braces. The shell will +open a new file descriptor that is guaranteed to be at least 10 and set +the parameter named by the identifier to the file descriptor opened. No +whitespace is allowed between the closing brace and the redirection +character. For example: indent(... {myfd}>&1) @@ -181,8 +201,12 @@ using it for allocating a file descriptor avoids the error. Note that this mechanism merely allocates or closes a file descriptor; it does not perform any redirections from or to it. It is usually convenient -to allocate a file descriptor prior to use as an argument to tt(exec). The -following shows a typical sequence of allocation, use, and closing of a +to allocate a file descriptor prior to use as an argument to tt(exec). +The syntax does not in any case work when used around complex commands +such as parenthesised subshells or loops, where the opening brace is +interpreted as part of a command list to be executed in the current shell. + +The following shows a typical sequence of allocation, use, and closing of a file descriptor: example(integer myfd @@ -194,22 +218,6 @@ Note that the expansion of the variable in the expression tt(>&$myfd) occurs at the point the redirection is opened. This is after the expansion of command arguments and after any redirections to the left on the command line have been processed. - -The `tt(|&)' command separator described in -ifzman(em(Simple Commands & Pipelines) in zmanref(zshmisc))\ -ifnzman(noderef(Simple Commands & Pipelines)) -is a shorthand for `tt(2>&1 |)'. - -The various forms of process substitution, `tt(LPAR())var(list)tt(RPAR())' for output, are often used together with -redirection. For example, if var(word) in an output redirection is of the -form `tt(>LPAR())var(list)tt(RPAR())' then the output is piped to the -command represented by var(list). See -ifzman(\ -em(Process Substitution) in zmanref(zshexpn))\ -ifnzman(\ -noderef(Process Substitution)). sect(Multios) cindex(multios) pindex(MULTIOS, use of) -- cgit v1.2.3 From bbbaed2b5395e0a646dc618cd8c6bdd7dde25c81 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 10 Aug 2011 11:31:18 +0000 Subject: 29663: add $EPOCHREALTIME to zsh/datetime --- ChangeLog | 13 ++++++++++++- Doc/Zsh/mod_datetime.yo | 10 +++++++++- Src/Modules/datetime.c | 27 +++++++++++++++++++++++++++ Src/module.c | 5 +++++ configure.ac | 4 +++- 5 files changed, 56 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 078971581..658dca388 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-08-10 Peter Stephenson + + * 29663: configure.ac, Src/module.c, Src/Modules/datetime.c, + Doc/Zsh/mod_datetime.yo: add $EPOCHREALTIME for time in + double precision floating point. + +2011-08-04 Peter Stephenson + + * 29643: Src/signals.c, Src/utils.c, Src/zle_main.c: set + incompfunc to zero when executing hook or trap function. + 2011-08-09 Peter Stephenson * 29661: Doc/Zsh/redirect.yo: Improve the documentation for @@ -15213,5 +15224,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5417 $ +* $Revision: 1.5418 $ ***************************************************** diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo index 145d4a181..514c43037 100644 --- a/Doc/Zsh/mod_datetime.yo +++ b/Doc/Zsh/mod_datetime.yo @@ -30,9 +30,17 @@ in seconds if tt(-r) is given) to var(scalar) instead of printing it. ) enditem() -The tt(zsh/datetime) module makes available one parameter: +The tt(zsh/datetime) module makes available several parameters: startitem() +vindex(EPOCHREALTIME) +item(tt(EPOCHREALTIME))( +A floating point value representing the number of seconds since +the epoch. The notional accuracy is to nanoseconds if the +tt(clock_gettime) call is available and to microseconds otherwise, +but in practice the range of double precision floating point and +shell scheduling latencies may be significant effects. +) vindex(EPOCHSECONDS) item(tt(EPOCHSECONDS))( An integer value representing the number of seconds since the diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index 45818b968..1f2b7e81c 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -151,6 +151,28 @@ getcurrentsecs(UNUSED(Param pm)) return (zlong) time(NULL); } +static double +getcurrentrealtime(UNUSED(Param pm)) +{ +#ifdef HAVE_CLOCK_GETTIME + struct timespec now; + + if (clock_gettime(CLOCK_REALTIME, &now) < 0) { + zwarn("EPOCHREALTIME: unable to retrieve time: %e", errno); + return (double)0.0; + } + + return (double)now.tv_sec + (double)now.tv_nsec * 1e-9; +#else + struct timeval now; + struct timezone dummy_tz; + + gettimeofday(&now, &dummy_tz); + + return (double)now.tv_sec + (double)now.tv_usec * 1e-6; +#endif +} + static struct builtin bintab[] = { BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, "qrs:", NULL), }; @@ -158,9 +180,14 @@ static struct builtin bintab[] = { static const struct gsu_integer epochseconds_gsu = { getcurrentsecs, NULL, stdunsetfn }; +static const struct gsu_float epochrealtime_gsu = +{ getcurrentrealtime, NULL, stdunsetfn }; + static struct paramdef patab[] = { SPECIALPMDEF("EPOCHSECONDS", PM_INTEGER|PM_READONLY, &epochseconds_gsu, NULL, NULL), + SPECIALPMDEF("EPOCHREALTIME", PM_FFLOAT|PM_READONLY, + &epochrealtime_gsu, NULL, NULL) }; static struct features module_features = { diff --git a/Src/module.c b/Src/module.c index 219bdfa8e..a5a6029b4 100644 --- a/Src/module.c +++ b/Src/module.c @@ -1081,6 +1081,11 @@ addparamdef(Paramdef d) pm->gsu.i = d->gsu ? (GsuInteger)d->gsu : &varinteger_gsu; break; + case PM_FFLOAT: + case PM_EFLOAT: + pm->gsu.f = d->gsu; + break; + case PM_ARRAY: pm->gsu.a = d->gsu ? (GsuArray)d->gsu : &vararray_gsu; break; diff --git a/configure.ac b/configure.ac index 1ce815ca5..54999b164 100644 --- a/configure.ac +++ b/configure.ac @@ -693,6 +693,8 @@ AC_CHECK_LIB(c, printf, [LIBS="$LIBS -lc"]) AC_CHECK_LIB(m, pow) +AC_CHECK_LIB(rt, clock_gettime) + dnl Various features of ncurses depend on having the right header dnl (the system's own curses.h may well not be good enough). dnl So don't search for ncurses unless we found the header. @@ -1170,7 +1172,7 @@ dnl need to integrate this function dnl AC_FUNC_STRFTIME AC_CHECK_FUNCS(strftime strptime mktime timelocal \ - difftime gettimeofday \ + difftime gettimeofday clock_gettime \ select poll \ readlink faccessx fchdir ftruncate \ fstat lstat lchown fchown fchmod \ -- cgit v1.2.3 From 7e27b4eee387f9a374349588d464918a500c202d Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 10 Aug 2011 23:04:57 +0000 Subject: unposted: fix two typos in 29661 --- Doc/Zsh/redirect.yo | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo index 67bad66ee..8d231f40f 100644 --- a/Doc/Zsh/redirect.yo +++ b/Doc/Zsh/redirect.yo @@ -169,13 +169,12 @@ cindex(file descriptors, use with parameters) cindex(parameters, for using file descriptors) When the shell is parsing arguments to a command, and the shell option -The option tt(IGNORE_BRACES) is not set, a different form of -redirection is allowed: instead of a digit before the operator -there is a valid shell identifier enclosed in braces. The shell will -open a new file descriptor that is guaranteed to be at least 10 and set -the parameter named by the identifier to the file descriptor opened. No -whitespace is allowed between the closing brace and the redirection -character. For example: +tt(IGNORE_BRACES) is not set, a different form of redirection is allowed: +instead of a digit before the operator there is a valid shell identifier +enclosed in braces. The shell will open a new file descriptor that +is guaranteed to be at least 10 and set the parameter named by the +identifier to the file descriptor opened. No whitespace is allowed +between the closing brace and the redirection character. For example: indent(... {myfd}>&1) -- cgit v1.2.3 From 8cbd5100022d651054b9edbbb79b38c8a442ec51 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 11 Aug 2011 18:45:04 +0000 Subject: 29674: add $epochtime to datetime --- Doc/Zsh/mod_datetime.yo | 17 ++++++++++++++++- Src/Modules/datetime.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo index 514c43037..619067698 100644 --- a/Doc/Zsh/mod_datetime.yo +++ b/Doc/Zsh/mod_datetime.yo @@ -30,7 +30,8 @@ in seconds if tt(-r) is given) to var(scalar) instead of printing it. ) enditem() -The tt(zsh/datetime) module makes available several parameters: +The tt(zsh/datetime) module makes available several parameters; +all are readonly: startitem() vindex(EPOCHREALTIME) @@ -45,5 +46,19 @@ vindex(EPOCHSECONDS) item(tt(EPOCHSECONDS))( An integer value representing the number of seconds since the epoch. +) +vindex(epochtime) +item(tt(epochtime))( +An array value containing the number of seconds since the epoch +in the first element and the remainder of the time since the epoch +in nanoseconds in the second element. To ensure the two elements +are consistent the array should be copied or otherwise referenced +as a single substitution before the values are used. The following +idiom may be used: + +example(for secs nsecs in $epochtime; do + ... +done) + ) enditem() diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index 1f2b7e81c..98bcd7d65 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -173,6 +173,45 @@ getcurrentrealtime(UNUSED(Param pm)) #endif } +static char ** +getcurrenttime(UNUSED(Param pm)) +{ + char **arr; + char buf[DIGBUFSIZE]; + +#ifdef HAVE_CLOCK_GETTIME + struct timespec now; + + if (clock_gettime(CLOCK_REALTIME, &now) < 0) { + zwarn("EPOCHREALTIME: unable to retrieve time: %e", errno); + return NULL; + } + + arr = (char **)zhalloc(3 * sizeof(*arr)); + sprintf(buf, "%ld", (long)now.tv_sec); + arr[0] = dupstring(buf); + sprintf(buf, "%ld", now.tv_nsec); + arr[1] = dupstring(buf); + arr[2] = NULL; + + return arr; +#else + struct timeval now; + struct timezone dummy_tz; + + gettimeofday(&now, &dummy_tz); + + arr = (char **)zhalloc(3 * sizeof(*arr)); + sprintf(buf, "%ld", (long)now.tv_sec); + arr[0] = dupstring(buf); + sprintf(buf, "%ld", (long)now.tv_usec * 1000); + arr[1] = dupstring(buf); + arr[2] = NULL; + + return arr; +#endif +} + static struct builtin bintab[] = { BUILTIN("strftime", 0, bin_strftime, 2, 2, 0, "qrs:", NULL), }; @@ -183,11 +222,16 @@ static const struct gsu_integer epochseconds_gsu = static const struct gsu_float epochrealtime_gsu = { getcurrentrealtime, NULL, stdunsetfn }; +static const struct gsu_array epochtime_gsu = +{ getcurrenttime, NULL, stdunsetfn }; + static struct paramdef patab[] = { SPECIALPMDEF("EPOCHSECONDS", PM_INTEGER|PM_READONLY, &epochseconds_gsu, NULL, NULL), SPECIALPMDEF("EPOCHREALTIME", PM_FFLOAT|PM_READONLY, - &epochrealtime_gsu, NULL, NULL) + &epochrealtime_gsu, NULL, NULL), + SPECIALPMDEF("epochtime", PM_ARRAY|PM_READONLY, + &epochtime_gsu, NULL, NULL) }; static struct features module_features = { -- cgit v1.2.3 From 5d97a1f1cd9d461c452de0d93674fa5e0ab0fe6d Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 14 Aug 2011 07:21:20 +0000 Subject: 29673: Clarify what 'other' in the ignore-line style does --- ChangeLog | 7 ++++++- Doc/Zsh/compsys.yo | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 95e51e433..beb770118 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-14 Mikael Magnusson + + * 29673: Doc/Zsh/compsys.yo: Clarify what 'other' in the + ignore-line style does. + 2011-08-11 Peter Stephenson * Src/Modules/datetime.mdd: unposted: also fix the autofeatures. @@ -15234,5 +15239,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5421 $ +* $Revision: 1.5422 $ ***************************************************** diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index ad2562a26..7251c76e9 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1684,8 +1684,8 @@ will be considered as possible completions. If it is set to `tt(current)', the word the cursor is on will not be considered as a possible completion. The value `tt(current-shown)' is similar but only applies if the list of completions is currently shown on the screen. -Finally, if the style is set to `tt(other)', no word apart from the -current one will be considered as a possible completion. +Finally, if the style is set to `tt(other)', all words on the line except +for the current one will be excluded from the possible completions. The values `tt(current)' and `tt(current-shown)' are a bit like the opposite of the tt(accept-exact) style: only strings with -- cgit v1.2.3 From 7db1a0cf3d6b93b8a434e1add6d923b0e6047e00 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 14 Aug 2011 23:10:41 +0000 Subject: 29388, 29680: clarify note about e:string: quoting. --- ChangeLog | 5 ++++- Doc/Zsh/expn.yo | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index d9e63f36e..59a18dc36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,9 @@ * unposted: Src/jobs.c: fix capitalized word in the middle of a sentence. + * 29388, 29680: Doc/Zsh/expn.yo: clarify note about e:string: + quoting. + 2011-08-14 Barton E. Schaefer * 29677: Src/exec.c, Src/signals.c, Src/zsh.h: flag jobs that are @@ -15254,5 +15257,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5427 $ +* $Revision: 1.5428 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 7060a49b4..4c85d3119 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -2367,8 +2367,8 @@ latter is inserted into the command line word by word. For example, suppose a directory contains a single file `tt(lonely)'. Then the expression `tt(*(e:'reply=(${REPLY}{1,2})':))' will cause the words -`tt(lonely1 lonely2)' to be inserted into the command line. Note the -quotation marks. +`tt(lonely1)' and `tt(lonely2)' to be inserted into the command line. Note +the quoting of var(string). The form tt(PLUS())var(cmd) has the same effect, but no delimiters appear around var(cmd). Instead, var(cmd) is taken as the longest sequence of -- cgit v1.2.3 From 512660352feb89ae046639a7ebf6d43e888c17d9 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sun, 14 Aug 2011 23:19:22 +0000 Subject: 29504: note when (#cN,M) can't be used in place of # or ##. --- ChangeLog | 9 ++++++--- Doc/Zsh/expn.yo | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 59a18dc36..e8625ca6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,9 @@ 2011-08-14 Mikael Magnusson - * 29673: Doc/Zsh/compsys.yo: Clarify what 'other' in the + * 29673: Doc/Zsh/compsys.yo: clarify what 'other' in the ignore-line style does. - * 28852: Misc/zargs, Zle/match-words-by-style: Use syntax that + * 28852: Misc/zargs, Zle/match-words-by-style: use syntax that doesn't depend on SHORT_LOOPS being set. * unposted: Src/hist.c: fix a typo in a comment. @@ -14,6 +14,9 @@ * 29388, 29680: Doc/Zsh/expn.yo: clarify note about e:string: quoting. + * 29504: Doc/Zsh/expn.yo: note when (#cN,M) can't be used in + place of # or ##. + 2011-08-14 Barton E. Schaefer * 29677: Src/exec.c, Src/signals.c, Src/zsh.h: flag jobs that are @@ -15257,5 +15260,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5428 $ +* $Revision: 1.5429 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 4c85d3119..adbc662e6 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1999,15 +1999,16 @@ point on. ) item(tt(c)var(N)tt(,)var(M))( The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere -that the tt(#) or tt(##) operators can be used; it cannot be combined -with other globbing flags and a bad pattern error occurs if it is -misplaced. It is equivalent to the form tt({)var(N)tt(,)var(M)tt(}) in -regular expressions. The previous character or group is required to -match between var(N) and var(M) times, inclusive. The form -tt(LPAR()#c)var(N)tt(RPAR()) requires exactly tt(N) matches; -tt(LPAR()#c,)var(M)tt(RPAR()) is equivalent to specifying var(N) as 0; -tt(LPAR()#c)var(N)tt(,RPAR()) specifies that there is no maximum limit -on the number of matches. +that the tt(#) or tt(##) operators can be used except in the expressions +`tt((*/)#)' and `tt((*/)##)' in filename generation, where `tt(/)' +has special meaning; it cannot be combined with other globbing flags and +a bad pattern error occurs if it is misplaced. It is equivalent to the +form tt({)var(N)tt(,)var(M)tt(}) in regular expressions. The previous +character or group is required to match between var(N) and var(M) times, +inclusive. The form tt(LPAR()#c)var(N)tt(RPAR()) requires exactly tt(N) +matches; tt(LPAR()#c,)var(M)tt(RPAR()) is equivalent to specifying var(N) +as 0; tt(LPAR()#c)var(N)tt(,RPAR()) specifies that there is no maximum +limit on the number of matches. ) item(tt(m))( Set references to the match data for the entire string matched; this is -- cgit v1.2.3 From ca7269e82da4175557b9ed1fc19389f693581b35 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 28 Aug 2011 16:38:28 +0000 Subject: users/16289: don't delete temporary files on disown. Document. --- ChangeLog | 7 ++++++- Doc/Zsh/expn.yo | 12 ++++++++++++ Src/exec.c | 14 +++++++------- Src/jobs.c | 31 ++++++++++++++++++------------- 4 files changed, 43 insertions(+), 21 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 9183dc348..58e06d4da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-08-28 Peter Stephenson + + * users/16289: Doc/Zsh/expn.yo, Src/exec.c, Src/jobs.c: don't + delete temporary files when disowning and document this. + 2011-08-20 Barton E. Schaefer * unposted: Functions/Zle/.distfiles: add move-line-in-buffer @@ -15330,5 +15335,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5445 $ +* $Revision: 1.5446 $ ***************************************************** diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index adbc662e6..28d525f14 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -471,6 +471,18 @@ example(tt({ paste pc++; if (!list_pipe && thisjob != list_pipe_job && !hasprocs(thisjob)) - deletejob(jobtab + thisjob); + deletejob(jobtab + thisjob, 0); cmdpush(CS_CURSH); execlist(state, 1, do_exec); cmdpop(); @@ -1434,7 +1434,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) zclose(opipe[0]); } if (how & Z_DISOWN) { - deletejob(jobtab + thisjob); + deletejob(jobtab + thisjob, 1); thisjob = -1; } else @@ -1484,7 +1484,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) printjob(jn, !!isset(LONGLISTJOBS), 1); } else if (newjob != list_pipe_job) - deletejob(jn); + deletejob(jn, 0); else lastwj = -1; } @@ -1588,7 +1588,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) if (list_pipe && (lastval & 0200) && pj >= 0 && (!(jn->stat & STAT_INUSE) || (jn->stat & STAT_DONE))) { - deletejob(jn); + deletejob(jn, 0); jn = jobtab + pj; if (jn->gleader) killjb(jn, lastval & ~0200); @@ -1596,7 +1596,7 @@ execpline(Estate state, wordcode slcode, int how, int last1) if (list_pipe_child || ((jn->stat & STAT_DONE) && (list_pipe || (pline_level && !(jn->stat & STAT_SUBJOB))))) - deletejob(jn); + deletejob(jn, 0); thisjob = pj; } @@ -4271,7 +4271,7 @@ execshfunc(Shfunc shf, LinkList args) * would be filled by a recursive function. */ last_file_list = jobtab[thisjob].filelist; jobtab[thisjob].filelist = NULL; - deletejob(jobtab + thisjob); + deletejob(jobtab + thisjob, 0); } if (isset(XTRACE)) { @@ -4300,7 +4300,7 @@ execshfunc(Shfunc shf, LinkList args) cmdsp = ocsp; if (!list_pipe) - deletefilelist(last_file_list); + deletefilelist(last_file_list, 0); } /* Function to execute the special type of command that represents an * diff --git a/Src/jobs.c b/Src/jobs.c index f58735bb0..94d25bb85 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -269,7 +269,7 @@ handle_sub(int job, int fg) sleep, the rest will be executed by a sub-shell, but the parent shell gets notified for the sleep. - deletejob(sj); */ + deletejob(sj, 0); */ /* If this super-job contains only the sub-shell, we have to attach the tty to its process group now. */ @@ -955,7 +955,7 @@ printjob(Job jn, int lng, int synch) if (jn->stat & STAT_DONE) { if (should_report_time(jn)) dumptime(jn); - deletejob(jn); + deletejob(jn, 0); if (job == curjob) { curjob = prevjob; prevjob = job; @@ -1085,7 +1085,7 @@ printjob(Job jn, int lng, int synch) if (jn->stat & STAT_DONE) { if (should_report_time(jn)) dumptime(jn); - deletejob(jn); + deletejob(jn, 0); if (job == curjob) { curjob = prevjob; prevjob = job; @@ -1100,12 +1100,13 @@ printjob(Job jn, int lng, int synch) /**/ void -deletefilelist(LinkList file_list) +deletefilelist(LinkList file_list, int disowning) { char *s; if (file_list) { while ((s = (char *)getlinknode(file_list))) { - unlink(s); + if (!disowning) + unlink(s); zsfree(s); } zfree(file_list, sizeof(struct linklist)); @@ -1141,7 +1142,7 @@ freejob(Job jn, int deleting) /* careful in case we shrink and move the job table */ int job = jn - jobtab; if (deleting) - deletejob(jobtab + jn->other); + deletejob(jobtab + jn->other, 0); else freejob(jobtab + jn->other, 0); jn = jobtab + job; @@ -1161,13 +1162,17 @@ freejob(Job jn, int deleting) /* * We are actually finished with this job, rather * than freeing it to make space. + * + * If "disowning" is set, files associated with the job are not + * actually deleted --- and won't be as there is nothing left + * to clear up. */ /**/ void -deletejob(Job jn) +deletejob(Job jn, int disowning) { - deletefilelist(jn->filelist); + deletefilelist(jn->filelist, disowning); if (jn->stat & STAT_ATTACH) { attachtty(mypgrp); adjustwinsize(0); @@ -1343,7 +1348,7 @@ zwaitjob(int job, int wait_cmd) child_block(); } } else { - deletejob(jn); + deletejob(jn, 0); pipestats[0] = lastval; numpipestats = 1; } @@ -1366,7 +1371,7 @@ waitjobs(void) if (jn->procs || jn->auxprocs) zwaitjob(thisjob, 0); else { - deletejob(jn); + deletejob(jn, 0); pipestats[0] = lastval; numpipestats = 1; } @@ -1494,7 +1499,7 @@ spawnjob(void) } } if (!hasprocs(thisjob)) - deletejob(jobtab + thisjob); + deletejob(jobtab + thisjob, 0); else jobtab[thisjob].stat |= STAT_LOCKED; thisjob = -1; @@ -2070,7 +2075,7 @@ bin_fg(char *name, char **argv, Options ops, int func) waitjobs(); retval = lastval2; } else if (ofunc == BIN_DISOWN) - deletejob(jobtab + job); + deletejob(jobtab + job, 1); break; case BIN_JOBS: printjob(job + (oldjobtab ? oldjobtab : jobtab), lng, 2); @@ -2106,7 +2111,7 @@ bin_fg(char *name, char **argv, Options ops, int func) #endif pids); } - deletejob(jobtab + job); + deletejob(jobtab + job, 1); break; } thisjob = ocj; -- cgit v1.2.3 From ba3ebac710d2e1f27631626d69f251707ba1a8f6 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Tue, 6 Sep 2011 16:13:09 +0000 Subject: 29736: mention when zstyle -t returns 1. --- ChangeLog | 6 +++++- Doc/Zsh/mod_zutil.yo | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 17d1a8f87..2dd4a988e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-09-06 Mikael Magnusson + + * 29736: Doc/Zsh/mod_zutil.yo: mention when zstyle -t returns 1. + 2011-09-05 Barton E. Schaefer * users/16302: Completion/Unix/Type/_path_files: pattern matching @@ -15365,5 +15369,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5453 $ +* $Revision: 1.5454 $ ***************************************************** diff --git a/Doc/Zsh/mod_zutil.yo b/Doc/Zsh/mod_zutil.yo index 1838eab5e..726b0f055 100644 --- a/Doc/Zsh/mod_zutil.yo +++ b/Doc/Zsh/mod_zutil.yo @@ -101,7 +101,8 @@ style is defined for at least one matching pattern, has only one string in its value, and that is equal to one of `tt(true)', `tt(yes)', `tt(on)' or `tt(1)'. If any var(strings) are given the status is zero if and only if at least one of the var(strings) is equal to at least one of the strings -in the value. If the style is not defined, the status is tt(2). +in the value. If the style is defined but doesn't match, the return status +is tt(1). If the style is not defined, the status is tt(2). The tt(-T) option tests the values of the style like tt(-t), but it returns status zero (rather than tt(2)) if the style is not defined for any -- cgit v1.2.3 From d88c4241f982fe45c462e0a7f17fddea57d121f4 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 7 Sep 2011 13:40:23 +0000 Subject: 29756: Doc/Zsh/params.yo: DIRSTACKSIZE is unlimited by default. --- ChangeLog | 6 +++++- Doc/Zsh/params.yo | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 994b9b524..91c8380b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-09-07 Simon Ruderich + + * 29756: Doc/Zsh/params.yo: DIRSTACKSIZE is unlimited by default. + 2011-09-07 Mikael Magnusson * 29755: Completion/Unix/Command/_ssh: add -O stop to to _ssh. @@ -15387,5 +15391,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5460 $ +* $Revision: 1.5461 $ ***************************************************** diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index c46d85bcd..e9a3c722d 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -907,7 +907,7 @@ directory would still be completed). ) vindex(DIRSTACKSIZE) item(tt(DIRSTACKSIZE))( -The maximum size of the directory stack. If the +The maximum size of the directory stack, by default there is no limit. If the stack gets larger than this, it will be truncated automatically. This is useful with the tt(AUTO_PUSHD) option. pindex(AUTO_PUSHD, use of) -- cgit v1.2.3 From b2da9b3afc57d442ff4d0ab4311450220156e4ee Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 7 Sep 2011 13:43:38 +0000 Subject: 29757: Doc/Zsh/compsys.yo: Remove superfluous brace. --- ChangeLog | 4 +++- Doc/Zsh/compsys.yo | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 91c8380b0..23189b3f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * 29756: Doc/Zsh/params.yo: DIRSTACKSIZE is unlimited by default. + * 29757: Doc/Zsh/compsys.yo: Remove superfluous brace. + 2011-09-07 Mikael Magnusson * 29755: Completion/Unix/Command/_ssh: add -O stop to to _ssh. @@ -15391,5 +15393,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5461 $ +* $Revision: 1.5462 $ ***************************************************** diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 7251c76e9..d3d272c10 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1085,7 +1085,7 @@ Some of these styles are tested first for every possible tag corresponding to a type of match, and if no style was found, for the 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) +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: -- cgit v1.2.3 From 748bd73d88ff777b6af0afd32934afb43b11ed6f Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 25 Sep 2011 18:09:13 +0000 Subject: unposted: cross-reference zmodload from the modules intro doc. 29769: follow-up 29677 to handle the case where thisjob == -1. --- ChangeLog | 9 ++++++++- Doc/Zsh/modules.yo | 8 ++++++-- Src/signals.c | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 74f78a944..2b7f1e15c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-09-25 Barton E. Schaefer + + * 29769: Src/signals.c: handle thisjob == -1 (no foreground job) + when checking for whether a background job is allowed to suspend. + + * unposted: Doc/Zsh/modules.yo: cross-reference zmodload. + 2011-09-22 Peter Stephenson * Daniel Friesel: 29796: Completion/X/Command/_mplayer: complete @@ -15440,5 +15447,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5472 $ +* $Revision: 1.5473 $ ***************************************************** diff --git a/Doc/Zsh/modules.yo b/Doc/Zsh/modules.yo index 3f9986096..c8b846b95 100644 --- a/Doc/Zsh/modules.yo +++ b/Doc/Zsh/modules.yo @@ -6,7 +6,11 @@ Some optional parts of zsh are in modules, separate from the core of the shell. Each of these modules may be linked in to the shell at build time, or can be dynamically linked while the shell is running -if the installation supports this feature. The modules that -are bundled with the zsh distribution are: +if the installation supports this feature. +Modules are linked at runtime with the tt(zmodload) command, +see ifzman(zmanref(zshbuiltins))\ +ifnzman(noderef(Shell Builtin Commands)). + +The modules that are bundled with the zsh distribution are: includefile(Zsh/modlist.yo) diff --git a/Src/signals.c b/Src/signals.c index dd39158d0..ad688094b 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -491,7 +491,9 @@ wait_for_processes(void) */ if (findproc(pid, &jn, &pn, 0)) { if (((jn->stat & STAT_BUILTIN) || - (list_pipe && (jobtab[thisjob].stat & STAT_BUILTIN))) && + (list_pipe && + (thisjob == -1 || + (jobtab[thisjob].stat & STAT_BUILTIN)))) && WIFSTOPPED(status) && WSTOPSIG(status) == SIGTSTP) { killjb(jn, SIGCONT); zwarn("job can't be suspended"); -- cgit v1.2.3 From c70e44c9bd770b7ca5959841faa0857cc9496d8e Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 12 Oct 2011 13:03:54 +0000 Subject: 29815: include mod_langinfo in documentation --- ChangeLog | 6 +++++- Doc/Makefile.in | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 1b67dccfa..a9b214167 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-10-12 Mikael Magnusson + + * 29815: Doc/Makefile.in: include mod_langinfo in documentation. + 2011-09-25 Barton E. Schaefer * 29799: Src/utils.c: swap order of RESET_PROMPT / REFRESH in @@ -15451,5 +15455,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5474 $ +* $Revision: 1.5475 $ ***************************************************** diff --git a/Doc/Makefile.in b/Doc/Makefile.in index f7f5915c1..d30149da0 100644 --- a/Doc/Makefile.in +++ b/Doc/Makefile.in @@ -59,7 +59,7 @@ Zsh/mod_attr.yo Zsh/mod_cap.yo Zsh/mod_clone.yo \ Zsh/mod_compctl.yo Zsh/mod_complete.yo Zsh/mod_complist.yo \ Zsh/mod_computil.yo Zsh/mod_curses.yo \ Zsh/mod_datetime.yo Zsh/mod_deltochar.yo \ -Zsh/mod_example.yo Zsh/mod_files.yo \ +Zsh/mod_example.yo Zsh/mod_files.yo Zsh/mod_langinfo.yo \ Zsh/mod_mapfile.yo Zsh/mod_mathfunc.yo Zsh/mod_newuser.yo \ Zsh/mod_parameter.yo Zsh/mod_pcre.yo Zsh/mod_regex.yo \ Zsh/mod_sched.yo Zsh/mod_socket.yo \ -- cgit v1.2.3 From 8dc39360c92252207c9287e63d2f7bb457a77aaf Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 14 Oct 2011 19:01:41 +0000 Subject: 29820: _pick_variant -b to match builtin --- ChangeLog | 8 ++++++- Completion/Base/Utility/_pick_variant | 8 ++++++- Doc/Zsh/compsys.yo | 8 ++++++- Src/Zle/zle_tricky.c | 41 +++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index a9b214167..bc4572ad4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-10-14 Peter Stephenson + + * 29820: Doc/Zsh/compsys.yo, + Completion/Base/Utility/_pick_variant: -b option to match + builtins. + 2011-10-12 Mikael Magnusson * 29815: Doc/Makefile.in: include mod_langinfo in documentation. @@ -15455,5 +15461,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5475 $ +* $Revision: 1.5476 $ ***************************************************** diff --git a/Completion/Base/Utility/_pick_variant b/Completion/Base/Utility/_pick_variant index 01fa2b98f..9099e3599 100644 --- a/Completion/Base/Utility/_pick_variant +++ b/Completion/Base/Utility/_pick_variant @@ -6,7 +6,7 @@ local -A opts (( $+_cmd_variant )) || typeset -gA _cmd_variant -zparseopts -D -A opts c: r: +zparseopts -D -A opts b: c: r: : ${opts[-c]:=$words[1]} while [[ $1 = *=* ]]; do @@ -19,6 +19,12 @@ if (( $+_cmd_variant[$opts[-c]] )); then return 0 fi +if [[ $+opts[-b] -eq 1 && -n $builtins[$opts[-c]] ]]; then + _cmd_variant[$opts[-c]]=$opts[-b] + (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}" + return 0 +fi + output="$(_call_program variant $opts[-c] "${@[2,-1]}" &1)" for cmd pat in "$var[@]"; do diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index d3d272c10..e07ac0e9e 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4387,7 +4387,9 @@ tt(ambiguous), tt(special-dirs), tt(list-suffixes) and tt(file-sort) described above. ) findex(_pick_variant) -item(tt(_pick_variant [ tt(-c) var(command) ] [ tt(-r) var(name) ] var(label)tt(=)var(pattern) ... var(label) [ var(args) ... ]))( +xitem(tt(_pick_variant) [ tt(-b) var(builtin-label) ] [ tt(-c) +var(command) ] [ tt(-r) var(name) ]) +item( var(label)tt(=)var(pattern) ... var(label) [ var(args) ... ])( This function is used to resolve situations where a single command name requires more than one type of handling, either because it has more than one variant or because there is a name clash between two @@ -4403,6 +4405,10 @@ tt(...)' contains var(pattern), then tt(label) is selected as the label for the command variant. If none of the patterns match, the final command label is selected and status 1 is returned. +If the `tt(-b) var(builtin-label)' is given, the command is tested to +see if it is provided as a shell builtin, possibly autoloaded; if so, +the label var(builtin-label) is selected as the label for the variant. + If the `tt(-r) var(name)' is given, the var(label) picked is stored in the parameter named var(name). diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 999b2b7be..6fa887a1e 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -1869,6 +1869,10 @@ get_comp_string(void) } } else if (p < curs) { if (*p == Outbrace) { + /* + * HERE: strip and remember code from last + * comma to here. + */ cant = 1; break; } @@ -1876,6 +1880,16 @@ get_comp_string(void) char *tp = p; if (!skipparens(Inbrace, Outbrace, &tp)) { + /* + * Balanced brace: skip. + * We only deal with unfinished braces, so + * something{foobar,morestuff}else + * doesn't work + * + * HERE: instead, continue, look for a comma. + * Stack tp and brace for popping when we + * find a comma at each level. + */ i += tp - p - 1; dp += tp - p - 1; p = tp - 1; @@ -1918,10 +1932,16 @@ get_comp_string(void) hascom = 1; } } else { + /* On or after the cursor position */ if (*p == Inbrace) { char *tp = p; if (!skipparens(Inbrace, Outbrace, &tp)) { + /* + * Balanced braces after the cursor. + * Could do the same with these as + * those before the cursor. + */ i += tp - p - 1; dp += tp - p - 1; p = tp - 1; @@ -1932,6 +1952,14 @@ get_comp_string(void) break; } if (p == curs) { + /* + * We've reached the cursor position. + * If there's a pending open brace at this + * point we need to stack the text. + * We've marked the bit we don't want from + * bbeg to bend, which might be a comma + * between the opening brace and us. + */ if (bbeg) { Brinfo new; int len = bend - bbeg; @@ -1961,10 +1989,23 @@ get_comp_string(void) bbeg = NULL; } if (*p == Comma) { + /* + * Comma on or after cursor. + * We set bbeg to NULL at the cursor; here + * it's being used to find the first comma + * afterwards. + */ if (!bbeg) bbeg = p; hascom = 2; } else if (*p == Outbrace) { + /* + * Closing brace on or after the cursor. + * Not sure how this can be after the cursor; + * if it was matched, wouldn't we have skipped + * over the group, and if it wasn't, surely we're + * not interested in it? + */ Brinfo new; int len; -- cgit v1.2.3 From aba557a13cd1099ade8cd5c2bf7a109df3c6d77f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 24 Oct 2011 15:35:13 +0000 Subject: Jérémie Roquet: c.f. users/16541: should be "filename generation", not "file generation" in cond doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 5 ++++- Doc/Zsh/cond.yo | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 2f20a43af..a5abb669e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2011-10-24 Peter Stephenson + * Jérémie Roquet: c.f. users/16541: Doc/Zsh/cond.yo: + should be "filename generation", not "file generation". + * Foudil Brétel: 29842: Completion/Unix/Command/_systemctl: major rewrite. @@ -15497,5 +15500,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5483 $ +* $Revision: 1.5484 $ ***************************************************** diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo index 489ee356b..71971b4b3 100644 --- a/Doc/Zsh/cond.yo +++ b/Doc/Zsh/cond.yo @@ -184,7 +184,7 @@ enditem() Normal shell expansion is performed on the var(file), var(string) and var(pattern) arguments, but the result of each expansion is constrained to be a single word, similar to the effect of double quotes. -File generation is not performed on any form of argument to conditions. +Filename generation is not performed on any form of argument to conditions. However, pattern metacharacters are active for the var(pattern) arguments; the patterns are the same as those used for filename generation, see ifzman(\ -- cgit v1.2.3 From 45faf8f5b2758a638e0958928262ca9d26980885 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 4 Nov 2011 14:14:26 +0000 Subject: 29891: make zle -lL with arguments work --- ChangeLog | 7 ++++++- Doc/Zsh/zle.yo | 15 ++++++++++----- Src/Zle/zle_thingy.c | 12 +++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 84e92c328..d2a18fd80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-11-04 Peter Stephenson + + * 29891: Doc/Zsh/zle.yo, Src/Zle/zle_thingy.c: allow "zle -lL" + with arguments to list in -L format. + 2011-10-31 Peter Stephenson * Jun T: 29883: Src/Builtins/rlimits.c, Src/Modules/zftp.c: cast @@ -15533,5 +15538,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5491 $ +* $Revision: 1.5492 $ ***************************************************** diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 5f4d639d3..752247461 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -392,11 +392,16 @@ commands to create the widgets. When combined with the tt(-a) option, all widget names are listed, including the builtin ones. In this case the tt(-L) option is ignored. -If at least one var(string) is given, nothing will be printed but the -return status will be zero if all var(string)s are names of existing -widgets (or of user-defined widgets if the tt(-a) flag is not given) -and non-zero if at least one var(string) is not a name of an defined -widget. +If at least one var(string) is given, and tt(-a) is present or tt(-L) is +not used, nothing will be printed. The return status will be zero if +all var(string)s are names of existing widgets and non-zero if at least one +var(string) is not a name of a defined widget. If tt(-a) is also +present, all widget names are used for the comparison including builtin +widgets, else only user-defined widgets are used. + +If at least one var(string) is present and the tt(-L) option is used, +user-defined widgets matching any var(string) are listed in the form of +tt(zle) commands to create the widgets. ) item(tt(-D) var(widget) ...)( Delete the named var(widget)s. diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index f712e1750..03e73b4ca 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -394,9 +394,13 @@ bin_zle_list(UNUSED(char *name), char **args, Options ops, UNUSED(char func)) Thingy t; for (; *args && !ret; args++) { - if (!(t = (Thingy) thingytab->getnode2(thingytab, *args)) || + HashNode hn = thingytab->getnode2(thingytab, *args); + if (!(t = (Thingy) hn) || (!OPT_ISSET(ops,'a') && (t->widget->flags & WIDGET_INT))) ret = 1; + else if (OPT_ISSET(ops,'L')) { + scanlistwidgets(hn, 1); + } } return ret; } @@ -483,6 +487,12 @@ bin_zle_keymap(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) return selectkeymap(*args, 0); } +/* + * List a widget. + * If list is negative, just print the name. + * If list is 0, use abbreviated format. + * If list is positive, output as a command. + */ /**/ static void scanlistwidgets(HashNode hn, int list) -- cgit v1.2.3 From ec6914b061c652a26078af71a29a3d3402583b52 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 7 Nov 2011 11:13:48 +0000 Subject: 29894: display and use previous replacement in replace-string --- ChangeLog | 7 ++++++- Doc/Zsh/contrib.yo | 5 +++++ Functions/Zle/replace-string | 20 +++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 8eda2f415..b9ac1e6ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-11-07 Peter Stephenson + + * 29894: Doc/Zsh/contrib.yo, Functions/Zle/replace-string: + display previous replacement and reuse if source string is empty. + 2011-11-04 Peter Stephenson * 29892: Functions/Zle/read-from-minibuffer, @@ -15543,5 +15548,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5493 $ +* $Revision: 1.5494 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 05bbcd7ec..b02c61c45 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2335,6 +2335,11 @@ regular expression matching is performed, else a literal string replacement. Note that the previous source and replacement text are the same whether pattern, regular expression or string matching is used. +In addition, tt(replace-string) shows the previous replacement above +the prompt, so long as there was one during the current session; if the +source string is empty, that replacement will be repeated without +the widget prompting for a replacement string. + For example, starting from the line: example(print This line contains fan and fond) diff --git a/Functions/Zle/replace-string b/Functions/Zle/replace-string index bc608e577..a3416a403 100644 --- a/Functions/Zle/replace-string +++ b/Functions/Zle/replace-string @@ -3,7 +3,15 @@ setopt extendedglob autoload -Uz read-from-minibuffer replace-string-again -local p1="Replace: " p2=" with: " +local p1 p2 + +if [[ -n $_replace_string_src ]]; then + p1="[$_replace_string_src -> $_replace_string_rep]"$'\n' +fi + +p1+="Replace: " +p2=" with: " + # Saving curwidget is necessary to avoid the widget name being overwritten. local REPLY previous curwidget=$WIDGET @@ -14,10 +22,12 @@ else fi read-from-minibuffer $p1 ${previous:+$_replace_string_src} || return 1 -typeset -g _replace_string_src=$REPLY +if [[ -n $REPLY ]]; then + typeset -g _replace_string_src=$REPLY -read-from-minibuffer "$p1$_replace_string_src$p2" \ - ${previous:+$_replace_string_rep} || return 1 -typeset -g _replace_string_rep=$REPLY + read-from-minibuffer "$p1$_replace_string_src$p2" \ + ${previous:+$_replace_string_rep} || return 1 + typeset -g _replace_string_rep=$REPLY +fi replace-string-again $curwidget -- cgit v1.2.3 From 7c4a81113448b4177bd9c35fd5b04b60dcaf35a7 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 18 Nov 2011 09:52:50 +0000 Subject: 29908: make MIME functions handle stacked suffixes --- ChangeLog | 9 +++++- Doc/Zsh/contrib.yo | 17 ++++++++++ Functions/MIME/.distfiles | 5 ++- Functions/MIME/zsh-mime-handler | 70 ++++++++++++++++++++++++++++++++--------- 4 files changed, 84 insertions(+), 17 deletions(-) (limited to 'Doc') diff --git a/ChangeLog b/ChangeLog index 05c5ba28e..b72cb695c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-11-18 Peter Stephenson + + * 29908: Doc/Zsh/contrib.yo, Functions/MIME/.distfiles, + Functions/MIME/zsh-mime-contexts, Functions/MIME/zsh-mime-handler: + make MIME functions handle contexts with stacked suffixes such + as .pdf.gz. + 2011-11-17 Peter Stephenson * Jun T.: 29907: Src/Modules/pcre.c: remove declaration of @@ -15582,5 +15589,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5500 $ +* $Revision: 1.5501 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index b02c61c45..aee0bd7f4 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2803,6 +2803,23 @@ start with tt(:mime:), with additional components in some cases. It is recommended that a trailing tt(*) (suitably quoted) be appended to style patterns in case the system is extended in future. Some examples are given below. + +For files that have multiple suffixes, e.g. tt(.pdf.gz), where the +context includes the suffix it will be looked up starting with the +longest possible suffix until a match for the style is found. +For example, if tt(.pdf.gz) produces a match for the handler, that +will be used; otherwise the handler for tt(.gz) will be used. Note +that, owing to the way suffix aliases work, it is always required that +there be a handler for the shortest possible suffix, so in this example +tt(.pdf.gz) can only be handled if tt(.gz) is also handled (though +not necessarily in the same way). Alternatively, if no handling +for tt(.gz) on its own is needed, simply adding the command + +example(alias -s gz=zsh-mime-handler) + +to the initialisation code is sufficient; tt(.gz) will not be handled +on its own, but may be in combination with other suffixes. + startitem() kindex(current-shell, MIME style) item(tt(current-shell))( diff --git a/Functions/MIME/.distfiles b/Functions/MIME/.distfiles index 01ac0d7ef..93c13f7da 100644 --- a/Functions/MIME/.distfiles +++ b/Functions/MIME/.distfiles @@ -1,4 +1,7 @@ DISTFILES_SRC=' .distfiles -zsh-mime-setup zsh-mime-handler pick-web-browser +pick-web-browser +zsh-mime-contexts +zsh-mime-handler +zsh-mime-setup ' diff --git a/Functions/MIME/zsh-mime-handler b/Functions/MIME/zsh-mime-handler index 9a40e67bb..abaf0b6e3 100644 --- a/Functions/MIME/zsh-mime-handler +++ b/Functions/MIME/zsh-mime-handler @@ -34,6 +34,8 @@ setopt extendedglob cbases nullglob $autocd # We need zformat from zsh/zutil for %s replacement. zmodload -i zsh/zutil +autoload -Uz zsh-mime-contexts + # Look for options. Because of the way this is usually invoked, # (there is always a command to be handled), only handle options # up to second last argument. @@ -62,12 +64,15 @@ shift $(( OPTIND - 1 )) # just as well pass them all down. However, we just take the # suffix from the first since that's what invoked us via suffix -s. -local suffix context +local suffix s local -a match mbegin mend -[[ $1 = (#b)*.([^.]##) ]] || return 1 -suffix=${(L)match[1]} -context=":mime:.${suffix}:" +suffix=${1:t} +if [[ $suffix != *.* ]]; then + "No suffix in command: $1" >&2 + return 1 +fi +suffix=${suffix#*.} local handler flags no_sh no_bg arg integer i @@ -77,11 +82,11 @@ local -a exec_asis hand_nonex # despite being called for interpretation by the mime handler. # Defaults to executable files, which ensures that they are executed as # they are, even if they have a suffix. -zstyle -a $context execute-as-is exec_asis || exec_asis=('*(*)' '*(/)') +zsh-mime-contexts -a $suffix execute-as-is exec_asis || exec_asis=('*(*)' '*(/)') # Set to a list of patterns for which the handler will be used even # if the file doesn't exist on the disk. -zstyle -a $context handle-nonexistent hand_nonex || +zsh-mime-contexts -a $suffix handle-nonexistent hand_nonex || hand_nonex=('[[:alpha:]]#:/*') local pattern @@ -92,9 +97,9 @@ local -a files # actual file or its directory. local dir local -a filepath -if zstyle -t $context find-file-in-path && [[ $1 != /* ]] && +if zsh-mime-contexts -t $suffix find-file-in-path && [[ $1 != /* ]] && [[ $1 != */* || -o pathdirs ]]; then - zstyle -a $context file-path filepath || filepath=($path) + zsh-mime-contexts -a $suffix file-path filepath || filepath=($path) for dir in $filepath; do if [[ -e $dir/$1 ]]; then 1=$dir/$1 @@ -153,19 +158,54 @@ if [[ ! -e $1 ]]; then fi fi -zstyle -s $context handler handler || - handler="${zsh_mime_handlers[$suffix]}" -zstyle -s $context flags flags || - flags="${zsh_mime_flags[$suffix]}" +if ! zsh-mime-contexts -s $suffix handler handler; then + # Look for handler starting with longest suffix match. + # Typically we'd only get a match for the shortest, but don't assume so. + s=$suffix + while true; do + handler="${zsh_mime_handlers[$s]}" + if [[ -n $handler ]]; then + break + fi + if [[ $s = *.* ]]; then + s=${s#*.} + else + break + fi + done + if [[ -z $handler ]]; then + if [[ $suffix = *.* ]]; then + print "No handler specified for suffix .$suffix or any final part" >&2 + else + print "No handler specified for suffix .$suffix" >&2 + fi + return 1 + fi +fi +if ! zsh-mime-contexts -s $suffix flags flags; then + # Same again for flags. + s=$suffix + while true; do + flags="${zsh_mime_flags[$suffix]}" + if [[ -n $flags ]]; then + break + fi + if [[ $s = *.* ]]; then + s=${s#*.} + else + break + fi + done +fi # Set to yes if we use eval instead of sh -c for complicated mailcap lines # Can possibly break some mailcap entries which expect sh compatibility, # but is faster, as a new process is not spawned. -zstyle -t $context current-shell && no_sh=yes +zsh-mime-contexts -t $suffix current-shell && no_sh=yes # Set to yes if the process shouldn't be backgrounded even if it doesn't need a # terminal and display is set. -zstyle -t $context never-background && no_bg=yes +zsh-mime-contexts -t $suffix never-background && no_bg=yes local hasmeta stdin @@ -241,7 +281,7 @@ if [[ $flags = *copiousoutput* ]]; then # We need to page the output. # Careful in case PAGER is a set of commands and arguments. local -a pager - zstyle -a $context pager pager || pager=(${=PAGER:-more}) + zsh-mime-contexts -a $suffix pager pager || pager=(${=PAGER:-more}) if [[ -n $stdin ]]; then cat $argv | $execargs | $pager else -- cgit v1.2.3