zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@sunsite.dk
Subject: Re: zsh widget to resolve symlinks
Date: Sun, 10 Dec 2006 17:56:13 +0000	[thread overview]
Message-ID: <200612101756.kBAHuDLN003968@pwslaptop.csr.com> (raw)
In-Reply-To: Message from Mikel Ward <mikel@mikelward.com>  of "Sun, 10 Dec 2006 11:33:23 +1100." <457B55D3.9030003@mikelward.com>

Mikel Ward wrote:
> It turns out copy-region-as-kill doesn't use killring but rather
> CUTBUFFER.  This is a little confusing!

Right, CUTBUFFER is the most recently killed, killring holds the entries
before that.  This is something of a historical curiosity.  The manual
needs to be more explicit about the link between the two.

> I'm also surprised that CUTBUFFER persists invocations of zle, yet it
> isn't set in the top-level interactive shell.

This reflects how zle works.  If you use "yank" when editing, it will
insert the last string cut or copied even if it wasn't in the current
command line, and even though zle wasn't active in the intervening period.

In recent zsh, you can hook in code to be run at the start of the line
by defining zle-line-init as a widget; however, you probably don't want
to reset CUTBUFFER because of its unexpected effect on yanking.

You can avoid using CUTBUFFER at all with something like (note I haven't
actually tried this but it shouldn't be too far out):

zle backward-word
integer pos1=$((CURSOR+1))
zle forward-word
# this will grab any whitespace at the end, too...
integer pos2=$((CURSOR))
local word="$BUFFER[$pos1,$pos2]"

and to replace the word, leaving the cursor after it,

LBUFFER="${LBUFFER[1,$pos-1]}$realpath"

If I were writing the widget, I'd probably use raw access to $BUFFER
etc. to find the start and end of the word (hence avoiding the use of
$CURSOR apart from finding out where to start), and ${(z)...} trickery
to access shell words as done in match-words-by-style (which might give
you some other ideas).

It occurred to me recently that a generic widget to split the line into
shell words and whitespace would be extremely useful, making this sort
of task much easier.  However, I haven't got around to it yet.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2006-12-10 17:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-09 23:18 error using custom widget: widgets can only be called when ZLE is active Mikel Ward
2006-12-10  0:10 ` error using custom widget: widgets can only be called when ZLE is active [solved] Mikel Ward
2006-12-10  0:33   ` zsh widget to resolve symlinks Mikel Ward
2006-12-10 17:56     ` Peter Stephenson [this message]
2006-12-14 11:22       ` PATCH: argument splitting (was Re: zsh widget to resolve symlinks) Peter Stephenson

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=200612101756.kBAHuDLN003968@pwslaptop.csr.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@sunsite.dk \
    /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).