Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Extending zed
- X-seq: zsh-users 23434
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: Extending zed
- Date: Mon, 04 Jun 2018 18:08:31 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1528128519; bh=Jlp7xcQnCIl6+p32Y43+MWH53QDQL1T0i/Kqw0EoXNs=; h=From:References:To:Subject:Date:From:Subject; b=uIVrVjqn8libv2FQzwUphYJPVVKvuGFBBmpTC/NIJb2P0EBvZJOD3olKYtqbLg2ejNPw5uXNgt8s/0dj8AoLUcJ3T+W6nc9iD3AbK7CQyBzFueArylvhyhqe4Lv1k5qvAhUzVWeEnQ3XeRpg7CF8Aw00NnXjffvkBFkRggMlCAnryIU36X3i7wkCEOYT08gwoGOlR6uDQdgs5bjtNESgZFcbk2t7EjhgKyeVjVU16LcVN/fFTC+ure1x9MjjARj/U32KiUV4hF0S+dnGYIjIEORgfDvJBMIxYe9/btwCtj7dYJUdOftxY1IvGYJjWU1vncZByIckoKwQScSgl/pgvw==
- In-reply-to: <CAKc7PVB6JhtAQa+MUs0tm28211e4xJ4QRt-83=QYmuOczKwcOA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20180603055854epcas5p1e92f5a41384aeb9d1555751df74f57ee@epcas5p1.samsung.com> <CAKc7PVDas7ZvXA0CvR1opSH5Wz0d=FVj=NZHGSu2k3C_o=fGZQ@mail.gmail.com> <20180604083801eucas1p258b13dadf37a66e8a59e8714462d0577~06DN1ECXq0206402064eucas1p26@eucas1p2.samsung.com> <CAKc7PVCV3TCe4k-SyJOiD6aDA+uF5FRM_5Q45X9sLPOeCOunWA@mail.gmail.com> <20180604095044eucas1p2ae6dd78f9518e91e6171d15d3717f924~07CtDwS5C1968619686eucas1p2k@eucas1p2.samsung.com> <CAKc7PVB6JhtAQa+MUs0tm28211e4xJ4QRt-83=QYmuOczKwcOA@mail.gmail.com>
Sebastian Gniazdowski wrote:
> I've looked at the undo problem. Ctrl-/ (or Ctrl-_ that's the same
> control code as we know) works fine in insert mode, i.e. it does do
> undo. I've checked it's bound to widget "undo" (checking code at the
> end of post). Then I've checked the not-working "u" in zed-vicmd
> keymap. It is also bound to widget "undo". But it makes viewport
> blank, doesn't do smooth undo like Ctrl-/. What is the way out of
> this? Shoud vicmd keymap bind to vi-undo-change? Docs suggest it is a
> one-time undo.
We can prevent the viewport clearing by setting UNDO_LIMIT_NO in an
initialisation widget.
An init function setup in the bind mode seems useful anyway. Perhaps for
vi users it should also contain zle vi-cmd-mode. (I alias vared to vared
-i vi-cmd-mode). I followed the naming of the __zed_pg_up widgets in
naming this __zed_init but I'm not especially fond of this – it looks
like a completion function.
vi-undo-change was once the default. It alternates between undoing
and redoing just the last change. undo acts in a vim compatible way:
multiple undos with a separate redo widget. Other mechanisms are
perhaps better: nvi uses u followed by . to do multiple undo. However,
multiple undo is very useful and the vim mechanism is what we have
implemented so it is the default.
Undoing individual characters at a time is not how undo works in vi or
vim. You can bind a key to undo in viins and it'll do that. Otherwise,
undo events are merged when you go into vi command mode allowing
vi-compatible undo behaviour of undoing whole vi changes.
If you want undo from vicmd to be somewhat more fine-grained, you can
call split-undo from within certain widgets. Redefining self-insert to
call split-undo should work, for example.
By the way, the change in 42929 to bind Home and End seems harmless
enough given that PgUp/Down is already there. I'm not so sure about
the use of zle -la to test for widgets existing (zle -N is silent and
idempotent anyway).
Oliver
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index f571daf5e..94938871e 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -67,6 +67,12 @@ if (( bind )) || ! bindkey -M zed >&/dev/null; then
# zed we may want to set this temporally.
bindkey -A main zed-normal-keymap
+ # Define a widget to use at startup, undo shouldn't clear initial buffer
+ __zed_init() {
+ UNDO_LIMIT_NO=$UNDO_CHANGE_NO
+ }
+ zle -N __zed_init
+
# Assign some default keys.
# Depending on your stty's, you may be able to use ^J as accept-line, else:
@@ -105,11 +111,11 @@ if ((fun)) then
var="${(q-)1} () {
}"
fi
- vared -M zed -m zed-vicmd var && eval function "$var"
+ vared -M zed -m zed-vicmd -i __zed_init var && eval function "$var"
else
zed_file_name=$1
[[ -f $1 ]] && var="$(<$1)"
- while vared -M zed -m zed-vicmd var
+ while vared -M zed -m zed-vicmd -i __zed_init var
do
{
print -r -- "$var" >| $zed_file_name
Messages sorted by:
Reverse Date,
Date,
Thread,
Author