From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers' list <zsh-workers@zsh.org>
Subject: PATCH: variable warnings issues
Date: Thu, 21 Jun 2018 14:43:32 +0100 [thread overview]
Message-ID: <20180621134335eucas1p2b831176d9b8e7fd6075eff86424d697f~6ML3VlYgA2597225972eucas1p23@eucas1p2.samsung.com> (raw)
In-Reply-To: <CGME20180621134335eucas1p2b831176d9b8e7fd6075eff86424d697f@eucas1p2.samsung.com>
I've been using WARN_CREATE_GLOBAL and WARN_NESTED_VAR extensively
and this adds a couple of improvements.
The principle change is to add the -g option to vared; it's similar
to the effect with typeset in this respect. You'd use it if your
vared is there to allow the user to edit a variable of their choosing
(e.g. I have a front-end varednl that runs vared with IFS set to $'\n').
You wouldn't use it if you're running vared in a function to edit
something you believe to be limited to that function.
While I'm at it, suppress WARN_NESTED_VAR warnings in
zsh_directory_name_cdr --- note you need to be able to inline array
asignments with typeset or this isn't possible. I don't think
there's a reason for backward compatibility here since this function
suite is always installed per zsh version and has been since it
appeared, but checking
[[ -n $reswords[(R)typeset] ]]
would be possible.
One day we might get around to extending the warnings to associative
arrays.
pws
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index bd0252f..b72606c 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -342,7 +342,7 @@ findex(vared)
cindex(parameters, editing)
cindex(editing parameters)
redef(SPACES)(0)(tt(ifztexi(NOTRANS(@ @ @ @ @ @ ))ifnztexi( )))
-xitem(tt(vared )[ tt(-Aache) ] [ tt(-p) var(prompt) ] [ tt(-r) var(rprompt) ])
+xitem(tt(vared )[ tt(-Aacghe) ] [ tt(-p) var(prompt) ] [ tt(-r) var(rprompt) ])
xitem(SPACES()[ tt(-M) var(main-keymap) ] [ tt(-m) var(vicmd-keymap) ])
xitem(SPACES()[ tt(-i) var(init-widget) ] [ tt(-f) var(finish-widget) ])
item(SPACES()[ tt(-t) var(tty) ] var(name))(
@@ -353,7 +353,9 @@ When the tt(-c) flag is given, the parameter is created if it doesn't
already exist. The tt(-a) flag may be given with tt(-c) to create
an array parameter, or the tt(-A) flag to create an associative array.
If the type of an existing parameter does not match the type to be
-created, the parameter is unset and recreated.
+created, the parameter is unset and recreated. The tt(-g) flag may
+be given to suppress warnings from the tt(WARN_CREATE_GLOBAL)
+and tt(WARN_NESTED_VAR) options.
If an array or array slice is being edited, separator characters as defined
in tt($IFS) will be shown quoted with a backslash, as will backslashes
diff --git a/Functions/Chpwd/zsh_directory_name_cdr b/Functions/Chpwd/zsh_directory_name_cdr
index c9be7db..cb72e46 100644
--- a/Functions/Chpwd/zsh_directory_name_cdr
+++ b/Functions/Chpwd/zsh_directory_name_cdr
@@ -1,14 +1,13 @@
if [[ $1 = n ]]; then
if [[ $2 = <-> ]]; then
# Recent directory
- typeset -ga reply
autoload -Uz cdr
cdr -r
if [[ -n ${reply[$2]} ]]; then
- reply=(${reply[$2]})
+ typeset -ga reply=(${reply[$2]})
return 0
else
- reply=()
+ typeset -ga reply=()
return 1
fi
fi
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index b78c47e..99e44a7 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1652,6 +1652,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
Param pm = 0;
int ifl;
int type = PM_SCALAR, obreaks = breaks, haso = 0, oSHTTY = 0;
+ int warn_flags;
char *p1, *p2, *main_keymapname, *vicmd_keymapname, *init, *finish;
Keymap main_keymapsave = NULL, vicmd_keymapsave = NULL;
FILE *oshout = NULL;
@@ -1665,6 +1666,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
return 1;
}
+ warn_flags = OPT_ISSET(ops, 'g') ? 0 : ASSPM_WARN;
if (OPT_ISSET(ops,'A'))
{
if (OPT_ISSET(ops, 'a'))
@@ -1845,11 +1847,11 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
a = spacesplit(t, 1, 0, 1);
zsfree(t);
if (PM_TYPE(pm->node.flags) == PM_ARRAY)
- setaparam(args[0], a);
+ assignaparam(args[0], a, warn_flags);
else
sethparam(args[0], a);
} else
- setsparam(args[0], t);
+ assignsparam(args[0], t, warn_flags);
unqueue_signals();
return 0;
}
@@ -2148,7 +2150,7 @@ zle_main_entry(int cmd, va_list ap)
static struct builtin bintab[] = {
BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL),
- BUILTIN("vared", 0, bin_vared, 1, 1, 0, "aAcef:hi:M:m:p:r:t:", NULL),
+ BUILTIN("vared", 0, bin_vared, 1, 1, 0, "aAcef:ghi:M:m:p:r:t:", NULL),
BUILTIN("zle", 0, bin_zle, 0, -1, 0, "aAcCDfFgGIKlLmMNrRTUw", NULL),
};
parent reply other threads:[~2018-06-21 13:43 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <CGME20180621134335eucas1p2b831176d9b8e7fd6075eff86424d697f@eucas1p2.samsung.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='20180621134335eucas1p2b831176d9b8e7fd6075eff86424d697f~6ML3VlYgA2597225972eucas1p23@eucas1p2.samsung.com' \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).