zsh-users
 help / color / mirror / code / Atom feed
* replacing current word in user-defined widget?
@ 2001-06-06 17:41 Adam Spiers
  2001-06-06 19:53 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Adam Spiers @ 2001-06-06 17:41 UTC (permalink / raw)
  To: zsh users mailing list

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,
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 :-)
Completion widgets seem to have it a lot easier, since they're given
the $words array to mess around with.

Any suggestions?


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: replacing current word in user-defined widget?
  2001-06-06 17:41 replacing current word in user-defined widget? Adam Spiers
@ 2001-06-06 19:53 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2001-06-06 19:53 UTC (permalink / raw)
  To: Adam Spiers, zsh users mailing list

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   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-06-06 19:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-06 17:41 replacing current word in user-defined widget? Adam Spiers
2001-06-06 19:53 ` Bart Schaefer

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).