zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd
@ 2018-06-04 11:17 ` Sebastian Gniazdowski
  2018-06-05  8:31   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2018-06-04 11:17 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

Hello,
the page up / page down bindings that I've added earlier were only for
insert mode. The patch binds them also in vicmd.

Other basic editor keys are Home, End, moving cursor to beginning or
end of line. I've added bindings for them, both to emacs/insert and to
vicmd. $terminfo was wrong about my khome, kend codes, so I've also
added a fallback bindings. I think such fallbacks is what normal
projects are doing – accumulate real-world situations.

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: zed_home_end_keys.diff.txt --]
[-- Type: text/plain, Size: 2506 bytes --]

diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index f571daf..7368439 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -3,7 +3,7 @@
 #
 # No other shell could do this.
 # Edit small files with the command line editor.
-# Use ^X^W to save, ^C to abort.
+# Use ^X^W to save (or ZZ in vicmd mode), ^C to abort.
 # Option -f: edit shell functions.  (Also if called as fned.)
 
 setopt localoptions noksharrays
@@ -60,6 +60,11 @@ __zed_pg_down()
     done
 }
 
+if ! zle -la __zed_pg_up __zed_pg_down; then
+    zle -N __zed_pg_up
+    zle -N __zed_pg_down
+fi
+
 if (( bind )) || ! bindkey -M zed >&/dev/null; then
   # Make the zed keymap a copy of the current main.
   bindkey -N zed main
@@ -75,10 +80,16 @@ if (( bind )) || ! bindkey -M zed >&/dev/null; then
   bindkey -M zed '^x^w' accept-line
   bindkey -M zed '^M' self-insert-unmeta
 
-  zle -N __zed_pg_up
-  zle -N __zed_pg_down
-  [[ ${+terminfo} = 1 && -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
-  [[ ${+terminfo} = 1 && -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+  [[ ${+terminfo} = 1 ]] && {
+    [[  -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
+    [[ -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+    [[ -n "$terminfo[khome]" ]] && bindkey -M zed "$terminfo[khome]" beginning-of-line
+    [[ -n "$terminfo[kend]" ]] && bindkey -M zed "$terminfo[kend]" end-of-line
+
+    # Fallback to well known code as terminfo might be wrong (often) sometimes
+    bindkey -M zed-vicmd "^[[H" beginning-of-line
+    bindkey -M zed-vicmd "^[[F" end-of-line
+  }
 
   # Make zed-set-file-name available.
   # Assume it's in fpath; there's no error at this point if it isn't
@@ -89,6 +100,16 @@ if (( bind )) || ! bindkey -M zed-vicmd >&/dev/null; then
   bindkey -N zed-vicmd vicmd
 
   bindkey -M zed-vicmd "ZZ" accept-line
+  [[ ${+terminfo} = 1 ]] && {
+    [[ -n "$terminfo[kpp]" ]] && bindkey -M zed-vicmd "$terminfo[kpp]" __zed_pg_up
+    [[ -n "$terminfo[knp]" ]] && bindkey -M zed-vicmd "$terminfo[knp]" __zed_pg_down
+    [[ -n "$terminfo[khome]" ]] && bindkey -M zed-vicmd "$terminfo[khome]" vi-beginning-of-line
+    [[ -n "$terminfo[kend]" ]] && bindkey -M zed-vicmd "$terminfo[kend]" vi-end-of-line
+
+    # Fallback to well known code as terminfo might be wrong (often) sometimes
+    bindkey -M zed-vicmd "^[[H" vi-beginning-of-line
+    bindkey -M zed-vicmd "^[[F" vi-end-of-line
+  }
 fi
 
 (( bind )) && return 0

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

* Re: [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd
  2018-06-04 11:17 ` [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd Sebastian Gniazdowski
@ 2018-06-05  8:31   ` Peter Stephenson
  2018-10-18  4:52     ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2018-06-05  8:31 UTC (permalink / raw)
  To: Zsh hackers list

On Mon, 4 Jun 2018 13:17:34 +0200
Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> the page up / page down bindings that I've added earlier were only for
> insert mode. The patch binds them also in vicmd.

Thanks.  The first two mentions of zed-vicmd should actually be zed.
I'll fix those and commit it.

pws


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

* Re: [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd
  2018-06-05  8:31   ` Peter Stephenson
@ 2018-10-18  4:52     ` Sebastian Gniazdowski
  2018-10-18  4:56       ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2018-10-18  4:52 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]

On Tue, 5 Jun 2018 at 10:32, Peter Stephenson <p.stephenson@samsung.com> wrote:
>
> On Mon, 4 Jun 2018 13:17:34 +0200
> Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> > the page up / page down bindings that I've added earlier were only for
> > insert mode. The patch binds them also in vicmd.
>
> Thanks.  The first two mentions of zed-vicmd should actually be zed.
> I'll fix those and commit it.

The patch wasn't commited, but I have a new version of it:
- followed Oliver point that zle -N is idempotent, so one can just
call `zle -N ...' without `zle -la' check,
- fixed the first two zed-vicmd mentions,
- terminfo-fallback bindings aren't guarded by ${+terminfo} = 1 check.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

[-- Attachment #2: zed_home_end_keys.v2.diff.txt --]
[-- Type: text/plain, Size: 2481 bytes --]

diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index f571daf..3325dd5 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -3,7 +3,7 @@
 #
 # No other shell could do this.
 # Edit small files with the command line editor.
-# Use ^X^W to save, ^C to abort.
+# Use ^X^W to save (or ZZ in vicmd mode), ^C to abort.
 # Option -f: edit shell functions.  (Also if called as fned.)
 
 setopt localoptions noksharrays
@@ -60,6 +60,9 @@ __zed_pg_down()
     done
 }
 
+zle -N __zed_pg_up
+zle -N __zed_pg_down
+
 if (( bind )) || ! bindkey -M zed >&/dev/null; then
   # Make the zed keymap a copy of the current main.
   bindkey -N zed main
@@ -75,10 +78,17 @@ if (( bind )) || ! bindkey -M zed >&/dev/null; then
   bindkey -M zed '^x^w' accept-line
   bindkey -M zed '^M' self-insert-unmeta
 
-  zle -N __zed_pg_up
-  zle -N __zed_pg_down
-  [[ ${+terminfo} = 1 && -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
-  [[ ${+terminfo} = 1 && -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+  [[ ${+terminfo} = 1 ]] && {
+    [[  -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
+    [[ -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+    [[ -n "$terminfo[khome]" ]] && bindkey -M zed "$terminfo[khome]" beginning-of-line
+    [[ -n "$terminfo[kend]" ]] && bindkey -M zed "$terminfo[kend]" end-of-line
+  }
+
+  # A fallback to a well known key-sequence code as terminfo
+  # might be wrong (often) sometimes
+  bindkey -M zed "^[[H" beginning-of-line
+  bindkey -M zed "^[[F" end-of-line
 
   # Make zed-set-file-name available.
   # Assume it's in fpath; there's no error at this point if it isn't
@@ -89,6 +99,17 @@ if (( bind )) || ! bindkey -M zed-vicmd >&/dev/null; then
   bindkey -N zed-vicmd vicmd
 
   bindkey -M zed-vicmd "ZZ" accept-line
+  [[ ${+terminfo} = 1 ]] && {
+    [[ -n "$terminfo[kpp]" ]] && bindkey -M zed-vicmd "$terminfo[kpp]" __zed_pg_up
+    [[ -n "$terminfo[knp]" ]] && bindkey -M zed-vicmd "$terminfo[knp]" __zed_pg_down
+    [[ -n "$terminfo[khome]" ]] && bindkey -M zed-vicmd "$terminfo[khome]" vi-beginning-of-line
+    [[ -n "$terminfo[kend]" ]] && bindkey -M zed-vicmd "$terminfo[kend]" vi-end-of-line
+  }
+
+  # A fallback to a well known key-sequence code as terminfo
+  # might be wrong (often) sometimes (vicmd keymap)
+  bindkey -M zed-vicmd "^[[H" vi-beginning-of-line
+  bindkey -M zed-vicmd "^[[F" vi-end-of-line
 fi
 
 (( bind )) && return 0

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

* Re: [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd
  2018-10-18  4:52     ` Sebastian Gniazdowski
@ 2018-10-18  4:56       ` Sebastian Gniazdowski
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Gniazdowski @ 2018-10-18  4:56 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Thu, 18 Oct 2018 at 06:52, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> On Tue, 5 Jun 2018 at 10:32, Peter Stephenson <p.stephenson@samsung.com> wrote:
> >
> > On Mon, 4 Jun 2018 13:17:34 +0200
> > Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> > > the page up / page down bindings that I've added earlier were only for
> > > insert mode. The patch binds them also in vicmd.
> >
> > Thanks.  The first two mentions of zed-vicmd should actually be zed.
> > I'll fix those and commit it.
>
> The patch wasn't commited, but I have a new version of it:

Sorry, it was commited, I was editing a 5.5.1 checkout instead of
HEAD. I'll prepare v3 patch if I'll find something meaningful to add.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

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

end of thread, other threads:[~2018-10-18  4:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180604111827epcas3p3431473d4909d3c2eefa3631c71bb1661@epcas3p3.samsung.com>
2018-06-04 11:17 ` [PATCH] Zed bindings uplift – page up/page down in ViCmd plus home, end in ViCmd Sebastian Gniazdowski
2018-06-05  8:31   ` Peter Stephenson
2018-10-18  4:52     ` Sebastian Gniazdowski
2018-10-18  4:56       ` Sebastian Gniazdowski

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