zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Dynamic directory name function
Date: Thu, 24 Sep 2015 09:37:52 +0100	[thread overview]
Message-ID: <20150924093752.581dcee9@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <150923231024.ZM32382@torch.brasslantern.com>

On Wed, 23 Sep 2015 23:10:24 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Sep 23,  9:48am, Peter Stephenson wrote:
> }
> } I did think about that.  But having written the wrapper function, with
> } the variables the way they are, everything immediately fell out neatly
> } and clearly with associative arrays having a natural meaning.
> 
> As long as they're all local to the wrapper or use a naming convention
> to avoid clashing with any other variables, I suppose that's fine.
> Naming convention is mostly what zstyle is for.

That's probably what I'll go with, unless someone who is actually going
to use this really feels the need for styles.  But thanks for the
comments.

> However, as far as I understand zsh_directory_name_generic from looking
> at the code and comments, you always start with the zdn_top hash, and
> its values can contain substrings of the form ":identifier" where that
> identifier then refers to another hash, and so on.

Yes, although I've just modified it so you can start with a style to
find the top variable.  Given the variables can be linked how you like
(nothing needs to be defined locally), the difference between the two
isn't that great.

> So if I've got ~[x:y], I have to find key "x" in zdn_top, and either
> that has to have a ":identifier" in its value, or there has to be a
> ":default:" key with another ":identifier", and in either case the
> hash referenced by that identifier has to have key "y", and so on.
> 
> Right so far?

Yes.

> Then as usual with zstyle you have to decide on what is context and
> what is style.  I guess to follow your model closely, we should make
> the identifier be the style, and the context is the the name of the
> wrapper function.
> 
> So you'd define the styles like this:
> 
>     zstyle ZDN_wrapper_name zdn_top \
> 	g   ~/git \
> 	ga  ~/alternate/git \
> 	gs  /scratch/$USER/git/:second2 \
> 	:default: /:second1
> 
>     zstyle ZDN_wrapper_name second1 \
>     	p  myproject \
> 	s  somproject \
> 	os otherproject/subproject/:third
> 
>     zstyle ZDN_wrapper_name third \
> 	s  top/srcdir \
> 	d  top/documentation
> 
> (rest omitted for brevity).
>...
> I don't see we've lost any readability/remember-ability at this level,

OK, that's pretty similar.  There's the repetition of ZDN_wrapper_name,
but that's more to do with protecting the namespace (you'd need it as
the prefix to an associative array if you wanted to be careful, unless
you do what I do and define it locally).  There's also the backslashes,
but more careful people than me probably don't mind those.

> but now those declarations can be global instead of local to each
> wrapper, so we can have multiple wrappers share them by doing
> 
>     zstyle 'ZDN_*' third ...

Yes, but you can do that just by having them reference the same
global associative arrays.  With a zstyle pointing to the top
associative array you can again define everything outside the wrapper.

> Maybe we should be doing
> 
>     zstyle ZDN_/scratch/$USER/git/ next-part \
> 	p myscratchproject \
> 	s somescratchproject

This is now at the level where if somebody put it in front of me I'd
find it too fiddly to use.

I think, really, it's six and two threes (or six of one and half a dozen
of the other, as the wordier people born south of Tyneside say).  zstyle
gives you a few extra tricks if you can probe the obscurity, although
obscurity is an entirely subjective concept.  Variables allow you to
define the whole thing inside a single function with no globals the way
I originally did, which doesn't really fit the zstyle model, and I would
think anyone who knows what an associative array is can pick it up the
entire system very quickly.

However, it was certainly useful to compare.

pws


      reply	other threads:[~2015-09-24  8:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-22 19:42 Peter Stephenson
2015-09-23  4:07 ` Bart Schaefer
2015-09-23  8:48   ` Peter Stephenson
2015-09-23  9:55     ` Peter Stephenson
2015-09-24  6:10     ` Bart Schaefer
2015-09-24  8:37       ` Peter Stephenson [this message]

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=20150924093752.581dcee9@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).