zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Add a much simpler alternative to using url-quote-magic + bracketed-paste-magic
Date: Tue, 29 Sep 2015 06:43:53 +0200	[thread overview]
Message-ID: <1443501833-29817-1-git-send-email-mikachu@gmail.com> (raw)
In-Reply-To: <1443501793-29753-1-git-send-email-mikachu@gmail.com>

Now that we have more control over the yank highlighting, we can handle pasted
urls directly, instead of mucking around with pretending we don't know which
text was pasted together, then trying to reverse engineer this fact from it looking
like a url. This function simply looks at the first few characters and if they
match the configured schemas, then the paste is quoted.

It handles NUMERIC to quote, but not any weird vi or newline stripping stuff.

---
 Functions/Zle/bracketed-paste-url-magic | 38 +++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Functions/Zle/bracketed-paste-url-magic

diff --git a/Functions/Zle/bracketed-paste-url-magic b/Functions/Zle/bracketed-paste-url-magic
new file mode 100644
index 0000000..e05e982
--- /dev/null
+++ b/Functions/Zle/bracketed-paste-url-magic
@@ -0,0 +1,38 @@
+# bracketed-paste-url-magic quotes pasted urls automatically, if the
+# paste exactly starts with a url, eg no spaces or other characters precede it
+#
+# To use it, put this in your startup files (eg, .zshrc)
+#
+# autoload -Uz bracketed-paste-url-magic
+# zle -N bracketed-paste bracketed-paste-url-magic
+#
+# You can customize which schemas are to be quoted by using
+#
+# zstyle :bracketed-paste-url-magic schema http https ftp
+#
+# The default can be seen just below.
+
+local -a schema
+zstyle -a :bracketed-paste-url-magic schema schema || schema=(http https ftp ftps file ssh sftp)
+
+local wantquote=${NUMERIC:-0}
+local content
+local start=$#LBUFFER
+
+zle .$WIDGET -N content
+
+if ! (( $wantquote )); then
+  if [[ $content = (${(~j:|:)schema})://* ]]; then
+    wantquote=1
+  fi
+fi
+
+if (( $wantquote )); then
+  content=${(q-)content}
+fi
+
+LBUFFER+=$content
+
+YANK_START=$start
+YANK_END=$#LBUFFER
+YANK_ACTIVE=1
-- 
2.5.0


  reply	other threads:[~2015-09-29  4:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29  4:43 PATCH: Make yank zle params writable Mikael Magnusson
2015-09-29  4:43 ` Mikael Magnusson [this message]
2015-09-29 18:09 ` Mikael Magnusson
2015-09-30  1:15 ` Mikael Magnusson
2015-09-30  2:06   ` PATCH: zle -f from inside widget to set flags and make yank start/end " Mikael Magnusson
2015-10-01 15:33     ` Jun T.
2015-10-01 19:43       ` Mikael Magnusson
2015-10-02  8:09         ` Jun T.
2015-10-02 18:43           ` Mikael Magnusson
2015-10-02 19:58             ` 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=1443501833-29817-1-git-send-email-mikachu@gmail.com \
    --to=mikachu@gmail.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).