From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29154 invoked by alias); 19 Apr 2012 22:49:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30425 Received: (qmail 546 invoked from network); 19 Apr 2012 22:48:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.212.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer; bh=Fn0yCQK9bnkBguQJf0iOCoB6hwfUIZwcdLY0alB1Y00=; b=IkeLWcmoPxf3AdXfhnngW6d0YBh+OaUDi9ti3Y5lI4TFrRkD/GjD52zZPuoHG27UAi EQ9smBRq0KRtwiCBlzV+lCIXSXbQCIalrMqnscs52iYeijqXzzMpfIZuFVhgbRr64Yor DwSW7emIRNoJpwNZ3NpYhmxJC6cWToynY1blWBLuTE5Q/Xr8l32bmJWnjK6VhVjX+La1 Lt5s3pi3yFmP3QhB5OQ0SaO8HTKMQKGRa2F/m07zwUwITOvyITF2qz90PoaY9/afoZNy +pV21mgQHwDq+68EUf/8rAwUJxJopIt9YLu5CqhIStinyupsYBg2XOnOAGnHbs6Pexau AyFA== From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Add localhistory state to ZLE_STATE Date: Fri, 20 Apr 2012 00:24:35 +0200 Message-Id: <1334874275-1000-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 1.7.10.GIT The sorting is possibly a bit of a hack. This lets you make wrappers that use set-local-history without changing the global setting, or show the current setting in the prompt, or whatever. function _set_local_history() { local oldstate=$ZLE_STATE zle .set-local-history if [[ $ZLE_STATE == $oldstate ]]; then return fi if [[ $ZLE_STATE == *globalhistory* ]]; then psvar[8]=(1) else psvar[8]=() fi zle reset-prompt } zle -N set-local-history _set_local_history function _local_history_command { if [[ $ZLE_STATE == *localhistory* ]]; then zle ${WIDGET#local-} return fi zle .set-local-history -n 1 zle ${WIDGET#local-} zle .set-local-history -n 0 } zle -N local-down-history _local_history_command zle -N local-up-history _local_history_command bindkey '^X^P' local-up-history bindkey '^X^N' local-down-history --- Doc/Zsh/zle.yo | 19 ++++++++++++++----- Src/Zle/zle_params.c | 28 ++++++++++++++++++---------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index f9c20de..86e139f 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -918,11 +918,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 4c32d18..e050cd6 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -712,21 +712,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: @@ -736,6 +732,13 @@ get_zle_state(UNUSED(Param pm)) str = "overwrite"; } break; + case 1: + if (hist_skip_flags & HIST_FOREIGN) { + str = "globalhistory"; + } else { + str = "localhistory"; + } + break; default: str = ""; @@ -749,7 +752,7 @@ get_zle_state(UNUSED(Param pm)) } else { /* Accumulating string */ if (istate) - *ptr++ = ' '; + *ptr++ = ':'; memcpy(ptr, str, slen); ptr += slen; } @@ -761,6 +764,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; } -- 1.7.10.GIT