From: Bart Schaefer <schaefer@brasslantern.com>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: A way to untie -T vars?
Date: Wed, 25 Jan 2023 18:34:15 -0800 [thread overview]
Message-ID: <CAH+w=7bLpgoo3FAmefDM8z9qOgCEY8hCjKE6a=bOwhDP4gByRw@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7Y1CP1tN29LHFC6QxcdDngZVLKEPdr6c3+h8UAXBy2q-Q@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 767 bytes --]
On Wed, Jan 25, 2023 at 3:48 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> The value being assigned to the variable is coming from $1=${(P)1} and
> ${(P)1} includes the specified justification, so the value assigned is
> always already the correct width.
Which means ${(P)#1} is the justification, no need to fork typeset for
that, and ...
> Is there any other way to reference
> the "real, unfilled" value of a parameter that has justification
> specified?
The only reliable way I can find is to first remove the justification:
% typeset -L5 FOO=123456789
% printf "<%s>\n" $FOO
<12345>
% typeset +L FOO
% printf "<%s>\n" $FOO
<123456789>
This can be done without otherwise changing the type or tied-ness of the scalar.
One more pass at it attached.
[-- Attachment #2: untie.txt --]
[-- Type: text/plain, Size: 1315 bytes --]
untie () {
emulate -L zsh -o extendedglob -o errreturn
while ((ARGC))
do
() {
case -${(tP)1}- in
(*-(readonly|special)-*) print -u2 -r "Can't untie ${(qqq)1}: ${(tP)1}"
return 0 ;;
(*-tied-*) set -- ${(s:-:tP)1} - $1 -g ;;
(*) : "${1}: not a tied parameter"
return 0 ;;
esac
while [[ $1 != - ]]
do
case $1 in
(export) set -- "$@" -x ;;
(tag) set -- "$@" -t ;;
(unique) set -- "$@" -U ;;
(upper) set -- "$@" -u ;;
(lower) set -- "$@" -l ;;
(hide) set -- "$@" -h ;;
(hideval) set -- "$@" -H ;;
(left) set -- "$@" -L${(P)#${@[$@[(i)-]+1]}} ;;
(right_blanks) set -- "$@" -R${(P)#${@[$@[(i)-]+1]}} ;;
(right_zeros) set -- "$@" -Z${(P)#${@[$@[(i)-]+1]}} ;;
esac
shift
done
shift
case -${(tP)1}- in
(*-array-*) set -- $# "$@" $1 "${(@P)1}"
unset $2
typeset -a ${argv[3,$1+1]} $2
shift $1+1
set -A "$@" ;;
(*-scalar-*) typeset -g +L +R +Z $1
set -- "$@" $1=${(P)1}
unset $1
shift
typeset "$@" ;;
(*) print -u2 -r -- "${1}: impossible: ${(tP)1}"
return 1 ;;
esac
} $1
shift
done
}
next prev parent reply other threads:[~2023-01-26 2:35 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-21 16:37 Sebastian Gniazdowski
2023-01-21 16:55 ` Bart Schaefer
2023-01-21 17:11 ` Bart Schaefer
2023-01-21 18:52 ` Bart Schaefer
2023-01-21 19:15 ` Roman Perepelitsa
2023-01-22 9:34 ` Pier Paolo Grassi
2023-01-22 9:58 ` Roman Perepelitsa
2023-01-23 2:14 ` Bart Schaefer
2023-01-23 9:47 ` Roman Perepelitsa
2023-01-23 18:27 ` Bart Schaefer
2023-01-23 18:42 ` Mikael Magnusson
2023-01-23 18:43 ` Mikael Magnusson
2023-01-23 19:12 ` Bart Schaefer
2023-01-24 5:45 ` Bart Schaefer
2023-01-24 9:56 ` Roman Perepelitsa
2023-01-24 16:42 ` Bart Schaefer
2023-01-24 16:45 ` Peter Stephenson
2023-01-24 17:40 ` Bart Schaefer
2023-01-24 17:54 ` Roman Perepelitsa
2023-01-24 22:54 ` Bart Schaefer
2023-01-25 14:41 ` Roman Perepelitsa
2023-01-25 22:39 ` Bart Schaefer
2023-01-25 23:48 ` Bart Schaefer
2023-01-26 2:34 ` Bart Schaefer [this message]
2023-01-21 17:15 ` Roman Perepelitsa
2023-01-21 17:23 ` Bart Schaefer
2023-01-21 17:31 ` Bart Schaefer
2023-01-21 17:48 ` Roman Perepelitsa
2023-01-21 17:50 ` Bart Schaefer
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='CAH+w=7bLpgoo3FAmefDM8z9qOgCEY8hCjKE6a=bOwhDP4gByRw@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=roman.perepelitsa@gmail.com \
--cc=zsh-users@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).