zsh-workers
 help / color / mirror / code / Atom feed
8b9ba20d01f2e69085f9cc4e3a35fcdbdea7d4db blob 2061 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
# Implementation of some functionality of the popular vim surround plugin.
# Allows "surroundings" to be changes: parentheses, brackets and quotes.

# To use
#   autoload -Uz surround
#   zle -N delete-surround surround
#   zle -N add-surround surround
#   zle -N change-surround surround
#   bindkey -a cs change-surround
#   bindkey -a ds delete-surround
#   bindkey -a ys add-surround
#   bindkey -M visual S add-surround
#
#  This doesn't allow yss to operate on a line but VS will work

setopt localoptions noksharrays
autoload -Uz select-quoted select-bracketed
local before after
local -A matching
matching=( \( \) \{ \} \< \> \[ \] )

case $WIDGET in
  change-*)
    local MARK="$MARK" CURSOR="$CURSOR" call
    read -k 1 before
    if [[ ${(kvj::)matching} = *$before* ]]; then
      call=select-bracketed
    else
      call=select-quoted
    fi
    read -k 1 after
    $call "a$before" || return 1
    before="$after"
    if [[ -n $matching[$before] ]]; then
      after=" $matching[$before]"
      before+=' '
    elif [[ -n $matching[(r)[$before:q]] ]]; then
      before="${(k)matching[(r)[$before:q]]}"
    fi
    BUFFER[CURSOR]="$after"
    BUFFER[MARK+1]="$before"
    CURSOR=MARK
  ;;
  delete-*)
    local MARK="$MARK" CURSOR="$CURSOR" call
    read -k 1 before
    if [[ ${(kvj::)matching} = *$before* ]]; then
      call=select-bracketed
    else
      call=select-quoted
    fi
    if $call "a$before"; then
      BUFFER[CURSOR]=''
      BUFFER[MARK+1]=''
      CURSOR=MARK
    fi
  ;;
  add-*)
    local save_cut="$CUTBUFFER"
    zle .vi-change || return
    local save_cur="$CURSOR"
    zle .vi-cmd-mode
    read -k 1 before
    after="$before"
    if [[ -n $matching[$before] ]]; then
      after=" $matching[$before]"
      before+=' '
    elif [[ -n $matching[(r)[$before:q]] ]]; then
      before="${(k)matching[(r)[$before:q]]}"
    fi
    CUTBUFFER="$before$CUTBUFFER$after"
    if (( CURSOR )); then
      zle .vi-put-after -n 1
    else
      zle .vi-put-before -n 1
    fi
    CUTBUFFER="$save_cut" CURSOR="$save_cur"
  ;;
esac
debug log:

solving 8b9ba20 ...
found 8b9ba20 in https://inbox.vuxu.org/zsh-workers/26566.1466625442@thecus.kiddle.eu/
found b7be30b in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 b7be30b7526411549f5d3b43e7a2dfa83086dd83	Functions/Zle/surround

applying [1/1] https://inbox.vuxu.org/zsh-workers/26566.1466625442@thecus.kiddle.eu/
diff --git a/Functions/Zle/surround b/Functions/Zle/surround
index b7be30b..8b9ba20 100644

Checking patch Functions/Zle/surround...
Applied patch Functions/Zle/surround cleanly.

index at:
100644 8b9ba20d01f2e69085f9cc4e3a35fcdbdea7d4db	Functions/Zle/surround

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