zsh-workers
 help / color / mirror / code / Atom feed
* Regarding emulate: a thought, and refresh my memory?
@ 2012-03-04  1:25 Bart Schaefer
  2012-03-06  8:27 ` PATCH " Bart Schaefer
  2012-03-06 20:06 ` Peter Stephenson
  0 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 2012-03-04  1:25 UTC (permalink / raw)
  To: zsh-workers

First the memory bump:

The code in bin_emulate dating all the way back to Andrej's patch in
zsh-workers/26425 rejects the combination of -L and -c.  The stated
reason for this is "do not confuse user who reads manuals."  However,
the -c option always restores everything at the end, and anyway one
can always run
    emulate zsh -c 'setopt localoptions; ...'
so I'm hoping someone can remind me why we bother throwing an error
on that combination.

The reason I ask is because it suddenly popped into my head that the
emulate command might just as well parse other startup-time options
besides just -c.  Primarily this means that instead of e.g.

    emulate zsh -c 'setopt xtrace; blah blah blah ...'

one could simply do

    emulate zsh -x -c 'blah blah blah ...'

Simlarly there are all sorts of functions that begin with stuff like

    emulate -R zsh
    setopt extendedglob

which could become

    emulate -R zsh -o extendedglob

and off you go.

I've got this 98% working by factoring a loop out of init.c:parseargs()
but it seems silly that
    emulate -L zsh -c '...'
throws an error when
    emulate zsh --localoptions -c '...'
does not.  (Of course -L means a bit more than --localoptions, but you
see my point, I hope.)


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

* PATCH Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-04  1:25 Regarding emulate: a thought, and refresh my memory? Bart Schaefer
@ 2012-03-06  8:27 ` Bart Schaefer
  2012-03-06 20:06 ` Peter Stephenson
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2012-03-06  8:27 UTC (permalink / raw)
  To: zsh-workers

On Mar 3,  5:25pm, Bart Schaefer wrote:
}
} The reason I ask is because it suddenly popped into my head that the
} emulate command might just as well parse other startup-time options
} besides just -c.

Never got any reply to that, but here for consideration is the patch.
In the documentation, we have way too many things called "option", so
I took to using "switch" for -L / -R and "flag" for what comes after
the shell name (because that's what the Invocation section calls them),
leaving "option" for the stuff you frob with setopt.  Fixed a cross-
reference while I was at it.

The init.c hunks look bigger than they really are because of moving a
chunk out of the middle of parseargs().

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.137
diff -u -r1.137 builtins.yo
--- Doc/Zsh/builtins.yo	1 Mar 2012 13:00:53 -0000	1.137
+++ Doc/Zsh/builtins.yo	6 Mar 2012 08:15:26 -0000
@@ -348,7 +348,7 @@
 cindex(sh, compatibility)
 cindex(ksh, compatibility)
 cindex(csh, compatibility)
-item(tt(emulate) [ tt(-LR) ] [ {tt(zsh)|tt(sh)|tt(ksh)|tt(csh)} [ tt(-c) tt(arg) ] ])(
+item(tt(emulate) [ tt(-LR) ] [ {tt(zsh)|tt(sh)|tt(ksh)|tt(csh)} [ var(flags) ... ] ])(
 Without any argument print current emulation mode.
 
 With single argument set up zsh options to emulate the specified shell
@@ -359,7 +359,7 @@
 argument are the same as those used to determine the emulation at startup
 based on the shell name, see
 ifzman(\
-the section `Compatibility' in zmanref(zshmisc)
+the section COMPATIBILITY in zmanref(zsh)
 )\
 ifnzman(\
 noderef(Compatibility)
@@ -373,26 +373,34 @@
 tt(eval) commands is not considered to be running directly from the
 function, hence does not provoke this behaviour.
 
-If the tt(-R) option is given, all options
+If the tt(-R) switch is given, all settable options
 are reset to their default value corresponding to the specified emulation
 mode, except for certain options describing the interactive
 environment; otherwise, only those options likely to cause portability
-problems in scripts and functions are altered.  If the tt(-L) option is given,
+problems in scripts and functions are altered.  If the tt(-L) switch is given,
 the options tt(LOCAL_OPTIONS) and tt(LOCAL_TRAPS) will be set as
 well, causing the effects of the tt(emulate) command and any tt(setopt) and
 tt(trap) commands to be local to the immediately surrounding shell
 function, if any; normally these options are turned off in all emulation
-modes except tt(ksh). The tt(-L) and tt(-c) are mutually exclusive.
+modes except tt(ksh). The tt(-L) switch is mutually exclusive with the
+use of tt(-c) in var(flags).
 
-If tt(-c) tt(arg) is given, evaluate tt(arg) while the requested
-emulation is temporarily in effect.  The emulation and all options will
-be restored to their original values before tt(emulate) returns.  The
-tt(-R) flag may be used.
+The var(flags) may be any of the invocation-time flags described in
+ifnzman(noderef(Invocation))\
+ifzman(the section INVOCATION in zmanref(zsh)),
+except that `tt(-o EMACS)' and `tt(-o VI)' may not be used.  Flags such
+as `tt(+r)'/`tt(+o restricted)' may be prohibited in some circumstances.
+If tt(-c) var(arg) appears in var(flags), var(arg) is evaluated while the
+requested emulation is temporarily in effect.  In this case the emulation
+mode and all options are restored to their previous values before
+tt(emulate) returns.  The tt(-R) switch may precede the name of the shell
+to emulate; note this has a meaning distinct from including tt(-R) in
+var(flags).
 
 Use of tt(-c) enables `sticky' emulation mode for functions defined
 within the evaluated expression:  the emulation mode is associated
 thereafter with the function so that whenever the function is executed
-the emulation (respecting the tt(-R) flag, if present) and all
+the emulation (respecting the tt(-R) switch, if present) and all
 options are set before entry to the function, and restored after exit.
 If the function is called when the sticky emulation is already in
 effect, either within an `tt(emulate) var(shell) tt(-c)' expression or
@@ -434,7 +442,7 @@
 sitem(3.)(No special handling is provided for functions marked for
 tt(autoload) nor for functions present in wordcode created by
 the tt(zcompile) command.)
-sitem(4.)(The presence or absence of the tt(-R) flag to tt(emulate)
+sitem(4.)(The presence or absence of the tt(-R) switch to tt(emulate)
 corresponds to different sticky emulation modes, so for example
 `tt(emulate sh -c)', `tt(emulate -R sh -c)' and `tt(emulate csh -c)'
 are treated as three distinct sticky emulations.)
Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.66
diff -u -r1.66 params.yo
--- Doc/Zsh/params.yo	7 Sep 2011 13:40:24 -0000	1.66
+++ Doc/Zsh/params.yo	6 Mar 2012 08:15:27 -0000
@@ -1003,6 +1003,10 @@
 backquotes only.  Should the chosen character be one of singlequote,
 doublequote or backquote, there must also be an odd number of them
 on the command line for the last one to be removed.
+
+For backward compabitility, if the tt(SUNKEYBOARDHACK) option is
+explicitly set, the value of tt(KEYBOARD_HACK) reverts to backquote.
+If the option is explicitly unset, this variable is set to empty.
 )
 vindex(KEYTIMEOUT)
 item(tt(KEYTIMEOUT))(
Index: Etc/FAQ.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Etc/FAQ.yo,v
retrieving revision 1.63
diff -u -r1.63 FAQ.yo
--- Etc/FAQ.yo	23 Feb 2012 21:39:31 -0000	1.63
+++ Etc/FAQ.yo	6 Mar 2012 08:15:29 -0000
@@ -722,7 +722,7 @@
      appear inside the tt({ }) the way they get appended to an alias.
 
   myeit() If the csh alias references its own name (tt(alias rm "rm -i")),
-     then in a zsh function you need the "command" keyword
+     then in a zsh function you need the "command" or "builtin" keyword
      (function tt(rm() { command rm -i "$@" })), but in a zsh alias
      you don't (tt(alias rm="rm -i")).
 
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.255
diff -u -r1.255 builtin.c
--- Src/builtin.c	5 Feb 2012 19:28:16 -0000	1.255
+++ Src/builtin.c	6 Mar 2012 08:15:34 -0000
@@ -58,7 +58,7 @@
     BUILTIN("disable", 0, bin_enable, 0, -1, BIN_DISABLE, "afmrs", NULL),
     BUILTIN("disown", 0, bin_fg, 0, -1, BIN_DISOWN, NULL, NULL),
     BUILTIN("echo", BINF_SKIPINVALID, bin_print, 0, -1, BIN_ECHO, "neE", "-"),
-    BUILTIN("emulate", 0, bin_emulate, 0, 3, 0, "LR", NULL),
+    BUILTIN("emulate", 0, bin_emulate, 0, -1, 0, "LR", NULL),
     BUILTIN("enable", 0, bin_enable, 0, -1, BIN_ENABLE, "afmrs", NULL),
     BUILTIN("eval", BINF_PSPECIAL, bin_eval, 0, -1, BIN_EVAL, NULL, NULL),
     BUILTIN("exit", BINF_PSPECIAL, bin_break, 0, 1, BIN_EXIT, NULL, NULL),
@@ -4958,14 +4958,14 @@
 {
     int opt_L = OPT_ISSET(ops, 'L');
     int opt_R = OPT_ISSET(ops, 'R');
-    int saveemulation, savesticky_emulation;
-    int ret;
+    int saveemulation, savesticky_emulation, savehackchar;
+    int ret = 1;
     char saveopts[OPT_SIZE];
+    char *cmd = 0;
+    const char *shname = *argv;
 
     /* without arguments just print current emulation */
-    if (!*argv) {
-	const char *shname;
-
+    if (!shname) {
 	if (opt_L || opt_R) {
 	    zwarnnam("emulate", "not enough arguments");
 	    return 1;
@@ -4995,39 +4995,46 @@
 
     /* with single argument set current emulation */
     if (!argv[1]) {
-	emulate(*argv, OPT_ISSET(ops,'R'));
+	emulate(shname, OPT_ISSET(ops,'R'));
 	if (OPT_ISSET(ops,'L'))
 	    opts[LOCALOPTIONS] = opts[LOCALTRAPS] = 1;
 	return 0;
     }
 
-    /* If "-c command" is given, evaluate command using specified
-     * emulation mode.
-     */
-    if (strcmp(argv[1], "-c")) {
-	zwarnnam("emulate", "unknown argument %s", argv[1]);
-	return 1;
-    }
+    argv++;
+    memcpy(saveopts, opts, sizeof(opts));
+    savehackchar = keyboardhackchar;
+    cmd = parseopts("emulate", &argv);
 
-    if (!argv[2]) {
-	zwarnnam("emulate", "not enough arguments");
-	return 1;
+    /* parseopts() has consumed anything that looks like an option */
+    if (*argv) {
+	zwarnnam("emulate", "unknown argument %s", *argv);
+	goto restore;
     }
 
-    if (opt_L) {
-	zwarnnam("emulate", "option -L incompatible with -c");
-	return 1;
-    }
+    /* If "-c command" is given, evaluate command using specified
+     * emulation mode.
+     */
+    if (cmd) {
+	if (opt_L) {
+	    zwarnnam("emulate", "option -L incompatible with -c");
+	    goto restore;
+	}
+	*--argv = cmd;	/* on stack, never free()d, see execbuiltin() */
+    } else
+	return 0;
 
-    memcpy(saveopts, opts, sizeof(opts));
     saveemulation = emulation;
     savesticky_emulation = sticky_emulation;
-    emulate(*argv, OPT_ISSET(ops,'R'));
+    emulate(shname, OPT_ISSET(ops,'R'));
     sticky_emulation = emulation;
-    ret = eval(argv+2);
-    memcpy(opts, saveopts, sizeof(opts));
+    ret = eval(argv);
     sticky_emulation = savesticky_emulation;
     emulation = saveemulation;
+ restore:
+    memcpy(opts, saveopts, sizeof(opts));
+    keyboardhackchar = savehackchar;
+    inittyptab();	/* restore banghist */
     return ret;
 }
 
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.122
diff -u -r1.122 init.c
--- Src/init.c	5 Jan 2012 20:01:25 -0000	1.122
+++ Src/init.c	6 Mar 2012 08:15:34 -0000
@@ -215,6 +215,7 @@
     return LOOP_OK;
 }
 
+/* Shared among parseargs(), parseopts(), init_io(), and init_misc() */
 static char *cmd;
 static int restricted;
 
@@ -222,9 +223,7 @@
 static void
 parseargs(char **argv, char **runscript)
 {
-    int optionbreak = 0;
     char **x;
-    int action, optno;
     LinkList paramlist;
 
     argzero = *argv++;
@@ -247,6 +246,49 @@
     opts[SHINSTDIN] = 0;
     opts[SINGLECOMMAND] = 0;
 
+    cmd = parseopts(NULL, &argv);
+
+    paramlist = znewlinklist();
+    if (*argv) {
+	if (unset(SHINSTDIN)) {
+	    if (cmd)
+		argzero = *argv;
+	    else
+		*runscript = *argv;
+	    opts[INTERACTIVE] &= 1;
+	    argv++;
+	}
+	while (*argv)
+	    zaddlinknode(paramlist, ztrdup(*argv++));
+    } else if (!cmd)
+	opts[SHINSTDIN] = 1;
+    if(isset(SINGLECOMMAND))
+	opts[INTERACTIVE] &= 1;
+    opts[INTERACTIVE] = !!opts[INTERACTIVE];
+    if (opts[MONITOR] == 2)
+	opts[MONITOR] = opts[INTERACTIVE];
+    if (opts[HASHDIRS] == 2)
+	opts[HASHDIRS] = opts[INTERACTIVE];
+    pparams = x = (char **) zshcalloc((countlinknodes(paramlist) + 1) * sizeof(char *));
+
+    while ((*x++ = (char *)getlinknode(paramlist)));
+    free(paramlist);
+    argzero = ztrdup(argzero);
+}
+
+/**/
+mod_export char *
+parseopts(char *nam, char ***argvp)
+{
+    int optionbreak = 0;
+    int action, optno;
+    char *cmd = 0;	/* deliberately hides static */
+    char **argv = *argvp;
+
+#define WARN_OPTION(F, S) if (nam) zwarnnam(nam, F, S); else zerr(F, S)
+#define LAST_OPTION(N) \
+	if (nam) { if (*argv) argv++; goto doneargv; } else exit(N)
+
     /* loop through command line options (begins with "-" or "+") */
     while (!optionbreak && *argv && (**argv == '-' || **argv == '+')) {
 	char *args = *argv;
@@ -267,11 +309,11 @@
 		if (!strcmp(*argv, "version")) {
 		    printf("zsh %s (%s-%s-%s)\n",
 			    ZSH_VERSION, MACHTYPE, VENDOR, OSTYPE);
-		    exit(0);
+		    LAST_OPTION(0);
 		}
 		if (!strcmp(*argv, "help")) {
 		    printhelp();
-		    exit(0);
+		    LAST_OPTION(0);
 		}
 		/* `-' characters are allowed in long options */
 		for(args = *argv; *args; args++)
@@ -292,73 +334,54 @@
 		if (!*++*argv)
 		    argv++;
 		if (!*argv) {
-		    zerr("string expected after -o");
-		    exit(1);
+		    WARN_OPTION("string expected after -o", NULL);
+		    LAST_OPTION(1);
 		}
 	    longoptions:
 		if (!(optno = optlookup(*argv))) {
-		    zerr("no such option: %s", *argv);
-		    exit(1);
-		} else if (optno == RESTRICTED)
+		    WARN_OPTION("no such option: %s", *argv);
+		    LAST_OPTION(1);
+		} else if (optno == RESTRICTED && !nam)
 		    restricted = action;
-		else
-		    dosetopt(optno, action, 1);
+		else if ((optno == EMACSMODE || optno == VIMODE) && nam)
+		    WARN_OPTION("can't change option: %s", *argv);
+		else if (dosetopt(optno, action, !nam) && nam)
+		    WARN_OPTION("can't change option: %s", *argv);
               break;
 	    } else if (isspace(STOUC(**argv))) {
 		/* zsh's typtab not yet set, have to use ctype */
 		while (*++*argv)
 		    if (!isspace(STOUC(**argv))) {
-		    badoptionstring:
-			zerr("bad option string: `%s'", args);
-			exit(1);
+		     badoptionstring:
+			WARN_OPTION("bad option string: '%s'", args);
+			LAST_OPTION(1);
 		    }
 		break;
 	    } else {
 	    	if (!(optno = optlookupc(**argv))) {
-		    zerr("bad option: -%c", **argv);
-		    exit(1);
-		} else if (optno == RESTRICTED)
+		    WARN_OPTION("bad option: -%c", **argv);
+		    LAST_OPTION(1);
+		} else if (optno == RESTRICTED && !nam)
 		    restricted = action;
-		else
-		    dosetopt(optno, action, 1);
+		else if ((optno == EMACSMODE || optno == VIMODE) && nam)
+		    WARN_OPTION("can't change option: %s", *argv);
+		else if (dosetopt(optno, action, !nam) && nam)
+		    WARN_OPTION("can't change option: -%c", **argv);
 	    }
 	}
 	argv++;
     }
-    doneoptions:
-    paramlist = znewlinklist();
+ doneoptions:
     if (cmd) {
 	if (!*argv) {
-	    zerr("string expected after -%s", cmd);
-	    exit(1);
+	    WARN_OPTION("string expected after -%s", cmd);
+	    LAST_OPTION(1);
 	}
 	cmd = *argv++;
     }
-    if (*argv) {
-	if (unset(SHINSTDIN)) {
-	    if (cmd)
-		argzero = *argv;
-	    else
-		*runscript = *argv;
-	    opts[INTERACTIVE] &= 1;
-	    argv++;
-	}
-	while (*argv)
-	    zaddlinknode(paramlist, ztrdup(*argv++));
-    } else if (!cmd)
-	opts[SHINSTDIN] = 1;
-    if(isset(SINGLECOMMAND))
-	opts[INTERACTIVE] &= 1;
-    opts[INTERACTIVE] = !!opts[INTERACTIVE];
-    if (opts[MONITOR] == 2)
-	opts[MONITOR] = opts[INTERACTIVE];
-    if (opts[HASHDIRS] == 2)
-	opts[HASHDIRS] = opts[INTERACTIVE];
-    pparams = x = (char **) zshcalloc((countlinknodes(paramlist) + 1) * sizeof(char *));
-
-    while ((*x++ = (char *)getlinknode(paramlist)));
-    free(paramlist);
-    argzero = ztrdup(argzero);
+ doneargv:
+    *argvp = argv;
+    return cmd;
 }
 
 /**/
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.60
diff -u -r1.60 options.c
--- Src/options.c	1 Mar 2012 13:00:53 -0000	1.60
+++ Src/options.c	6 Mar 2012 08:15:35 -0000
@@ -767,6 +767,8 @@
 	    return -1;
 #endif /* GETPWNAM_FAKED */
     } else if ((optno == EMACSMODE || optno == VIMODE) && value) {
+	if (sticky_emulation)
+	    return -1;
 	zleentry(ZLE_CMD_SET_KEYMAP, optno);
 	opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] = 0;
     } else if (optno == SUNKEYBOARDHACK) {


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-04  1:25 Regarding emulate: a thought, and refresh my memory? Bart Schaefer
  2012-03-06  8:27 ` PATCH " Bart Schaefer
@ 2012-03-06 20:06 ` Peter Stephenson
  2012-03-06 20:22   ` Stephane Chazelas
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2012-03-06 20:06 UTC (permalink / raw)
  To: zsh-workers

On Sat, 03 Mar 2012 17:25:21 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> The code in bin_emulate dating all the way back to Andrej's patch in
> zsh-workers/26425 rejects the combination of -L and -c.  The stated
> reason for this is "do not confuse user who reads manuals."  However,
> the -c option always restores everything at the end, and anyway one
> can always run
>     emulate zsh -c 'setopt localoptions; ...'
> so I'm hoping someone can remind me why we bother throwing an error
> on that combination.

I can't imagine there's anything fundamental about it.
 
> The reason I ask is because it suddenly popped into my head that the
> emulate command might just as well parse other startup-time options
> besides just -c.

Can't see why not.  I often do "emulate -L zsh; setopt extendedglob
cbases", it would be sensible to put that in one command.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-06 20:06 ` Peter Stephenson
@ 2012-03-06 20:22   ` Stephane Chazelas
  2012-03-07  6:38     ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Stephane Chazelas @ 2012-03-06 20:22 UTC (permalink / raw)
  To: zsh-workers

2012-03-06 20:06:52 +0000, Peter Stephenson:
[...]
> Can't see why not.  I often do "emulate -L zsh; setopt extendedglob
> cbases", it would be sensible to put that in one command.
[...]

What about special parameters like:

zsh_options=(noshwordsplit noposixstrings...)

emulate -L $zsh_options extendedglob

-- 
Stephane


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-06 20:22   ` Stephane Chazelas
@ 2012-03-07  6:38     ` Bart Schaefer
  2012-03-07 11:34       ` Stephane Chazelas
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2012-03-07  6:38 UTC (permalink / raw)
  To: zsh-workers

On Mar 6,  8:22pm, Stephane Chazelas wrote:
} Subject: Re: Regarding emulate: a thought, and refresh my memory?
}
} 2012-03-06 20:06:52 +0000, Peter Stephenson:
} [...]
} > Can't see why not.  I often do "emulate -L zsh; setopt extendedglob
} > cbases", it would be sensible to put that in one command.
} [...]
} 
} What about special parameters like:
} 
} zsh_options=(noshwordsplit noposixstrings...)
} 
} emulate -L $zsh_options extendedglob

Yes, that's the idea, just not the precise formulation.

The first word (that doesn't begin with a hyphen) seen by "emulate" has
to be the name of the emulation mode.  So, based on PWS's feedback I've
just committed 30320, which enables for example this:

    zsh_options=(noshwordsplit noposixstrings ...)

    emulate -L zsh --$^zsh_options --extendedglob

Hmm, I should probably add a bit of doc to the description of the -c
flag pointing out that only the emulation mode is sticky, not the full
set of options one might throw in.

Unless PWS, who knows more about how the sticky emulation works than
I do, has a clever idea about that?


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-07  6:38     ` Bart Schaefer
@ 2012-03-07 11:34       ` Stephane Chazelas
  2012-03-07 17:45         ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Stephane Chazelas @ 2012-03-07 11:34 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

2012-03-06 22:38:06 -0800, Bart Schaefer:
> On Mar 6,  8:22pm, Stephane Chazelas wrote:
> } Subject: Re: Regarding emulate: a thought, and refresh my memory?
> }
> } 2012-03-06 20:06:52 +0000, Peter Stephenson:
> } [...]
> } > Can't see why not.  I often do "emulate -L zsh; setopt extendedglob
> } > cbases", it would be sensible to put that in one command.
> } [...]
> } 
> } What about special parameters like:
> } 
> } zsh_options=(noshwordsplit noposixstrings...)
> } 
> } emulate -L $zsh_options extendedglob
> 
> Yes, that's the idea, just not the precise formulation.
> 
> The first word (that doesn't begin with a hyphen) seen by "emulate" has
> to be the name of the emulation mode.  So, based on PWS's feedback I've
> just committed 30320, which enables for example this:
> 
>     zsh_options=(noshwordsplit noposixstrings ...)
> 
>     emulate -L zsh --$^zsh_options --extendedglob
> 
> Hmm, I should probably add a bit of doc to the description of the -c
> flag pointing out that only the emulation mode is sticky, not the full
> set of options one might throw in.
> 
> Unless PWS, who knows more about how the sticky emulation works than
> I do, has a clever idea about that?
[...]

Sorry, I realise I wrote the opposite of what I meant.

What I meant was that instead of introducing a  cumbersome
confusing syntax, We could get rid of "emulate" (yes the
contrary of what I actually wrote) and do it with setopt.

Instead of "emulate zsh", do "setopt $zsh_options", and instead of 
"emulate -L zsh", "setopt localoptions $zsh_options", where
$zsh_options is a special parameters that contains the option
settings needed to /emulate/ zsh.

What do you think?
-- 
Stephane


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-07 11:34       ` Stephane Chazelas
@ 2012-03-07 17:45         ` Bart Schaefer
  2012-03-08  8:38           ` Stephane Chazelas
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2012-03-07 17:45 UTC (permalink / raw)
  To: zsh-workers

On Mar 7, 11:34am, Stephane Chazelas wrote:
}
} Sorry, I realise I wrote the opposite of what I meant.
} 
} What I meant was that instead of introducing a  cumbersome
} confusing syntax, We could get rid of "emulate" (yes the
} contrary of what I actually wrote) and do it with setopt.

That doesn't cover the "emulate zsh -c ..." semantics.  To replace
the current (even without workers/30320) emulate behavior, we'd need:

(1) two special parameters for each emulation mode, one with the set
of options from "emulate -R" and the other the minimal set;
(2) an extension of the "eval" command to unwind the option state and
implement "sticky emulation" (this can't be based on localoptions as
the emulated code needs license to freely change that);
(3) a different mechanism to control the (small) set of behaviors that
depend on the global emulation mode rather than on the setopt values;
(4) a replacement for the other use of "emulate" which is to test what
the current emulation mode *is*, e.g., to be able to discover that the
shell was started with ARGV0=sh or similar.

I'm not sure the sum of that ends up being any less cumbersome, not
to mention breaking ten years' worth of zsh functions that start with
"emulate -LR zsh".

I also disagree that the emulate syntax is cumbersome or confusing,
as it's very similar to sticking the word "emulate" in front of the
command you'd use to start a new external shell.  When using -c it's
cumbersome to properly quote a whole function definition, but to fix
that "emulate" (or "eval" in (2) above) would have to be a keyword.

"emulate zsh -c ..." is actually pretty close in semantics to
"function { setopt localoptions $zsh_options; ... }" except for the
parenthetical caveat in (2) above, so if not for (3) above we could
use an extension to the function keyword instead of eval, which would
eliminate the quoting problem without creating any new keywords.
This may be worth thinking about, independently of emulate-vs-setopt.

-- 
Barton E. Schaefer


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-07 17:45         ` Bart Schaefer
@ 2012-03-08  8:38           ` Stephane Chazelas
  2012-03-08 15:08             ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Stephane Chazelas @ 2012-03-08  8:38 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

2012-03-07 09:45:36 -0800, Bart Schaefer:
[...]
> I also disagree that the emulate syntax is cumbersome or confusing,
[...]

Sorry, I probably misread this thread (I admit very quickly). I
just thought it was.

"
Instead of
emulate -L zsh
setopt extendedglob

we could have a new syntax that does

emulate -L zsh -c 'setopt extendedglob'
"

Upon which I thought, gosh, there has to be something simpler
hence the

setopt localoptions $zsh_options extendedglob

-- 
Stephane


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

* Re: Regarding emulate: a thought, and refresh my memory?
  2012-03-08  8:38           ` Stephane Chazelas
@ 2012-03-08 15:08             ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2012-03-08 15:08 UTC (permalink / raw)
  To: zsh-workers

On Mar 8,  8:38am, Stephane Chazelas wrote:
}
} Sorry, I probably misread this thread (I admit very quickly). I
} just thought it was.
} 
} "
} Instead of
} emulate -L zsh
} setopt extendedglob
} 
} we could have a new syntax that does
} 
} emulate -L zsh -c 'setopt extendedglob'
} "

No, that thread came and went back in January 2009.  The syntax for
"emulate zsh -c ..." is two years old ... but this thread *is* about
making it less necessary to put setopt commands inside the string
that is passed with -c.


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

end of thread, other threads:[~2012-03-08 15:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-04  1:25 Regarding emulate: a thought, and refresh my memory? Bart Schaefer
2012-03-06  8:27 ` PATCH " Bart Schaefer
2012-03-06 20:06 ` Peter Stephenson
2012-03-06 20:22   ` Stephane Chazelas
2012-03-07  6:38     ` Bart Schaefer
2012-03-07 11:34       ` Stephane Chazelas
2012-03-07 17:45         ` Bart Schaefer
2012-03-08  8:38           ` Stephane Chazelas
2012-03-08 15:08             ` Bart Schaefer

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).