zsh-workers
 help / color / mirror / code / Atom feed
52246b88f3374b94f534ab27dc982244fc329d0d blob 3365 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
 
# Edit the command line using your usual editor.
# Binding this to '!' in the vi command mode map,
#   autoload -Uz edit-command-line
#   zle -N edit-command-line
#   bindkey -M vicmd '!' edit-command-line
# will give ksh-like behaviour for that key,
# except that it will handle multi-line buffers properly.

emulate -L zsh
local left right prebuffer buffer=$BUFFER lbuffer=$LBUFFER
local TMPSUFFIX=.zsh
# set up parameters depending on which context we are called from,
# see below comment for more details
if (( REGION_ACTIVE == 1 )); then
  if (( CURSOR < MARK )); then
    left=$CURSOR right=$MARK
    lbuffer=
  else
    left=$MARK right=$CURSOR
    lbuffer[right-left,-1]=
  fi
  (( left++ ))
  buffer=$BUFFER[left,right]
elif (( REGION_ACTIVE == 2 )); then
  local mark_left mark_right offset_right
  if (( CURSOR < MARK )); then
    mark_left=$CURSOR mark_right=$MARK
  else
    mark_left=$MARK mark_right=$CURSOR
  fi
  left=${(SB)${BUFFER[1,mark_left]}%$'\n'}
  (( left != 1 )) && (( left++ ))
  offset_right=${(SB)${BUFFER[mark_right+1,-1]}#$'\n'}
  if (( offset_right == 1 )); then
    right=$#BUFFER
  else
    (( right = mark_right + offset_right - 1 ))
  fi
  lbuffer=${lbuffer[left,CURSOR]}
  buffer=$BUFFER[left,right]
elif (( ! ZLE_RECURSIVE )); then
  prebuffer=$PREBUFFER
fi

() {
  exec </dev/tty

  # Compute the cursor's position in bytes, not characters.
  setopt localoptions nomultibyte noksharrays

  (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2]

  # Open the editor, placing the cursor at the right place if we know how.
  local -a editor
  zstyle -a :zle:$WIDGET editor editor
  if (( ! $#editor )); then
    editor=( "${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}" )
  fi
  case $editor in
    (*vim*)
      integer byteoffset=$(( $#prebuffer + $#lbuffer + 1 ))
      "${(@)editor}" -c "normal! ${byteoffset}go" -- $1;;
    (*emacs*)
      local lines=( "${(@f):-"$prebuffer$lbuffer"}" )
      "${(@)editor}" +${#lines}:$((${#lines[-1]} + 1)) $1;;
    (*) "${(@)editor}" $1;;
  esac

  (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1]

  # Replace the buffer with the editor output.
  # avoid drawing a new prompt when we can:
  # - in recursive-edit, the send-break will just cancel the recursive-edit
  #   rather than reload the line from print -z so in that case we want to
  #   just set $BUFFER (unfortunately, recursive-edit doesn't reset CONTEXT
  #   or PREBUFFER so we have to explicitly handle this case, which overrides
  #   the following point)
  # - when we are at PS2 (CONTEXT == cont && ! ZLE_RECURSIVE) we do want the
  #   break or otherwise the text from PREBUFFER will be inserted twice
  # - when the region is active, we only want to change the parts of BUFFER
  #   covered by the region, and any PREBUFFER stays as PREBUFFER
  # - in all other cases (that I can think of) we also just want to set
  #   $BUFFER directly.
  if (( REGION_ACTIVE )); then
    # adjust the length of the region to the length of the edited text
    local prelen=$#BUFFER
    BUFFER[left,right]="$(<$1)"
    if (( MARK > CURSOR )); then
      (( MARK += $#BUFFER - prelen ))
    else
      (( CURSOR += $#BUFFER - prelen ))
    fi
  elif [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then
    BUFFER="$(<$1)" 
  else
    print -Rz - "$(<$1)"
    zle send-break
  fi

} =(<<<"$prebuffer$buffer")
debug log:

solving 52246b88f ...
found 52246b88f in https://inbox.vuxu.org/zsh-workers/PEEOyknRLLWFRjtZRcuxXrkHEqQYs6bxEPs_PEMqZNVbYD3QjR0HgbERrKA6gpZqMODFfgwDZMe6Nw2GM0f9JbtSN4bcaxrkp6bYsxTR7ZQ=@protonmail.com/
found 5f7ea321f in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 5f7ea321fd006b5adffe90b4ee577b24ca1fb0f1	Functions/Zle/edit-command-line

applying [1/1] https://inbox.vuxu.org/zsh-workers/PEEOyknRLLWFRjtZRcuxXrkHEqQYs6bxEPs_PEMqZNVbYD3QjR0HgbERrKA6gpZqMODFfgwDZMe6Nw2GM0f9JbtSN4bcaxrkp6bYsxTR7ZQ=@protonmail.com/
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 5f7ea321f..52246b88f 100644

Checking patch Functions/Zle/edit-command-line...
Applied patch Functions/Zle/edit-command-line cleanly.

index at:
100644 52246b88f3374b94f534ab27dc982244fc329d0d	Functions/Zle/edit-command-line

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