From b0784025b18a95515c1905be6f7190f4951100e5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 23 Jan 2017 03:33:38 +0000 Subject: 40396: vcs_info quilt: More documentation of '%Q' and 'use-quilt'. --- Doc/Zsh/contrib.yo | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Doc/Zsh/contrib.yo') diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index f764eb7c6..8f79694e0 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1288,6 +1288,17 @@ to tt(mq) information). See the tt(get-mq) and tt(get-bookmarks) styles. Both of these styles may be enabled at the same time. If both are enabled, both resulting strings will be shown separated by a semicolon (that cannot currently be customized). + +The tt(quilt) `standalone' backend sets this expando to the same value as the +tt(%Q) expando. +) +item(tt(%Q))( +Quilt series information. +When quilt is used (either in `addon' mode or as a `standalone' backend), +this expando is set to quilt series' tt(patch-format) string. +The tt(set-patch-format) hook and tt(nopatch-format) style are honoured. + +See tt(Quilt Support) below for details. ) enditem() @@ -1346,6 +1357,10 @@ 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). +Quilt integration is off by default; to enable it, set the tt(use-quilt) style, +and add tt(%Q) to your tt(formats) or tt(actionformats) style: +example(zstyle ':vcs_info:*' use-quilt true) + 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 -- cgit v1.2.3 From 49bc46946e93e55fd74c8b5a7109e49e41820725 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 1 Feb 2017 17:36:54 +0000 Subject: 40476: vcs_info $backend_misc: Document at the right point, provide in quilt 'standalone' mode. --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 6 +++--- Functions/VCS_Info/VCS_INFO_quilt | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 302f70662..647ae5ca9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-02-03 Daniel Shahaf + + * 40476: Doc/Zsh/contrib.yo, Functions/VCS_Info/VCS_INFO_quilt: + vcs_info $backend_misc: Document at the right point, provide + in quilt 'standalone' mode. + 2017-02-02 Peter Stephenson * 40486: Src/Modules/regex.c, Src/params.c: don't warn on diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8f79694e0..79e02628a 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1207,6 +1207,8 @@ item(tt(nopatch-format))( This pair of styles format the patch information used by the tt(%m) expando in formats and actionformats for the tt(git) and tt(hg) backends. The value is subject to certain tt(%)-expansions described below. +The expanded value is made available in the global tt(backend_misc) array as +tt(${backend_misc[patches]}) (also if a tt(set-patch-format) hook is used). ) kindex(get-unapplied) item(tt(get-unapplied))( @@ -1612,9 +1614,7 @@ 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 tt(%m) escape in -tt(formats) and tt(actionformats); it will be available in the global -tt(backend_misc) array as tt($backend_misc[patches]}); and it will be +tt(${hook_com[applied-string]}) will be available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles. ) item(tt(gen-unapplied-string))( diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt index aed9f0c33..d6b7c2f72 100644 --- a/Functions/VCS_Info/VCS_INFO_quilt +++ b/Functions/VCS_Info/VCS_INFO_quilt @@ -184,6 +184,7 @@ function VCS_INFO_quilt() { case ${mode} in (standalone) + backend_misc[patches]=${qstring} VCS_INFO_formats '' '' "${root}" '' '' '' "${qstring}" VCS_INFO_set ;; -- cgit v1.2.3 From bb6c08b51a0798700b6fdd0b75581dca21dc4e5b Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 4 Feb 2017 05:42:31 +0000 Subject: unposted: vcs_info git: Fix typo in manual. --- ChangeLog | 6 ++++++ Doc/Zsh/contrib.yo | 4 ++-- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 69984887b..1b88bfd25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-02-04 Daniel Shahaf + + * unposted: Doc/Zsh/contrib.yo, + Functions/VCS_Info/Backends/VCS_INFO_get_data_git: vcs_info git: + Fix typo in manual. + 2017-02-03 Daniel Shahaf * 40480: Functions/VCS_Info/Backends/VCS_INFO_get_data_git, diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 79e02628a..a454f60a3 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1279,8 +1279,8 @@ A "misc" replacement. It is at the discretion of the backend to decide what this replacement expands to. The tt(hg) and tt(git) backends use this expando to display patch information. -tt(hg) sources patch information from the tt(mq) extensions; tt(git) from the -tt(rebase) command and from the and tt(stgit) extension. The tt(patch-format) +tt(hg) sources patch information from the tt(mq) extensions; tt(git) from in-progress +tt(rebase) and tt(cherry-pick) operations and from the tt(stgit) extension. The tt(patch-format) and tt(nopatch-format) styles control the generated string. The former is used when at least one patch from the patch queue has been applied, and the latter otherwise. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 1b25b1c7c..192b0a10d 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -179,6 +179,7 @@ local patchdir=${gitdir}/patches/${gitbranch} if [[ -d $patchdir ]] && [[ -f $patchdir/applied ]] \ && [[ -f $patchdir/unapplied ]] then + # stgit git_patches_applied=(${(f)"$(< "${patchdir}/applied")"}) git_patches_unapplied=(${(f)"$(< "${patchdir}/unapplied")"}) VCS_INFO_git_handle_patches -- cgit v1.2.3 From ecd88284f358cbcd787757184bbf8704779cab1a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 5 Feb 2017 08:28:13 +0000 Subject: 40492: vcs_info: Escape '%' signs in payloads. Test case: a patch whose subject is '%Sfoo%sbar'. ('S' and 's' are expandos both in prompts and in the 'formats' style.) --- ChangeLog | 7 +++++++ Doc/Zsh/contrib.yo | 17 +++++++++++++++++ Etc/BUGS | 7 ------- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 1 + Functions/VCS_Info/VCS_INFO_set-patch-format | 14 ++++++++++++++ README | 9 +++++++++ 6 files changed, 48 insertions(+), 7 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 051a76b8c..787c27e1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2017-02-09 Daniel Shahaf + + * 40492: Doc/Zsh/contrib.yo, Etc/BUGS, + Functions/VCS_Info/Backends/VCS_INFO_get_data_hg, + Functions/VCS_Info/VCS_INFO_set-patch-format, README: vcs_info: + Escape '%' signs in payloads. + 2017-02-08 Daniel Shahaf * unposted: Completion/Unix/Command/_subversion: _svn: Fix diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index a454f60a3..5d0696dcc 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1344,6 +1344,12 @@ 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. +When one of the tt(gen-applied-string), tt(gen-unapplied-string), and +tt(set-patch-format) hooks is defined, +applying tt(%)-escaping (`tt(foo=${foo//'%'/%%})') to the interpolated values +for use in the prompt is the responsibility of those hooks (jointly); +when neither of those hooks is defined, tt(vcs_info) handles escaping by itself. +We regret this coupling, but it was required for backwards compatibility. subsect(Quilt Support) @@ -1616,6 +1622,9 @@ top-most patch and so forth. When setting tt(ret) to non-zero, the string in tt(${hook_com[applied-string]}) will be available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles. +This hook is, in concert with tt(set-patch-format), responsible for +tt(%)-escaping that value for use in the prompt. +(See the `Oddities' section.) ) item(tt(gen-unapplied-string))( Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg) (with @@ -1629,6 +1638,9 @@ 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 tt(%u) in the tt(patch-format) and tt(nopatch-format) styles. +This hook is, in concert with tt(set-patch-format), responsible for +tt(%)-escaping that value for use in the prompt. +(See the `Oddities' section.) ) item(tt(gen-mqguards-string))( Called in the tt(hg) backend when tt(guards-string) is generated; the @@ -1706,6 +1718,11 @@ controllable in addition to that. If tt(ret) is set to non-zero, the string in tt(${hook_com[patch-replace]}) will be used unchanged instead of an expanded format from tt(patch-format) or tt(nopatch-format). + +This hook is, in concert with the tt(gen-applied-string) or +tt(gen-unapplied-string) hooks if they are defined, responsible for +tt(%)-escaping the final tt(patch-format) value for use in the prompt. +(See the `Oddities' section.) ) item(tt(set-message))( Called each time before a `tt(vcs_info_msg_)var(N)tt(_)' message is set. diff --git a/Etc/BUGS b/Etc/BUGS index a351464ac..008e337ca 100644 --- a/Etc/BUGS +++ b/Etc/BUGS @@ -15,13 +15,6 @@ It is currently impossible to time builtins. 40106: The comp* completion-related builtins (compadd, compset, etc) are run with $_comp_options in effect, rather than the user's options. ------------------------------------------------------------------------ -40240: vcs_info: percent escapes in payloads are interpreted - -Example: hg branch names and quilt patch subjects that contain the literal -string '%F{blue}', cause $vcs_info_msg_N_ to be rendered in blue. - -40240 has a patch, but 40241 explains why that patch is incomplete. ------------------------------------------------------------------------- users/20807: vcs_info quilt 'addon' mode: hook lookup context specifies the underlying VCS but not whether quilt is used. diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index 143eb42f0..d4030125c 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -202,6 +202,7 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \ if VCS_INFO_hook 'gen-mqguards-string' "${mqguards[@]}"; then guards_string=${(j:,:)mqguards} + # TODO: %-escape extra_zformats[g:...] value else guards_string=${hook_com[guards-string]} fi diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format index c5da36808..cdf2d303e 100644 --- a/Functions/VCS_Info/VCS_INFO_set-patch-format +++ b/Functions/VCS_Info/VCS_INFO_set-patch-format @@ -18,12 +18,15 @@ # - $hook_com is overwritten and the keys 'applied', 'applied-n', # 'unapplied', 'unapplied-n', 'all-n' are set. { + local applied_needs_escaping='unknown' + local unapplied_needs_escaping='unknown' if VCS_INFO_hook 'gen-applied-string' "${(@P)1}"; then if (( ${(P)#1} )); then REPLY=${(P)1[1]} else REPLY="" fi + applied_needs_escaping='yes' else REPLY=${hook_com[applied-string]} fi @@ -32,6 +35,7 @@ if VCS_INFO_hook 'gen-unapplied-string' "${(@P)3}"; then REPLY=${(P)#3} + unapplied_needs_escaping='yes' else REPLY=${hook_com[unapplied-string]} fi @@ -54,12 +58,22 @@ hook_com[all-n]=$(( ${hook_com[applied-n]} + ${hook_com[unapplied-n]} )) hook_com+=( ${7:+"${(@kvP)7}"} ) if VCS_INFO_hook 'set-patch-format' "${(P)6}"; then + # Escape the value for use in $PS1 + if [[ $applied_needs_escaping == 'yes' ]]; then + hook_com[applied]=${hook_com[applied]//'%'/%%} + fi + if [[ $unapplied_needs_escaping == 'yes' ]]; then + hook_com[unapplied]=${hook_com[unapplied]//'%'/%%} + fi + zformat -f REPLY "${(P)6}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \ "n:${hook_com[applied-n]}" "c:${hook_com[unapplied-n]}" \ "a:${hook_com[all-n]}" \ ${8:+"${(@P)8}"} else + unset applied_needs_escaping unapplied_needs_escaping # the hook deals with escaping REPLY=${hook_com[patch-replace]} fi hook_com=() + } diff --git a/README b/README index 26eb24550..594b6f1cd 100644 --- a/README +++ b/README @@ -62,6 +62,15 @@ Note that functions including a non-leading / behave as before, e.g. if `dir/name' is found anywhere under a directory in $fpath it is loaded as a function named `dir/name'. +3) vcs_info: When neither a set-patch-format nor a gen-applied-string +(resp. gen-unapplied-string) hook is set, vcs_info now '%'-escapes the +applied-string (resp. unapplied-string) before interpolating it into the +patch-format string, to prevent literal `%' signs in the interpolated +value from being interpreted as prompt escape sequences. If you use +${vcs_info_msg_0_} in a context other than the shell prompt, you may need +to undo the escaping with: + print -v vcs_info_msg_0_ -Pr -- "${vcs_info_msg_0_}" + Incompatibilities between 5.0.8 and 5.3 ---------------------------------------- -- cgit v1.2.3 From 56ef4f62c424db4b9c93e44a918e25651de03855 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 10 Mar 2017 11:02:40 +0000 Subject: 40822: vcs_info quilt: Document the '.quilt-foo' zstyle context element. (Compare users/20807.) --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 4d305d06f..225f7312f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-03-14 Daniel Shahaf + + * 40822: Doc/Zsh/contrib.yo: vcs_info quilt: Document the + '.quilt-foo' zstyle context element. (Compare users/20807.) + 2017-03-12 Oliver Kiddle * Wieland Hoffmann: 40837: Completion/Unix/Command/_pgrep: diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 5d0696dcc..ed33a4a0c 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -944,11 +944,17 @@ example(:vcs_info:var(vcs-string):var(user-context):var(repo-root-name)) startitem() 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.) +is one of: tt(git), tt(git-svn), tt(git-p4), tt(hg), tt(hg-git), +tt(hg-hgsubversion), tt(hg-hgsvn), tt(darcs), tt(bzr), tt(cdv), tt(mtn), +tt(svn), tt(cvs), tt(svk), tt(tla), tt(p4) or tt(fossil). +This is followed by `tt(.quilt-)var(quilt-mode)' in Quilt mode +(see bf(Quilt Support) for details) +and by `tt(+)var(hook-name)' while hooks are active +(see bf(Hooks in vcs_info) for details). + +COMMENT(users/20807) +Currently, hooks in quilt mode don't add the `tt(.quilt-)var(quilt-mode)' information. +This may change in the future. ) item(var(user-context))( is a freely configurable string, assignable by @@ -1369,6 +1375,11 @@ Quilt integration is off by default; to enable it, set the tt(use-quilt) style, and add tt(%Q) to your tt(formats) or tt(actionformats) style: example(zstyle ':vcs_info:*' use-quilt true) +Styles looked up from the Quilt support code include `tt(.quilt-)var(quilt-mode)' +in the var(vcs-string) part of the context, where var(quilt-mode) is either +tt(addon) or tt(standalone). +Example: tt(:vcs_info:git.quilt-addon:default:)var(repo-root-name). + 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 -- cgit v1.2.3 From f3ae40f8aa81f40b665e4a4cb69b48ac25cab38e Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 18 Mar 2017 00:54:56 +0000 Subject: unposted: vcs_info quilt: Fix documentation markup typo. --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index e445e9973..8fd5df6e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-03-18 Daniel Shahaf + + * unposted: Doc/Zsh/contrib.yo: vcs_info quilt: Fix documentation + markup typo. + 2017-03-16 Daniel Shahaf * 40855: Completion/Unix/Command/_dmidecode: Fix _arguments diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index ed33a4a0c..c5a75a707 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1386,7 +1386,7 @@ a directory that holds quilt's patches needs to be found. That directory is 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 +`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 -- cgit v1.2.3 From 10220628e7bf5ca7287f1472dbd22db0aab3823d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 18 Mar 2017 00:53:26 +0000 Subject: 40859: vcs_info docs: Use proper internal links through texinfo nodes. Changes: - Add texinode()'s - Replace 'see foo' with 'see noderef(foo)' Drive-by changes: - Fix one reference to a nonexistent "Styles" section - (minor) Fix whitespace around "once" --- ChangeLog | 5 +++++ Doc/Zsh/contrib.yo | 65 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 19 deletions(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index 8fd5df6e3..d496c04eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-03-19 Daniel Shahaf + + * 40859: Doc/Zsh/contrib.yo: vcs_info docs: Use proper internal + links through texinfo nodes. + 2017-03-18 Daniel Shahaf * unposted: Doc/Zsh/contrib.yo: vcs_info quilt: Fix documentation diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index c5a75a707..b9e4a8fe2 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -862,7 +862,8 @@ sitem(SVK (tt(svk)))(uref(http://svk.bestpractical.com/)) endsitem() There is also support for the patch management system tt(quilt) -(uref(http://savannah.nongnu.org/projects/quilt)). See tt(Quilt Support) +(uref(http://savannah.nongnu.org/projects/quilt)). See +ifzman(bf(Quilt Support))ifnzman(noderef(vcs_info Quilt Support)) below for details. To load tt(vcs_info): @@ -872,6 +873,18 @@ example(autoload -Uz vcs_info) It can be used in any existing prompt, because it does not require any specific tt($psvar) entries to be available. +startmenu() +menu(vcs_info Quickstart) +menu(vcs_info Configuration) +menu(vcs_info Oddities) +menu(vcs_info Quilt Support) +menu(vcs_info API) +menu(vcs_info Variables) +menu(vcs_info Hooks) +menu(vcs_info Examples) +endmenu() + +texinode(vcs_info Quickstart)(vcs_info Configuration)()(Version Control Information) subsect(Quickstart) To get this feature working quickly (including colors), you can do the @@ -935,6 +948,7 @@ That means the detection of these systems is skipped em(completely). No wasted time there. +texinode(vcs_info Configuration)(vcs_info Oddities)(vcs_info Quickstart)(Version Control Information) subsect(Configuration) The tt(vcs_info) feature can be configured via tt(zstyle). @@ -948,9 +962,9 @@ is one of: tt(git), tt(git-svn), tt(git-p4), tt(hg), tt(hg-git), tt(hg-hgsubversion), tt(hg-hgsvn), tt(darcs), tt(bzr), tt(cdv), tt(mtn), tt(svn), tt(cvs), tt(svk), tt(tla), tt(p4) or tt(fossil). This is followed by `tt(.quilt-)var(quilt-mode)' in Quilt mode -(see bf(Quilt Support) for details) +(see ifzman(bf(Quilt Support))ifnzman(noderef(vcs_info Quilt Support)) for details) and by `tt(+)var(hook-name)' while hooks are active -(see bf(Hooks in vcs_info) for details). +(see ifzman(bf(Hooks in vcs_info))ifnzman(noderef(vcs_info Hooks)) for details). COMMENT(users/20807) Currently, hooks in quilt mode don't add the `tt(.quilt-)var(quilt-mode)' information. @@ -1062,17 +1076,17 @@ example(zstyle ':vcs_info:*' disable-patterns "${+LPAR()b+RPAR()HOME}/.zsh+LPAR( kindex(use-quilt) item(tt(use-quilt))( If enabled, the tt(quilt) support code is active in `addon' mode. -See tt(Quilt Support) for details. +See ifzman(bf(Quilt Support))ifnzman(noderef(vcs_info Quilt Support)) for details. ) kindex(quilt-standalone) item(tt(quilt-standalone))( If enabled, `standalone' mode detection is attempted if no VCS is active -in a given directory. See tt(Quilt Support) for details. +in a given directory. See ifzman(bf(Quilt Support))ifnzman(noderef(vcs_info Quilt Support)) for details. ) kindex(quilt-patch-dir) item(tt(quilt-patch-dir))( Overwrite the value of the tt($QUILT_PATCHES) environment variable. See -tt(Quilt Support) for details. +ifzman(bf(Quilt Support))ifnzman(noderef(vcs_info Quilt Support)) for details. ) kindex(quiltcommand) item(tt(quiltcommand))( @@ -1203,7 +1217,8 @@ is only used by tt(vcs_info)'s hooks system. ) kindex(hooks) item(tt(hooks))( -A list style that defines hook-function names. See bf(Hooks in vcs_info) +A list style that defines hook-function names. See ifzman(bf(Hooks in vcs_info))\ +ifnzman(noderef(vcs_info Hooks)) below for details. ) kindex(patch-format) @@ -1306,7 +1321,7 @@ When quilt is used (either in `addon' mode or as a `standalone' backend), this expando is set to quilt series' tt(patch-format) string. The tt(set-patch-format) hook and tt(nopatch-format) style are honoured. -See tt(Quilt Support) below for details. +See ifzman(tt(Quilt Support))ifnzman(noderef(vcs_info Quilt Support)) below for details. ) enditem() @@ -1340,6 +1355,7 @@ endsitem() Not all VCS backends have to support all replacements. For tt(nvcsformats) no replacements are performed at all, it is just a string. +texinode(vcs_info Oddities)(vcs_info Quilt Support)(vcs_info Configuration)(Version Control Information) subsect(Oddities) If you want to use the tt(%b) (bold off) prompt expansion in tt(formats), @@ -1357,6 +1373,7 @@ for use in the prompt is the responsibility of those hooks (jointly); when neither of those hooks is defined, tt(vcs_info) handles escaping by itself. We regret this coupling, but it was required for backwards compatibility. +texinode(vcs_info Quilt Support)(vcs_info API)(vcs_info Oddities)(Version Control Information) subsect(Quilt Support) bf(Quilt) is not a version control system, therefore this is not implemented @@ -1400,8 +1417,10 @@ to know which patches of a series are not yet applied, you need to activate the tt(get-unapplied) style in the appropriate context. 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 +information is presented (see +ifzman(the bf(Configuration) and bf(Hooks in vcs_info) sections)\ +ifnzman(noderef(vcs_info Configuration) and noderef(vcs_info Hooks))), +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 bf(git), or tt(mq) for bf(hg)); the configuration for systems like that are generally configured the same way as the bf(quilt) @@ -1455,6 +1474,7 @@ Note, if there is both a function and a variable by the name of tt(quilt-standalone), the function will take precedence. +texinode(vcs_info API)(vcs_info Variables)(vcs_info Quilt Support)(Version Control Information) subsect(Function Descriptions (Public API)) startitem() @@ -1463,7 +1483,8 @@ item(tt(vcs_info) [var(user-context)])( The main function, that runs all backends and assembles all data into 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 +ifzman(bf(Variable Description))ifnzman(noderef(vcs_info Variables)) +below). If an argument is given, that string will be used instead of tt(default) in the var(user-context) field of the style context. ) @@ -1472,7 +1493,8 @@ 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 bf(Hooks in vcs_info) below for details. +here. See ifzman(bf(Hooks in vcs_info))ifnzman(noderef(vcs_info Hooks)) +below for details. ) findex(vcs_info_hookdel) item(tt(vcs_info_hookdel))( @@ -1481,8 +1503,9 @@ first non-option argument; what follows is a list of hook-function names to un-register from the hook. If `tt(-a)' is used as the first argument, tt(all) occurrences of the functions are unregistered. Otherwise only the last occurrence is removed (if a function was registered to a hook -more than once) . The `tt(+vi-)' prefix needs to be left out here. See -bf(Hooks in vcs_info) below for details. +more than once). The `tt(+vi-)' prefix needs to be left out here. +See ifzman(bf(Hooks in vcs_info))ifnzman(noderef(vcs_info Hooks)) +below for details. ) findex(vcs_info_lastmsg) item(tt(vcs_info_lastmsg))( @@ -1507,6 +1530,7 @@ enditem() All functions named tt(VCS_INFO_*) are for internal use only. +texinode(vcs_info Variables)(vcs_info Hooks)(vcs_info API)(Version Control Information) subsect(Variable Description) startitem() @@ -1524,6 +1548,7 @@ enditem() All variables named tt(VCS_INFO_*) are for internal use only. +texinode(vcs_info Hooks)(vcs_info Examples)(vcs_info Variables)(Version Control Information) subsect(Hooks in vcs_info) Hooks are places in tt(vcs_info) where you can run your own code. That @@ -1635,7 +1660,7 @@ tt(${hook_com[applied-string]}) will be available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles. This hook is, in concert with tt(set-patch-format), responsible for tt(%)-escaping that value for use in the prompt. -(See the `Oddities' section.) +(See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).) ) item(tt(gen-unapplied-string))( Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg) (with @@ -1651,7 +1676,7 @@ tt(${hook_com[unapplied-string]}) will be available as tt(%u) in the tt(patch-format) and tt(nopatch-format) styles. This hook is, in concert with tt(set-patch-format), responsible for tt(%)-escaping that value for use in the prompt. -(See the `Oddities' section.) +(See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).) ) item(tt(gen-mqguards-string))( Called in the tt(hg) backend when tt(guards-string) is generated; the @@ -1733,7 +1758,7 @@ tt(nopatch-format). This hook is, in concert with the tt(gen-applied-string) or tt(gen-unapplied-string) hooks if they are defined, responsible for tt(%)-escaping the final tt(patch-format) value for use in the prompt. -(See the `Oddities' section.) +(See ifzman(the bf(Oddities) section)ifnzman(noderef(vcs_info Oddities)).) ) item(tt(set-message))( Called each time before a `tt(vcs_info_msg_)var(N)tt(_)' message is set. @@ -1762,10 +1787,12 @@ tt(vcs_info). ) enditem() -If all of this sounds rather confusing, take a look at the bf(Examples) -section below and also in the tt(Misc/vcs_info-examples) file in the Zsh source. +If all of this sounds rather confusing, take a look at +ifzman(the bf(Examples) section below)ifnzman(noderef(vcs_info Examples)) +and also in the tt(Misc/vcs_info-examples) file in the Zsh source. They contain some explanatory code. +texinode(vcs_info Examples)(Prompt Themes)(vcs_info Hooks)(Version Control Information) subsect(Examples) Don't use tt(vcs_info) at all (even though it's in your prompt): -- cgit v1.2.3 From b627c251a40bf4b6968b7fc5fcb9311bcf9bfb66 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 20 Mar 2017 18:51:24 +0000 Subject: unposted (after 40859): Fix yodl warning: makeinfo ./zsh.texi ./zsh.texi:36246: Next field of node `vcs_info Examples' not pointed to (perhaps incorrect sectioning?). ./zsh.texi:36419: This node (Prompt Themes) has the bad Prev. Seen with yodl 3.00.00 but not with 3.04.00. --- ChangeLog | 4 ++++ Doc/Zsh/contrib.yo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Doc/Zsh/contrib.yo') diff --git a/ChangeLog b/ChangeLog index d496c04eb..ad269634e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-03-20 Daniel Shahaf + + * unposted (after 40859): Doc/Zsh/contrib.yo: Fix yodl warning. + 2017-03-19 Daniel Shahaf * 40859: Doc/Zsh/contrib.yo: vcs_info docs: Use proper internal diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index b9e4a8fe2..35ab100b5 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1792,7 +1792,7 @@ ifzman(the bf(Examples) section below)ifnzman(noderef(vcs_info Examples)) and also in the tt(Misc/vcs_info-examples) file in the Zsh source. They contain some explanatory code. -texinode(vcs_info Examples)(Prompt Themes)(vcs_info Hooks)(Version Control Information) +texinode(vcs_info Examples)()(vcs_info Hooks)(Version Control Information) subsect(Examples) Don't use tt(vcs_info) at all (even though it's in your prompt): -- cgit v1.2.3 From 43e55a9bcd2c90124a751f2597d2f33cb6e3c042 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sat, 29 Jul 2017 16:58:39 -0700 Subject: 41472: introduce cleanup hooks default and restore special themes, and update documentation --- Doc/Zsh/contrib.yo | 74 +++++++++++++++++++- Functions/Prompts/prompt_bart_setup | 10 ++- Functions/Prompts/prompt_default_setup | 7 ++ Functions/Prompts/prompt_off_setup | 13 ++-- Functions/Prompts/prompt_restore_setup | 2 + Functions/Prompts/promptinit | 120 +++++++++++++++++++++++++-------- 6 files changed, 187 insertions(+), 39 deletions(-) create mode 100644 Functions/Prompts/prompt_default_setup create mode 100644 Functions/Prompts/prompt_restore_setup (limited to 'Doc/Zsh/contrib.yo') diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 35ab100b5..35ce91575 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1920,8 +1920,9 @@ subsect(Installation) You should make sure all the functions from the tt(Functions/Prompts) directory of the source distribution are available; they all begin with the string `tt(prompt_)' except for the special function`tt(promptinit)'. -You also need the `tt(colors)' function from tt(Functions/Misc). All of -these functions may already have been installed on your system; if not, +You also need the `tt(colors)' and `tt(add-zsh-hook)' functions from +tt(Functions/Misc). +All these functions may already be installed on your system; if not, you will need to find them and copy them. The directory should appear as one of the elements of the tt(fpath) array (this should already be the case if they were installed), and at least the function tt(promptinit) @@ -1975,6 +1976,75 @@ normally call a theme's setup function directly. ) enditem() +subsect(Utility Themes) + +startitem() +item(tt(prompt off))( +The theme `tt(off)' sets all the prompt variables to minimal values with +no special effects. +) +item(tt(prompt default))( +The theme `tt(default)' sets all prompt variables to the same state as +if an interactive zsh was started with no initialization files. +) +item(tt(prompt restore))( +The special theme `tt(restore)' erases all theme settings and sets prompt +variables to their state before the first time the `tt(prompt)' function +was run, provided each theme has properly defined its cleanup (see below). + +Note that you can undo `tt(prompt off)' and `tt(prompt default)' with +`tt(prompt restore)', but a second restore does not undo the first. +) +enditem() + +subsect(Writing Themes) + +The first step for adding your own theme is to choose a name for it, +and create a file `tt(prompt_var(name)_setup)' in a directory in your +tt(fpath), such as tt(~/myfns) in the example above. The file should +at minimum contain assignments for the prompt variables that your +theme wishes to modify. By convention, themes use tt(PS1), tt(PS2), +tt(RPS1), etc., rather than the longer tt(PROMPT) and tt(RPROMPT). + +The file is autoloaded as a function in the current shell context, so +it may contain any necessary commands to customize your theme, including +defining additional functions. To make some complex tasks easier, your +setup function may also do any of the following: + +startitem() +item(Assign tt(prompt_opts))( +The array tt(prompt_opts) may be assigned any of tt("bang"), tt("cr"), +tt("percent"), tt("sp"), and/or tt("subst") as values. The corresponding +setopts (tt(promptbang), etc.) are turned on, all other prompt-related +options are turned off. The tt(prompt_opts) array preserves setopts even +beyond the scope of tt(localoptions), should your function need that. +) +item(Modify precmd and preexec)( +Use of tt(add-zsh-hook) is recommended. The tt(precmd) and tt(preexec) +hooks are automatically adjusted if the prompt theme changes or is +disabled. +) +item(Declare cleanup)( +If your function makes any other changes that should be undone when the +theme is disabled, your setup function may call +example(prompt_cleanup var(command)) +where var(command) should be suitably quoted. If your theme is ever +disabled or replaced by another, var(command) is executed with tt(eval). +You may declare more than one such cleanup hook. +) +item(Define preview)( +Define or autoload a function tt(prompt_var(name)_preview) to display +a simulated version of your prompt. A simple default previewer is +defined by tt(promptinit) for themes that do not define their own. +This preview function is called by `tt(prompt -p)'. +) +item(Provide help)( +Define or autoload a function tt(prompt_var(name)_help) to display +documentation or help text for your theme. +This help function is called by `tt(prompt -h)'. +) +enditem() + texinode(ZLE Functions)(Exception Handling)(Prompt Themes)(User Contributions) sect(ZLE Functions) diff --git a/Functions/Prompts/prompt_bart_setup b/Functions/Prompts/prompt_bart_setup index cb032de8a..6de412231 100644 --- a/Functions/Prompts/prompt_bart_setup +++ b/Functions/Prompts/prompt_bart_setup @@ -16,9 +16,13 @@ prompt_bart_help () { blue, and the default foreground) are used if no arguments are given. The defaults look best on a light background. - The "off" token temporarily disables the theme; "on" restores it. No background colors or hardwired cursor motion escapes are used, and it is not necessary to setopt promptsubst. + + The "off" token temporarily disables the theme; "on" restores it. + Note, this does NOT fully reset to the original prompt state, it + only hides/reveals the extra lines above the command line and + removes the supporting hooks. EOF [[ $(read -sek 1 "?${(%):-%S[press return]%s}") == [Qq] ]] && print -nP '\r%E' && return @@ -183,7 +187,7 @@ prompt_bart_setup () { add-zsh-hook -D preexec "prompt_*_preexec" functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}" [[ $prompt_theme[1] = bart ]] && PS1=${${(f)PS1}[-1]} - return 1 + return 1 # Prevent change of $prompt_theme ;; (on|enable) shift @@ -224,6 +228,8 @@ prompt_bart_setup () { add-zsh-hook precmd prompt_bart_precmd add-zsh-hook preexec prompt_bart_preexec + prompt_cleanup \ + 'functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch}"' functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_bart_winch} prompt_bart_winch" diff --git a/Functions/Prompts/prompt_default_setup b/Functions/Prompts/prompt_default_setup new file mode 100644 index 000000000..aed74eb67 --- /dev/null +++ b/Functions/Prompts/prompt_default_setup @@ -0,0 +1,7 @@ +PS1='%m%# ' +PS2='%_> ' +PS3='?# ' +PS4='+%N:%i> ' +unset RPS1 RPS2 RPROMPT RPROMPT2 + +prompt_opts=( cr percent sp ) diff --git a/Functions/Prompts/prompt_off_setup b/Functions/Prompts/prompt_off_setup index f604b477f..e6d16bfd9 100644 --- a/Functions/Prompts/prompt_off_setup +++ b/Functions/Prompts/prompt_off_setup @@ -1,9 +1,10 @@ # Very simple prompt -prompt_off_setup () { - PS1="%# " - PS2="> " - prompt_opts=( cr percent ) -} +prompt_default_setup 2>/dev/null -prompt_off_setup "$@" +PS1="%# " +PS2="> " +PS3='?# ' +PS4='+> ' + +prompt_opts=( cr percent sp ) diff --git a/Functions/Prompts/prompt_restore_setup b/Functions/Prompts/prompt_restore_setup new file mode 100644 index 000000000..54c4adbf9 --- /dev/null +++ b/Functions/Prompts/prompt_restore_setup @@ -0,0 +1,2 @@ +# Damn that was easy +zstyle -t :prompt-theme cleanup diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 587248997..e27b8779a 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -47,20 +47,36 @@ prompt_preview_safely() { return fi - local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 - local -a precmd_functions preexec_functions - - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _preview function that it's been autoloaded. - prompt_${1}_setup - - if typeset +f prompt_${1}_preview >&/dev/null; then - prompt_${1}_preview "$@[2,-1]" - else - prompt_preview_theme "$@" - fi + # This handles all the stuff from the default :prompt-theme cleanup + local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 + local +h PROMPT=$PROMPT RPROMPT=$RPOMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR + local -a precmd_functions preexec_functions prompt_preview_cleanup + local -aLl +h zle_highlight + + { + # Save and clear current restore-point if any + zstyle -g prompt_preview_cleanup :prompt-theme cleanup + { + zstyle -d :prompt-theme cleanup + + # The next line is a bit ugly. It (perhaps unnecessarily) + # runs the prompt theme setup function to ensure that if + # the theme has a _preview function that it's been autoloaded. + prompt_${1}_setup + + if typeset +f prompt_${1}_preview >&/dev/null; then + prompt_${1}_preview "$@[2,-1]" + else + prompt_preview_theme "$@" + fi + } always { + # Run any theme-specific cleanup, then reset restore point + zstyle -t :prompt-theme cleanup + } + } always { + (( $#prompt_preview_cleanup )) && + zstyle -e :prompt-theme cleanup "${prompt_preview_cleanup[@]}" + } } set_prompt() { @@ -84,9 +100,9 @@ Use prompt -h for help on specific themes.' setopt localtraps if [[ -z "$prompt_theme[1]" ]]; then # Not using a prompt theme; save settings - local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 - local precmd_functions preexec_functions + local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2 + local +h PROMPT=$PROMPT RPROMPT=$RPOMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR + local -a precmd_functions preexec_functions else trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0 fi @@ -104,11 +120,11 @@ Use prompt -h for help on specific themes.' ;; h) if [[ -n "$2" && -n $prompt_themes[(r)$2] ]]; then if functions prompt_$2_setup >/dev/null; then - # The next line is a bit ugly. It (perhaps unnecessarily) - # runs the prompt theme setup function to ensure that if - # the theme has a _help function that it's been autoloaded. - prompt_$2_setup - fi + # The next line is a bit ugly. It (perhaps unnecessarily) + # runs the prompt theme setup function to ensure that if + # the theme has a _help function that it's been autoloaded. + prompt_$2_setup + fi if functions prompt_$2_help >/dev/null; then print "Help for $2 theme:\n" prompt_$2_help @@ -168,28 +184,74 @@ Use prompt -h for help on specific themes.' esac } +prompt_cleanup () { + local -a cleanup_hooks + if zstyle -g cleanup_hooks :prompt-theme cleanup + then + cleanup_hooks+=(';' "$@") + zstyle -e :prompt-theme cleanup "${cleanup_hooks[@]}" + elif (( $+prompt_preview_cleanup == 0 )) + then + print -u2 "prompt_cleanup: no prompt theme active" + return 1 + fi +} + prompt () { - local prompt_opts + local -a prompt_opts theme_active + zstyle -g theme_active :prompt-theme cleanup || { + # This is done here rather than in set_prompt so that it + # is safe and sane for set_prompt to setopt localoptions, + # which will be cleared before we arrive back here again. + # This is also why we pass around the prompt_opts array. + [[ -o promptbang ]] && prompt_opts+=(bang) + [[ -o promptcr ]] && prompt_opts+=(cr) + [[ -o promptpercent ]] && prompt_opts+=(percent) + [[ -o promptsp ]] && prompt_opts+=(sp) + [[ -o promptsubst ]] && prompt_opts+=(subst) + zstyle -e :prompt-theme cleanup \ + 'zstyle -d :prompt-theme cleanup;' \ + 'prompt_default_setup;' \ + ${PS1+PS1="${(q)PS1}"} \ + ${PS2+PS2="${(q)PS2}"} \ + ${PS3+PS3="${(q)PS3}"} \ + ${PS4+PS4="${(q)PS4}"} \ + ${RPS1+RPS1="${(q)RPS1}"} \ + ${RPS2+RPS2="${(q)RPS2}"} \ + ${RPROMPT+RPROMPT="${(q)RPROMPT}"} \ + ${RPROMPT2+RPROMPT2="${(q)RPROMPT2}"} \ + ${PSVAR+PSVAR="${(q)PSVAR}"} \ + "precmd_functions=(${(q)precmd_functions[@]})" \ + "preexec_functions=(${(q)preexec_functions[@]})" \ + "prompt_opts=( ${prompt_opts[*]} )" \ + 'reply=(yes)' + } set_prompt "$@" - (( $#prompt_opts )) && - setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}" + (( ${#prompt_opts} )) && + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" true } prompt_preview_theme () { emulate -L zsh - local -a psv; psv=($psvar); local -a +h psvar; psvar=($psv) # Ick - local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 - local precmd_functions preexec_functions prompt_opts - local -aLl +h zle_highlight + # Check for proper state handling + (( $+prompt_preview_cleanup )) || { + prompt_preview_safely "$@" + return + } + + # Minimal preview for prompts that don't supply one + local -a prompt_opts print -n "$1 theme" (( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'" print ":" prompt_${1}_setup "$@[2,-1]" + (( ${#prompt_opts} )) && + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" [[ -n ${precmd_functions[(r)prompt_${1}_precmd]} ]] && prompt_${1}_precmd [[ -o promptcr ]] && print -n $'\r'; : -- cgit v1.2.3