zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Anybody know what's going on here in _expand?  Patch?
Date: Thu, 26 Dec 2013 17:08:27 -0800	[thread overview]
Message-ID: <131226170827.ZM31040@torch.brasslantern.com> (raw)

Line numbers for reference:

103 # Now try globbing.
104 
105 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob &&
106     eval 'exp=( ${~exp//(#b)\\[         
107 ]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null

There is a trailing space and tab on line 106.

That stuff starting with //(#b) appears to want to replace any
whitespace that is preceded by a backslash with *something*, but as
there are no parens for the $match array to refer to, it ends up simply
removing the whitespace (along with the backslash), at least as far as I
can tell.  That can't be correct ...?

A bit further up is this:

 89   eval 'exp=( ${${(e)exp//\\[   
 90 ]/ }//(#b)([    
 91 ])/\\$match[1]} )' 2>/dev/null

That looks pretty similar (trailing space+tab on both lines 89 and 90)
except there it's turning backslash-whitespace into just a space, and
then adding back the backslash to any space that appears after applying
the (e) flag.

As it turns out, that eval on line 106 is where Yuri D'Elia's examples
[from the "Expanding quotes" thread over on zsh-users] go wrong. Adding
quote marks as well as whitespace to the character class on 106 "fixes"
both examples.

If nobody can explain what's correct about lines 106 and 107 as is,
then I propose the following patch, which adds the seemingly missing
backreference parens as well as putting quote chars in the class.


diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand
index 44954a2..e52144c 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -103,8 +103,8 @@ subd=("$exp[@]")
 # Now try globbing.
 
 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob &&
-    eval 'exp=( ${~exp//(#b)\\[ 	
-]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null
+    eval 'exp=( ${~exp//(#b)\\([ 	\"'"\'"'
+])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null
 
 ### Don't remember why we once used this instead of the (q) above.
 #    eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )' 2>/dev/null


             reply	other threads:[~2013-12-27  1:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-27  1:08 Bart Schaefer [this message]
2013-12-27 15:08 ` Jun T.

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=131226170827.ZM31040@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).