zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Pier Paolo Grassi <pierpaolog@gmail.com>, Zsh Users <zsh-users@zsh.org>
Subject: Re: A way to untie -T vars?
Date: Mon, 23 Jan 2023 21:45:26 -0800	[thread overview]
Message-ID: <CAH+w=7YSr1RjDi3zXAhBg6unDj0gcjG+DKM5BjKVgoVhoP+Rog@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7bzka=NBZ1SGRt7Fj65KuC3mmH99E8uyCn=Ff=uFaM58w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

On Mon, Jan 23, 2023 at 10:27 AM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> array local left justified 10 zero filled 10 uppercase tagged unique
> tied FOO foo
>
> (plus export, hide, and hideval, which typeset +m does not display)

Minor correction:  typeset +m does output "exported" for scalars, but
not for arrays even when tied to an exported scalar.

> Pondering.

I've reached the conclusion that "local" makes no difference here.  If
any calling scope has declared the parameter local, it will remain
local to that scope even if unset, and the dynamic scope behavior of
"typeset -g" from inside "untie" will apply to the variable in that
scope.

Also, per the other thread, there's no way to get the justification
width for -L/-R/-Z without using typeset +m so that's what I've done.
Since -L and -Z may be specified together, I've made two calls to
typeset +m, the gyrations to reduce it to a single call seemed even
more confusing than the hoops necessary to shuffle all the switches
through the positional parameters.

Attached this time because I'm sure gmail would maim it.  This has
been tested with convoluted cases, but not with simple ones, so it may
still need refinement.

[-- Attachment #2: untie.txt --]
[-- Type: text/plain, Size: 1342 bytes --]

untie () {
  emulate -L zsh -o extendedglob -o errreturn
  while ((ARGC))
  do
    () {
      case ${(tP)1} in
        (*right_zeros*) set -- $1 -Z${${(M@)$(typeset +m $1):#[[:digit:]]#}[1]} ;;
      esac
      case ${(tP)1} in
        (*left*) set -- "$@" -L${${(M@)$(typeset +m $1):#[[:digit:]]#}[1]} ;;
        (*right_blanks*) set -- "$@" -R${${(M@)$(typeset +m $1):#[[:digit:]]#}[1]} ;;
      esac
      if [[ ${(tP)1} = *export* ]]
      then
        set -- $1 -x ${argv[2,$#]}
      else
        set -- $1 -g ${argv[2,$#]}
      fi
      set ${(s:-:tP)1} - $1 ${argv[2,$#]}
      while [[ $1 != - ]]
      do
        case $1 in
          (tag) set -- "$@" -t ;;
          (unique) set -- "$@" -U ;;
          (upper) set -- "$@" -u ;;
          (lower) set -- "$@" -l ;;
          (hide) set -- "$@" -h ;;
          (hideval) set -- "$@" -H ;;
        esac
        shift
      done
      shift
      case ${(tP)1} in
        (array*tied*) set -- $1 $# "$@" $1 "${(@P)1}"
          unset $1
          typeset -a ${argv[4,$2+2]} $1
          shift $2+2
          set -A "$@" ;;
        (scalar*tied*) set -- "$@" $1=${(P)1}
          unset $1
          shift
          typeset "$@" ;;
        (*tied*) print -u2 -r "Can't untie ${(qqq)1}: ${(tP)1}" ;;
        (*) : "${1}: not a tied parameter" ;;
      esac
    } $1
    shift
  done
}

  parent reply	other threads:[~2023-01-24  5:46 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 [this message]
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
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=7YSr1RjDi3zXAhBg6unDj0gcjG+DKM5BjKVgoVhoP+Rog@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=pierpaolog@gmail.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).