zsh-workers
 help / color / mirror / code / Atom feed
ae4addd5b94247c8bba6b7221e9db9aabb2ed76a blob 4773 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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 
# Restrict the start of the editable line to the region between cursor
# and mark (including the character at the end).  Can be bound used as
# a zle widget, or called as a function from another widget.
#
# Optionally accepts exactly two arguments, which are used instead of
# $CURSOR and $MARK as limits to the range.
#
# Upon exit, $MARK is always the start of the edited range and $CURSOR
# the end of the range, even if they began in the opposite order.
#
# Other options:
#   -p pretext   show "pretext" instead of the buffer text before the region.
#   -P posttext  show "posttext" instead of the buffer text after the region.
#                Either or both may be empty.
#   -n           Only replace the text before or after the region with
#                the -p or -P options if the text was not empty.
#   -l lbufvar   $lbufvar is assigned the value of $LBUFFER and
#   -r rbufvar   $rbufvar is assigned the value of $RBUFFER
#                from any recursive edit (i.e. not with -S or -R).  Neither
#                lbufvar nor rbufvar may begin with the prefix "_ntr_".
#   -S statevar
#   -R statevar
#      Save or restore the state in/from the parameter named statevar.  In
#      either case no recursive editing takes place; this will typically be
#      done within the calling function between calls with -S and -R.  The
#      statevar may not begin with the prefix "_ntr_" which is reserved for
#      parameters within narrow-to-region.

emulate -L zsh
setopt extendedglob

local _ntr_new_lbuf _ntr_newrbuf _ntr_lbuf_return _ntr_rbuf_return
local _ntr_predisplay=$PREDISPLAY _ntr_postdisplay=$POSTDISPLAY
integer _ntr_savelim=$UNDO_LIMIT_NO _ntr_changeno
integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK
integer _ntr_stat

local _ntr_opt _ntr_pretext _ntr_posttext _ntr_usepretext _ntr_useposttext
local _ntr_nonempty _ntr_save _ntr_restore _ntr_lbuffer _ntr_rbuffer

while getopts "l:np:P:r:R:S:" _ntr_opt; do
  case $_ntr_opt in
    (l) _ntr_lbuf_return=$OPTARG
	;;
    (n) _ntr_nonempty=1
	;;
    (p) _ntr_pretext=$OPTARG _ntr_usepretext=1
	;;
    (P) _ntr_posttext=$OPTARG _ntr_useposttext=1
	;;
    (r) _ntr_rbuf_return=$OPTARG
	;;
    (R) _ntr_restore=$OPTARG
        ;;
    (S)	_ntr_save=$OPTARG
	;;
    (*) [[ $_ntr_opt != '?' ]] && print "$0: unhandled option: $_ntr_opt" >&2
	return 1
	;;
  esac
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))

if [[ $_ntr_restore = _ntr_* || $_ntr_save = _ntr_* ||
      $_ntr_lbuf_return = _ntr_* || $ntr_rbuf_return = _ntr_* ]]; then
  zle -M "$0: _ntr_ prefix is reserved" >&2
  return 1
fi

if [[ -n $_ntr_save || -z $_ntr_restore ]]; then

  if (( $# )); then
    if (( $# != 2 )); then
      zle -M "$0: supply zero or two arguments" >&2
      return 1
    fi
    _ntr_start=$1
    _ntr_end=$2
  else
    _ntr_start=$MARK
    _ntr_end=$CURSOR
  fi

  if (( _ntr_start > _ntr_end )); then
    _ntr_swap=_ntr_start
    _ntr_start=_ntr_end
    _ntr_end=_ntr_swap
  fi

  (( _ntr_end++, _ntr_cursor -= _ntr_start, _ntr_mark -= _ntr_start ))
  
  _ntr_lbuffer=${BUFFER[1,_ntr_start]}
  if [[ -z $_ntr_usepretext || ( -n $_ntr_nonempty && -z $_ntr_lbuffer ) ]]
  then
    _ntr_pretext=$_ntr_lbuffer
  fi
  _ntr_rbuffer=${BUFFER[_ntr_end,-1]}
  if [[ -z $_ntr_useposttext || ( -n $_ntr_nonempty && -z $_ntr_rbuffer ) ]]
  then
    _ntr_posttext=$_ntr_rbuffer
  fi
  _ntr_changeno=$UNDO_CHANGE_NO
  PREDISPLAY="$_ntr_predisplay$_ntr_pretext"
  POSTDISPLAY="$_ntr_posttext$_ntr_postdisplay"

  if [[ -n $_ntr_save ]]; then
    builtin typeset -ga $_ntr_save
    set -A $_ntr_save "${_ntr_predisplay}" "${_ntr_postdisplay}" \
	"${_ntr_lbuffer}" "${_ntr_rbuffer}" || return 1
  fi

  BUFFER=${BUFFER[_ntr_start+1,_ntr_end-1]}
  CURSOR=$_ntr_cursor
  MARK=$_ntr_mark
  zle split-undo
fi

if [[ -z $_ntr_save && -z $_ntr_restore ]]; then
  {
    UNDO_LIMIT_NO=$UNDO_CHANGE_NO
    zle recursive-edit
    _ntr_stat=$?
    _ntr_newlbuf="$LBUFFER"
    _ntr_newrbuf="$RBUFFER"

    [[ -n $_ntr_lbuf_return ]] &&
      builtin typeset -g ${_ntr_lbuf_return}="${LBUFFER}"
    [[ -n $_ntr_rbuf_return ]] &&
      builtin typeset -g ${_ntr_rbuf_return}="${RBUFFER}"
  } always {
    zle undo $_ntr_changeno
    UNDO_LIMIT_NO=_ntr_savelim
  }
fi

if [[ -n $_ntr_restore || -z $_ntr_save ]]; then
  if [[ -n $_ntr_restore ]]; then
    if ! { _ntr_predisplay="${${(@P)_ntr_restore}[1]}"
           _ntr_postdisplay="${${(@P)_ntr_restore}[2]}"
           _ntr_lbuffer="${${(@P)_ntr_restore}[3]}"
           _ntr_rbuffer="${${(@P)_ntr_restore}[4]}" }; then
      zle -M Failed. >&2
      return 1
    fi
  fi

  PREDISPLAY=$_ntr_predisplay
  POSTDISPLAY=$_ntr_postdisplay
  LBUFFER="$_ntr_lbuffer$_ntr_newlbuf"
  RBUFFER="$_ntr_newrbuf$_ntr_rbuffer"
  MARK=${#_ntr_lbuffer}
fi

return $_ntr_stat
debug log:

solving ae4addd ...
found ae4addd in https://inbox.vuxu.org/zsh-workers/9927.1437383950@thecus.kiddle.eu/
found 293f89b in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 293f89b0fea557fc9e9d54e1fe19ca20255b4930	Functions/Zle/narrow-to-region

applying [1/1] https://inbox.vuxu.org/zsh-workers/9927.1437383950@thecus.kiddle.eu/
diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region
index 293f89b..ae4addd 100644

Checking patch Functions/Zle/narrow-to-region...
Applied patch Functions/Zle/narrow-to-region cleanly.

index at:
100644 ae4addd5b94247c8bba6b7221e9db9aabb2ed76a	Functions/Zle/narrow-to-region

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