zsh-workers
 help / color / mirror / code / Atom feed
* Re: False alarm (nonomatch and cshnullglob)
       [not found] <960722151122.ZM10323@candle.brasslantern.com>
@ 1996-07-23  7:31 ` Peter Stephenson
  1996-07-23  8:34   ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 1996-07-23  7:31 UTC (permalink / raw)
  To: Zsh hackers list

schaefer@candle.brasslantern.com wrote:
> zsh% setopt nobadpattern nonomatch
> zsh% echo ( Make | buy )
> zsh: no match
> 
> I forgot that I also have cshnullglob set.

I suppose that's right, since the manual says that nullglob overrides
nonomatch, and (elsewhere) that cshnullglob overrides nullglob, but it
does seem a bit of a palaver deciding on the behaviour, easy to get
confused, and hard to set the behaviour you want if there are default
settings in /etc/zshrc.  Still, there doesn't seem to be much to do
without a really radical options overhaul (setopt
nomatch=csh/null/none would be nice).

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-23  7:31 ` False alarm (nonomatch and cshnullglob) Peter Stephenson
@ 1996-07-23  8:34   ` Bart Schaefer
  1996-07-23 17:35     ` Zoltan Hidvegi
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 1996-07-23  8:34 UTC (permalink / raw)
  To: Peter Stephenson, Zsh hackers list

On Jul 23,  9:31am, Peter Stephenson wrote:
} Subject: Re: False alarm (nonomatch and cshnullglob)
}
} schaefer@candle.brasslantern.com wrote:
} > zsh% setopt nobadpattern nonomatch
} > zsh% echo ( Make | buy )
} > zsh: no match
} > 
} > I forgot that I also have cshnullglob set.
} 
} does seem a bit of a palaver deciding on the behaviour, easy to get
} confused, and hard to set the behaviour you want if there are default
} settings in /etc/zshrc.

Someone previously suggested that options should be heirarchical, or
somehow otherwise related, so that (e.g.) "setopt nonomatch" would
automatically imply "unsetopt nullglob cshnullglob".

} Still, there doesn't seem to be much to do
} without a really radical options overhaul (setopt
} nomatch=csh/null/none would be nice).

The advantage to csh's scheme of having magic variable names for the
options is that you can easily convert booleans to have more than two
values, without changing the syntax of setting options in general and
without losing the old set/unset boolean meaning.

The disadvantages are cluttering the variable namespace and increasing
the amount of memory required to store a simple truth value.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-23  8:34   ` Bart Schaefer
@ 1996-07-23 17:35     ` Zoltan Hidvegi
  1996-07-23 20:18       ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Zoltan Hidvegi @ 1996-07-23 17:35 UTC (permalink / raw)
  To: schaefer; +Cc: pws, zsh-workers

> Someone previously suggested that options should be heirarchical, or
> somehow otherwise related, so that (e.g.) "setopt nonomatch" would
> automatically imply "unsetopt nullglob cshnullglob".

Perhaps that would be nice but I'm not sure it worth the extra code it adds.

> The advantage to csh's scheme of having magic variable names for the
> options is that you can easily convert booleans to have more than two
> values, without changing the syntax of setting options in general and
> without losing the old set/unset boolean meaning.

It would not be difficult to add the setopt option=value syntax.  Options
are stored in a char array so this can be done without changing the array.
But I still do not see how can such a feature be used.

Zoltan



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-23 17:35     ` Zoltan Hidvegi
@ 1996-07-23 20:18       ` Bart Schaefer
  1996-07-23 21:58         ` Bart Schaefer
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 1996-07-23 20:18 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: pws, zsh-workers

On Jul 23,  7:35pm, Zoltan Hidvegi wrote:
} Subject: Re: False alarm (nonomatch and cshnullglob)
}
} > Someone previously suggested that options should be heirarchical, or
} > somehow otherwise related, so that (e.g.) "setopt nonomatch" would
} > automatically imply "unsetopt nullglob cshnullglob".
} 
} Perhaps that would be nice but I'm not sure it worth the extra code it adds.

Appended is an implementation using zsh functions to wrap the builtin
setopt/unsetopt commands.

} It would not be difficult to add the setopt option=value syntax.  Options
} are stored in a char array so this can be done without changing the array.
} But I still do not see how can such a feature be used.

The idea would be that you'd combine options like globdots, shglob,
ignorebraces, extendedglob, noglob, etc. into a single option (e.g.)
globstyle, and then you'd

    setopt globstyle=(globdots shglob ignorebraces)

You could also have options with multiple mutually-exclusive values,
e.g.

    setopt nomatchstyle=(csh)	# Possible values are csh, null, none

Since you now can't (e.g.) set one glob action without also setting the
rest of globstyle, you *know* that you aren't trying to use extendedglob
when noglob is set, and so forth.

----- 8< ----- snip ----- 8< ----- snip -----
#! /usr/local/bin/zsh
# Wrapper for setopt/unsetopt
# Put this in a file named "setopt" directory in your FPATH,
# link the name "unsetopt" to that file as well, and autoload
# both setopt and unsetopt.  Do this before setting any options.

local kshop ksharray localop monitor zle name value

[[ -o ksharrays ]] && ksharray=on || ksharray=off
[[ -o kshoptionprint ]] && kshop=on || kshop=off
[[ -o localoptions ]] && localop=on || localop=off
[[ -o monitor ]] && monitor=on || monitor=off
[[ -o zle ]] && zle=on || zle=off

builtin setopt localoptions kshoptionprint
builtin unsetopt ksharrays

options=()
typeset -xU options

builtin setopt | while read name value
do
    case $name in
    Current)		continue;;
    ksharrays)		value=$ksharray;;
    kshoptionprint)	value=$kshop;;
    localoptions)	value=$localop;;
    monitor)		value=$monitor;;
    zle)		value=$zle;;
    esac

    options=($options $name)

    # This array stores the default settings, just in case ...
    # I haven't come up with a use for this yet, except maybe
    # to get at the parent's value of "monitor" and "zle" even
    # in subshells.
    settings[$options[(i)$name]]=$value
done

# There is no case where an option A should always be on when
# another option B is off.  However:
#
# on_opts	option A should be on when B is on
# off_opts	option A should be off when B is on
# co_opts	option A should be off when B is off

off_opts[$options[(i)automenu]]=menucomplete
co_opts[$options[(i)correct]]=correctall
on_opts[$options[(i)correctall]]=correct
off_opts[$options[(i)cshjunkiehistory]]=nobanghist
off_opts[$options[(i)cshnullglob]]="nonomatch nullglob"
off_opts[$options[(i)extendedglob]]=noglob
off_otps[$options[(i)globassign]]=noglob
off_opts[$options[(i)globcomplete]]=noglob
off_opts[$options[(i)globdots]]=noglob
off_opts[$options[(i)globsubst]]=noglob
co_opts[$options[(i)hashcmds]]="hashdirs hashlistall"
on_opts[$options[(i)hashdirs]]=hashcmds
on_opts[$options[(i)hashlistall]]=hashcmds
#off_opts[$options[(i)ignorebraces]]=rcexpandparam
off_opts[$options[(i)menucomplete]]=automenu
co_opts[$options[(i)monitor]]=notify
#off_opts[$options[(i)nobanghist]]=cshjunkiehistory
#off_opts[$options[(i)noglob]]="extendedglob globassign globcomplete globdots globsubst numericglobsort shglob"
off_opts[$options[(i)nonomatch]]="cshnullglob nullglob"
on_opts[$options[(i)notify]]=monitor
off_opts[$options[(i)nullglob]]="cshnullglob nonomatch"
off_opts[$options[(i)numericglobsort]]=noglob
off_opts[$options[(i)rcexpandparam]]=ignorebraces
#off_opts[$options[(i)shglob]]=noglob
on_opts[$options[(i)singlelinezle]]=zle
co_opts[$options[(i)zle]]=singlelinezle

function dosetopt() {
    builtin unsetopt localoptions
    [[ -n "${off_opts[${options[(i)$1]}]}" ]] &&
	eval unsetopt ${off_opts[${options[(i)$1]}]}
    [[ -n "${on_opts[${options[(i)$1]}]}" ]] &&
	eval setopt ${on_opts[${options[(i)$1]}]}
    builtin setopt $1
}
function dounsetopt() {
    builtin unsetopt localoptions
    [[ -n "${co_opts[${options[(i)$1]}]}" ]] &&
	eval builtin unsetopt ${co_opts[${options[(i)$1]}]}
    builtin unsetopt $1
}

function setopt() {
    builtin unsetopt localoptions
    [[ $# -eq 0 ]] && { builtin setopt ; return $? }
    for i; do dosetopt $i; done
}
function unsetopt() {
    builtin unsetopt localoptions
    [[ $# -eq 0 ]] && return
    for i; do dounsetopt $i; done
}
----- 8< ----- snip ----- 8< ----- snip -----

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-23 20:18       ` Bart Schaefer
@ 1996-07-23 21:58         ` Bart Schaefer
  1996-07-24  8:31           ` Zefram
  1996-07-25 20:10           ` Zoltan Hidvegi
  0 siblings, 2 replies; 9+ messages in thread
From: Bart Schaefer @ 1996-07-23 21:58 UTC (permalink / raw)
  To: zsh-workers

On Jul 23,  1:18pm, Bart Schaefer wrote:
} Subject: Re: False alarm (nonomatch and cshnullglob)
}
} } > Someone previously suggested that options should be heirarchical, or
} } > somehow otherwise related, so that (e.g.) "setopt nonomatch" would
} } > automatically imply "unsetopt nullglob cshnullglob".
} } 
} } Perhaps that would be nice but I'm not sure it worth the extra code it adds.
} 
} Appended is an implementation using zsh functions to wrap the builtin
} setopt/unsetopt commands.

I should have mentioned that this implementation is not suitable for use
in combination with "setopt localoptions" in shell functions.  If you
use this wrapper, then your shell functions that desire localoptions need
to always use "builtin setopt".

Having the behavior itself built in to zsh would eliminate that problem.


-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-23 21:58         ` Bart Schaefer
@ 1996-07-24  8:31           ` Zefram
  1996-07-25 20:10           ` Zoltan Hidvegi
  1 sibling, 0 replies; 9+ messages in thread
From: Zefram @ 1996-07-24  8:31 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

>I should have mentioned that this implementation is not suitable for use
>in combination with "setopt localoptions" in shell functions.  If you
>use this wrapper, then your shell functions that desire localoptions need
>to always use "builtin setopt".
>
>Having the behavior itself built in to zsh would eliminate that problem.

...but would introduce the problem that an innocent setopt can change
more options than it appears to, confusing lots of existing functions.
If we introduce group option setting, it must be using new option
names, to avoid changing the meaning of existing options.



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-23 21:58         ` Bart Schaefer
  1996-07-24  8:31           ` Zefram
@ 1996-07-25 20:10           ` Zoltan Hidvegi
  1996-07-25 20:46             ` Bart Schaefer
  1 sibling, 1 reply; 9+ messages in thread
From: Zoltan Hidvegi @ 1996-07-25 20:10 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

> I should have mentioned that this implementation is not suitable for use
> in combination with "setopt localoptions" in shell functions.  If you
> use this wrapper, then your shell functions that desire localoptions need
> to always use "builtin setopt".
> 
> Having the behavior itself built in to zsh would eliminate that problem.

Note that a function can always change options of the caller by unsetting
localoptions before return.  Localoptions is always local.  See
man zshoptions for details.

Zoltan



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-25 20:10           ` Zoltan Hidvegi
@ 1996-07-25 20:46             ` Bart Schaefer
  1996-07-25 20:53               ` Zoltan Hidvegi
  0 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 1996-07-25 20:46 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zsh-workers

On Jul 25, 10:10pm, Zoltan Hidvegi wrote:
} Subject: Re: False alarm (nonomatch and cshnullglob)
}
} > I should have mentioned that this implementation is not suitable for use
} > in combination with "setopt localoptions" in shell functions.  If you
} > use this wrapper, then your shell functions that desire localoptions need
} > to always use "builtin setopt".
} > 
} > Having the behavior itself built in to zsh would eliminate that problem.
} 
} Note that a function can always change options of the caller by unsetting
} localoptions before return.

Yes, which means that any function that's going to be a wrapper around
"setopt" has to unsetopt localoptions, which is what my functions do.
Thus even if you try to setopt localoptions, the setopt wrapper will
still change the options of the caller.

If you can think of a workaround for this, I'd be thrilled to hear it.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

* Re: False alarm (nonomatch and cshnullglob)
  1996-07-25 20:46             ` Bart Schaefer
@ 1996-07-25 20:53               ` Zoltan Hidvegi
  0 siblings, 0 replies; 9+ messages in thread
From: Zoltan Hidvegi @ 1996-07-25 20:53 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

> Yes, which means that any function that's going to be a wrapper around
> "setopt" has to unsetopt localoptions, which is what my functions do.
> Thus even if you try to setopt localoptions, the setopt wrapper will
> still change the options of the caller.
> 
> If you can think of a workaround for this, I'd be thrilled to hear it.

Oops, sorry, I did not read carefully enough.  I now see your point but
unfortunately I know no workaround for that.

Zoltan



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

end of thread, other threads:[~1996-07-25 20:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <960722151122.ZM10323@candle.brasslantern.com>
1996-07-23  7:31 ` False alarm (nonomatch and cshnullglob) Peter Stephenson
1996-07-23  8:34   ` Bart Schaefer
1996-07-23 17:35     ` Zoltan Hidvegi
1996-07-23 20:18       ` Bart Schaefer
1996-07-23 21:58         ` Bart Schaefer
1996-07-24  8:31           ` Zefram
1996-07-25 20:10           ` Zoltan Hidvegi
1996-07-25 20:46             ` Bart Schaefer
1996-07-25 20:53               ` Zoltan Hidvegi

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