Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_PCNT
	autolearn=no autolearn_force=no version=3.4.1
Date: Fri, 13 May 2016 11:23:48 +0200
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: bracket-paste-magic adds backslashes inside a quoted string if
 URL is pasted ("regression" compared to pre-5.1 url-quote-magic)
Message-ID: <20160513092348.GB18186@zira.vinc17.org>
Mail-Followup-To: zsh-workers@zsh.org
References: <20160506205309.GY5029@sym.noone.org>
 <160508115026.ZM10022@torch.brasslantern.com>
 <20160509141306.GA18211@cventin.lip.ens-lyon.fr>
 <160509084143.ZM13554@torch.brasslantern.com>
 <20160510085833.GA20332@cventin.lip.ens-lyon.fr>
 <160510125848.ZM1686@torch.brasslantern.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <160510125848.ZM1686@torch.brasslantern.com>
X-Mailer-Info: https://www.vinc17.net/mutt/
User-Agent: Mutt/1.6.1-6650-vl-r88942 (2016-05-12)
X-Seq: zsh-workers 38484

On 2016-05-10 12:58:48 -0700, Bart Schaefer wrote:
> On May 10, 10:58am, Vincent Lefevre wrote:
> }
> } > We had quite a bit of discussion on related topics when bracketed-paste
> } > was added.  The general idea is that a paste is treated as a unit, and
> } > the default behavior of bracketed-paste-magic is to restrict its action
> } > to remain "inside" that unit.
> } 
> } I'm not sure what you call "unit"
> 
> A single keystroke.  A single widget event.  As if the entire paste, no
> matter how large, is one indivisible object.

But the main point is that there is a context. For instance,
a context can be:

  echo http://localhost/foo

or

  echo 'http://localhost/foo

If I type "?", I expect "\?" to be entered in the first context,
and "?" in the second case. Ditto if "?" is pasted. In both cases,
the action remains inside the unit. So, I don't understand why
bracketed-paste-magic doesn't behave that way by default.

> bracketed-paste-url-magic takes a different approach, examining the
> paste to see if it starts with a URI scheme and if so quoting the
> whole thing, and otherwise not interfering with the default paste
> behavior at all (so you get even less context sensitivity).

bracketed-paste-url-magic is something new to me. I currently have:

  autoload -Uz url-quote-magic
  zle -N self-insert url-quote-magic
  autoload -Uz bracketed-paste-magic
  zle -N bracketed-paste bracketed-paste-magic
  zstyle :bracketed-paste-magic paste-init backward-extend-paste

the only reason of the zstyle line being to get the above expected
behavior when pasting "?". Do you mean that instead of the zstyle
line, bracketed-paste-url-magic would do the work? Does this replace
bracketed-paste-magic or should bracketed-paste-url-magic be used
in addition to bracketed-paste-magic?

bracketed-paste-url-magic is not described in the zsh man pages.

> A third (so far unimplemented) approach would be to examine LBUFFER
> for an unbalanced quote mark and treat the paste accordingly, but
> what exactly does "accordingly" mean?  Escape any quotes of the same
> type that are in the paste, or assume the user is intentionally
> pasting the closing quote?

I would say: the same behavior as url-quote-magic.

URL's normally don't have quotes. For instance, when searching for

  "foo"

or

  'foo'

(with quotes) on Google, Firefox displays the URL's with quotes,
but when I copy-paste these URL's to Emacs, I get:

  https://www.google.fr/#q=%22foo%22
  https://www.google.fr/#q=%27foo%27

and I assume that's Firefox that escapes the quote characters (there
may be a RFC requirement concerning allowed characters in URL's, but
I haven't checked). Note that such escaping is not just useful for
shells, but also for pasting URL's to an XML document in an editor,
since XML attributes also use " and ' quote characters as delimiters.

So, I think that a quote should have its usual shell meaning like
with url-quote-magic (though this could also be configurable).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

