zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Add localhistory state to ZLE_STATE
@ 2012-04-19 22:24 Mikael Magnusson
  2012-04-19 22:33 ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2012-04-19 22:24 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Add localhistory state to ZLE_STATE
  2012-04-19 22:24 PATCH: Add localhistory state to ZLE_STATE Mikael Magnusson
@ 2012-04-19 22:33 ` Mikael Magnusson
  2012-04-20 15:23   ` Vin Shelton
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2012-04-19 22:33 UTC (permalink / raw)
  To: zsh-workers

On 2012-04-20, Mikael Magnusson <mikachu@gmail.com> wrote:
> 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.
[...]
> +	    case 1:
> +		if (hist_skip_flags & HIST_FOREIGN) {
> +		    str = "globalhistory";
> +		} else {
> +		    str = "localhistory";
> +		}
> +		break;

Of course I managed to invert this test.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Add localhistory state to ZLE_STATE
  2012-04-19 22:33 ` Mikael Magnusson
@ 2012-04-20 15:23   ` Vin Shelton
  2012-04-20 15:29     ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Vin Shelton @ 2012-04-20 15:23 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-workers

I got a build failure on install.info:

tzsh.texi:15164: @item found outside of an insertion block.
tzsh.texi:15171: Unmatched `@end'.
makeinfo: Removing output file
`/home/opt/build/zsh-2012-04-20/Doc/infodir/zsh.info' due to errors;
use --force to preserve.
make[1]: *** [install.info] Error 1
make[1]: Leaving directory `/home/opt/build/zsh-2012-04-20/Doc'
make: *** [install.info] Error 2

I think there's an extra enditem() in the zle.yo patch:


Index: ChangeLog
===================================================================
RCS file: /cvsroot/zsh/zsh/ChangeLog,v
retrieving revision 1.5634
diff -u -0 -r1.5634 ChangeLog
--- ChangeLog	19 Apr 2012 22:37:41 -0000	1.5634
+++ ChangeLog	20 Apr 2012 15:20:53 -0000
@@ -0,0 +1,4 @@
+2012-04-20  Vin Shelton  <acs@xemacs.org>
+
+	* Doc/Zsh/zle.yo: Removed extra enditem.
+
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.99
diff -u -r1.99 zle.yo
--- Doc/Zsh/zle.yo	19 Apr 2012 22:37:41 -0000	1.99
+++ Doc/Zsh/zle.yo	20 Apr 2012 15:21:12 -0000
@@ -1470,7 +1470,6 @@
 line up to the cursor.
 This leaves the cursor in its original position.
 )
-enditem()
 tindex(set-local-history)
 item(tt(set-local-history))(
 By default, history movement commands visit the imported lines as well as


Regards,
  Vin


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Add localhistory state to ZLE_STATE
  2012-04-20 15:23   ` Vin Shelton
@ 2012-04-20 15:29     ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2012-04-20 15:29 UTC (permalink / raw)
  To: Vin Shelton; +Cc: zsh-workers

On 2012-04-20, Vin Shelton <acs@alumni.princeton.edu> wrote:
> I got a build failure on install.info:
[...]
> *** [install.info] Error 2
>
> I think there's an extra enditem() in the zle.yo patch:

Thanks, when I added it I didn't look to carefully and just assumed
the enditem() was paired with the item() for each entry.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-20 15:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-19 22:24 PATCH: Add localhistory state to ZLE_STATE Mikael Magnusson
2012-04-19 22:33 ` Mikael Magnusson
2012-04-20 15:23   ` Vin Shelton
2012-04-20 15:29     ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).