zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Adam Spiers <adam@spiers.net>,
	zsh users mailing list <zsh-users@sunsite.auc.dk>
Subject: Re: replacing current word in user-defined widget?
Date: Wed, 6 Jun 2001 19:53:48 +0000	[thread overview]
Message-ID: <1010606195348.ZM2482@candle.brasslantern.com> (raw)
In-Reply-To: <20010606184150.A23107@thelonious.new.ox.ac.uk>

On Jun 6,  6:41pm, Adam Spiers wrote:
}
} I was trying to write a make-path-absolute type of widget that
} replaces the pathname which is the current word with an absolute path,

That sounds like a job for a completion widget.  As you say:

} Completion widgets seem to have it a lot easier, since they're given
} the $words array to mess around with.

Something like:

	#compdef -k complete-word ^X^F
	compadd -U -S '' $PWD/$words[CURRENT]

Might be a good idea to test $compstate[quote] etc. but you get the idea.

However ...

} but I got stuck trying to write code which figures out where the
} current word starts and ends.  Presumably it involves looking at
} $BUFFER and $CURSOR, and maybe doing word splitting with ${(z)BUFFER}
} or similar, but beyond that I don't have much of a clue :-)

I messed with this while trying to write an improved transpose-words and
came to the conclusion that it's nearly impossible.  As you noticed, one
can split the command line into words with ${(z)BUFFER} but as that has
the side-effect of removing an unknown amount of whitespace between the
words, you can't map from CURSOR to an index into the resulting array.

You can try taking the last word from ${(z)LBUFFER} and the first word
from ${(z)RBUFFER) and gluing them together, but I'm not sure that'll
work right if the cursor is in the middle of a quoted string, so it's
best to let the completion code deal with it.

Unfortunately transpose-words doesn't have that option, because it has
to deal with two words, not one.  So I eventually gave up.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


      reply	other threads:[~2001-06-06 19:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-06 17:41 Adam Spiers
2001-06-06 19:53 ` Bart Schaefer [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=1010606195348.ZM2482@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=adam@spiers.net \
    --cc=zsh-users@sunsite.auc.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).