diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Doc/Zsh/zle.yo | 19 | ||||
-rw-r--r-- | Src/Zle/zle_params.c | 28 |
3 files changed, 37 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog index 3ef0c6946..6d33c4d90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ Functions/Zle/url-quote-magic: add missing local for match, mbegin and mend. + * 30425 (fixed): Src/Zle/zle_params.c, Doc/Zsh/zle.yo: + Add localhistory/globalhistory to $ZLE_STATE as set by the + set-local-history zle widget. + 2012-05-01 Peter Stephenson <p.w.stephenson@ntlworld.com> * users/17046: Src/utils.c, Test/D04parameter.ztst: don't @@ -16267,5 +16271,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5646 $ +* $Revision: 1.5647 $ ***************************************************** diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index bfbddc7d1..3e8c25a90 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -908,11 +908,20 @@ item(tt(ZLE_STATE) (scalar))( Contains a set of space-separated words that describe the current tt(zle) state. -Currently, the only state shown is the insert mode as set by the -tt(overwrite-mode) or tt(vi-replace) widgets. The string contains -`tt(insert)' if characters to be inserted on the command line move existing -characters to the right, `tt(overwrite)' if characters to be inserted -overwrite existing characters. +Currently, the states shown are the insert mode as set by the +tt(overwrite-mode) or tt(vi-replace) widgets and whether history commands +will visit imported entries as controlled by the set-local-history widget. +The string contains `tt(insert)' if characters to be inserted on the +command line move existing characters to the right or `tt(overwrite)' +if characters to be inserted overwrite existing characters. It contains +`tt(localhistory)' if only local history commands will be visited or +`tt(globalhistory)' if imported history commands will also be visited. + +The substrings are sorted in alphabetical order so that if you want to +test for two specific substrings in a future-proof way, you can do match +by doing: + +example(if [[ $ZLE_STATE == *insert*globalhistory* ]]; then ...; fi) ) enditem() diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index 1a39df862..03c6261f5 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -709,21 +709,17 @@ get_context(UNUSED(Param pm)) static char * get_zle_state(UNUSED(Param pm)) { - char *zle_state = NULL, *ptr = NULL; + char *zle_state = NULL, *ptr = NULL, **arr = NULL; int itp, istate, len = 0; /* - * When additional substrings are added, they should be kept in - * alphabetical order, so the user can easily match against this - * parameter: if [[ $ZLE_STATE == *bar*foo*zonk* ]]; then ...; fi + * Substrings are sorted at the end, so the user can + * easily match against this parameter: + * if [[ $ZLE_STATE == *bar*foo*zonk* ]]; then ...; fi */ for (itp = 0; itp < 2; itp++) { char *str; - /* - * Currently there is only one state: insert or overwrite. - * This loop is to make it easy to add others. - */ - for (istate = 0; istate < 1; istate++) { + for (istate = 0; istate < 2; istate++) { int slen; switch (istate) { case 0: @@ -733,6 +729,13 @@ get_zle_state(UNUSED(Param pm)) str = "overwrite"; } break; + case 1: + if (hist_skip_flags & HIST_FOREIGN) { + str = "localhistory"; + } else { + str = "globalhistory"; + } + break; default: str = ""; @@ -746,7 +749,7 @@ get_zle_state(UNUSED(Param pm)) } else { /* Accumulating string */ if (istate) - *ptr++ = ' '; + *ptr++ = ':'; memcpy(ptr, str, slen); ptr += slen; } @@ -758,6 +761,11 @@ get_zle_state(UNUSED(Param pm)) *ptr = '\0'; } } + + arr = colonsplit(zle_state, 0); + strmetasort(arr, SORTIT_ANYOLDHOW, NULL); + zle_state = zjoin(arr, ' ', 1); + freearray(arr); return zle_state; } |