From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 7472F23E38 for ; Wed, 28 Feb 2024 21:12:05 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709151125; b=LDn0h1xiXZSeqYFfznPuhN/P5jZghnnUbN89TSuZMP+R46xfCr9BByHSHRsXIPO7zew4APs8/w VjbXsdn+DVUd/+5vpHljPGoE59EwXRwShuLC7ZW3ZCh2tX5FfdjEkSD+eR3uHrBrQgMHgHtfvr aRD9SqzdAEnB8egHPANWKGf2sIncI5Lqpdh9k/x8qK3tJwCOMRbBYLHP4G1HHVGzfA54Y0FSCh u2ak6+BoneGMtWSYOa7OYs9N1k2mX6UKNkXhBCTn7m6bK47J5PAX7x+oE9BQVf+ud2CgXtGtei W6XXlIz+nqIe2PW8iVpUffDaSqV4x68P60ZUN+ZCF+k5LA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wfhigh4-smtp.messagingengine.com) smtp.remote-ip=64.147.123.155; dkim=pass header.d=midchildan.org header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=midchildan.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1709151125; bh=JqIl5r+/SdiRWf7tLVeiF0Iiu027BzklG6R7OAcgsCs=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=XW60fiamJf2AtrylmYaz+6XfNEOWBKUJ6DPs+K+V1xg+gM3/JQZoFNkVbmlWf1LxfZ2W+zMhII jcGfjI1f/2V/MGGNymucxvKugHzQULvJ+K0XAsCIFcC5xvZoTSg1yQuKw8YVaiTm8CQZGxb4zR qr/4dToH1/TliWPFaS9zuOqJp9BIj3vjqhKJIjQ+T4xMRmrf2ci/WcYYE35BbWszbuRFRkVk0d oi1RQHKpIPOiq4RZQHXW7Z4LU9ocdpaz+XIr+37Gv+mQdNrs5rWQgzpXvouq3/vxusKCQzCOEd W3nVMTzHlKxLHdeREkFQ4MTPrHSUZTPSD5NKiD5D60VoWQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=7uS+gtZqaA0TbuYAN+PH0X9Gq6UiRLlPQ2Q7i7Q2FeE=; b=TPw053b3WVi7oeHb8XZtaBTZeZ T3wM3GG32sYz8IktG89GV+cWO0oQO1FndRJbCRz9MaEH0ZuLNyXPTW46qkUsIdhc4JeNOg7VrWmGo /0waGPsZo2r8QdMl1goXjE0UANsVTzLT+E/vw8W0/CSUnELfdv0fjvejhBVPqjpjKKEXIY5YT1yP1 xM0Q08tQpNmEwiuda9puZnLgeQEEH7nlNOfTW78EHwKwHQkOHZFJZqpIUD+5bl+UJDxTTeL+lcFkd wx6+vlgVP6TxVOJy1nNpkdGG6H6O3S/G92WfjO7bqoEmH+QqJAFDjNIWdoYfuj72wWUbgQb6kiFmi EBQCQTog==; Received: by zero.zsh.org with local id 1rfQHc-0000e0-So; Wed, 28 Feb 2024 20:12:05 +0000 Authentication-Results: zsh.org; iprev=pass (wfhigh4-smtp.messagingengine.com) smtp.remote-ip=64.147.123.155; dkim=pass header.d=midchildan.org header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=midchildan.org; arc=none Received: from wfhigh4-smtp.messagingengine.com ([64.147.123.155]:50345) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rfQGx-0000JE-FY; Wed, 28 Feb 2024 20:11:25 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.west.internal (Postfix) with ESMTP id 4A885180006C; Wed, 28 Feb 2024 15:11:21 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 28 Feb 2024 15:11:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=midchildan.org; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1709151080; x= 1709237480; bh=7uS+gtZqaA0TbuYAN+PH0X9Gq6UiRLlPQ2Q7i7Q2FeE=; b=Y VcaR+rEpUZQLOeP8GQjOQRTMSDyJEgSmvkI26RkTtAJosDjifTkn4JZy5Gmjz/Ik eqyUzo4eBRanOb923EM1+9EQOk2jzWgoqcIWLVj87Mjzgk1e/AkyotiVBRpsc8O8 33lERC+fyoy8/mhb4EopFanvTJgpFAE77GfQJmic8uf/wAb+BOPR3mFDIQW7Urm+ MlrC1A25Xud6XVgn5QB0q4iMhBMRm7Lfl3rkDNxF4fbIhriDaO0/ShR0nlMScSAv ZCk59lp5ejBKCV6oM77LTQpONU2bx6fLHQ+x6QhZJHfm/ITOC7a8AUxZ7zTBb1dL ANcp++i2bzohFDt3Z4D8A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1709151080; x= 1709237480; bh=7uS+gtZqaA0TbuYAN+PH0X9Gq6UiRLlPQ2Q7i7Q2FeE=; b=g Rgox7jm0kr3qAdV1AktezIF7H6gijYfPiePN4Pd08D2jcicfQafbNWMR0m1jcvlj NACg6FnlPqofj7yevt6JudzGOQaiaMIectSetx7qJR55sPWpLEyeZOzXuLbI1GXw NkcZ4h+0cNeDTJp9LAB21ds2zOad5QcvY2g6C/DGIQ4/EPxpgadrwyWO2nqS2VSt NV6jTjNVkDRAkHSpPwc77Cvct3hP71d+aHcCU6Tv6E/z3yByVEs9XpJtH9thqMpt 7FxV7yqKDAonvUEXNvaO4SM+pVQKLEICf6E6r9fyWM4sBHcywCgsU58VLJ6LKguf zGrSaDADOmt1MylMykwFg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeejgdduvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkfgjfhgggfestdekre dttddttdenucfhrhhomhepmhhiuggthhhilhgurghnuceoghhithesmhhiuggthhhilhgu rghnrdhorhhgqeenucggtffrrghtthgvrhhnpedugfffgeffieekgeekvdeihfduffdvhf fgkeefuefhffegueettdektdffgeduieenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehgihhtsehmihgutghhihhluggrnhdrohhrgh X-ME-Proxy: Feedback-ID: i970949fb:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Feb 2024 15:11:19 -0500 (EST) From: midchildan To: zsh-workers@zsh.org Cc: midchildan Subject: [PATCH] incarg: add a backward variant and make it repeatable Date: Thu, 29 Feb 2024 05:07:33 +0900 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 52637 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: I misunderstood the part about the previous patch being applied, and just realized it already made into master. So I rebased the latest follow-up patch against the current master branch. --- Doc/Zsh/contrib.yo | 8 +- Functions/Zle/incarg | 64 +++++++- Test/X05zleincarg.ztst | 356 ++++++++++++++++++++++++++++++----------- 3 files changed, 324 insertions(+), 104 deletions(-) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index ea00f0ccc..e682c800a 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2635,7 +2635,8 @@ When the widget is named tt(incarg), the widget will increment an integer placed under the cursor placed or just to the left of it. tt(decarg), on the other hand, decrements the integer. When the name is prefixed with tt(vi), the cursor will jump to the nearest integer after the cursor before incrementing -it. +it. The tt(vi) prefix can also be combined with a tt(backward-) prefix to make +the widget search backwards for numbers. There's also a tt(sync-) prefix that can be added to the widget name. This variant is used for creating a sequence of numbers on split terminals with @@ -2643,8 +2644,9 @@ synchronized key input. The first pane won't increment the integer at all, but each pane after that will have the integer incremented once more than the previous pane. It currently supports tmux and iTerm2. -The prefixes tt(vi) and tt(sync-) can be combined, for example, into -tt(vim-sync-). In this case, the tt(vi) prefix should come first. +The prefixes tt(vi), tt(backward-), and tt(sync-) can be combined, for example, +into tt(vim-sync-) or tt(vim-backward-sync-). The tt(vi) prefix needs to be +at the very beginning. example(bindkey '^X+' incarg) ) diff --git a/Functions/Zle/incarg b/Functions/Zle/incarg index 9d56b21f6..f8b0e6b3b 100644 --- a/Functions/Zle/incarg +++ b/Functions/Zle/incarg @@ -41,11 +41,20 @@ emulate -L zsh # This behaves like Vim's CTRL-A / CTRL-X. It moves the cursor to the nearest # number after the cursor and increments or decrements it. # +# - vim-backward-incarg / vim-backward-decarg +# +# This behaves like vim-incarg & vim-decarg, but it searches backwards for a +# number. +# # - vim-sync-incarg / vim-sync-decarg # # This combines the behavior of the vim- and sync- variants. It's inspired by # Vim's g_CTRL-A / g_CTRL-X. # +# - vim-backward-sync-incarg / vim-backward-sync-decarg +# +# This combines the behavior of the vim-backward- and sync- variants. +# # Example Usage: # # autoload -Uz incarg @@ -58,9 +67,13 @@ emulate -L zsh # 'g^A' vim-sync-incarg \ # 'g^X' vim-sync-decarg +zle -f vichange + setopt localoptions extended_glob local match mbegin mend MATCH MBEGIN MEND i +[[ -z "$BUFFER" ]] && return 1 + # find the number and determine the base integer pos=$(( CURSOR + 1 )) base=0 @@ -104,11 +117,35 @@ fi if (( base == 0 )); then if [[ "$WIDGET" == vi* ]]; then - # jump to the nearest number after the cursor - while [[ "$BUFFER[pos]" == [^0-9] ]]; do - (( pos++ )) - (( pos > $#BUFFER )) && return 1 - done + if [[ "$WIDGET" == *backward-* ]]; then + # search backwards for a number + while true; do + case "$BUFFER[1,pos]" in + *0[xX][0-9a-fA-F]##) base=16 ;; + *0[oO][0-7]##) base=8 ;; + *0[bB][01]##) base=2 ;; + *[0-9]) base=10 ;; + *-) + case "$BUFFER[pos,-1]" in + -0[xX][0-9a-fA-F]*) ;; + -0[oO][0-7]*) ;; + -0[bB][01]*) ;; + -[0-9]*) base=10 ;; + esac + ;; + esac + (( base != 0 )) && break + + (( pos-- )) + (( pos <= 0 )) && return 1 + done + else + # jump to the nearest number after the cursor + while [[ "$BUFFER[pos]" == [^0-9] ]]; do + (( pos++ )) + (( pos > $#BUFFER )) && return 1 + done + fi fi # check for a prefix right after the cursor and jump right after it, if any @@ -204,6 +241,12 @@ fi local old="$BUFFER[first,last]" integer oldlen=$#BUFFER +integer oldnum="$base#$old" 2> /dev/null + +# -00 should increment to 01 instead of 001 +if [[ "$BUFFER[first]" == '-' ]] && (( oldnum == 0 && delta > 0 )); then + (( ndigits-- )) +fi local fmt1 fmt2 case "$base" in @@ -214,10 +257,12 @@ case "$base" in esac local raw_result padded +# $(( )) outputs an error message to stderr when integer truncation occurs printf -v raw_result "%0$ndigits$fmt1" $(( [$fmt2] "$base#$old" + delta )) 2> /dev/null padded="${raw_result// /0}" +integer newnum="$base#$padded" 2> /dev/null -integer oldnum="$base#$old" newnum="$base#$padded" 2> /dev/null +# try to detect integer truncation if (( base != 10 && newnum < 0 || delta > 0 && newnum < oldnum || delta < 0 && newnum > oldnum )); then @@ -242,7 +287,12 @@ if zstyle -t ":zle:$WIDGET" debug; then zle -M "[$WIDGET] base: $base delta: $delta old: '$old' new: '$new'" fi -BUFFER[first,last]="$new" +if (( 0 < first && first <= last && last <= $#BUFFER )); then + BUFFER[first,last]="$new" +else + zle -M "[$WIDGET] The detected location of the integer was invalid. [location=BUFFER[$first,$last]]" + return 1 +fi integer offset=0 if [[ "$WIDGET" == vi* ]]; then diff --git a/Test/X05zleincarg.ztst b/Test/X05zleincarg.ztst index 2a6aa2d3f..50a450734 100644 --- a/Test/X05zleincarg.ztst +++ b/Test/X05zleincarg.ztst @@ -10,7 +10,7 @@ fi zpty_run ' autoload -Uz incarg - for name in {,vim-}{,sync-}{inc,dec}arg; do + for name in {,vim-,vim-backward-}{,sync-}{inc,dec}arg; do zle -N "$name" incarg done bindkey -v "^N" incarg @@ -21,6 +21,8 @@ bindkey -a "^P" vim-decarg bindkey -a "^F" vim-sync-incarg bindkey -a "^B" vim-sync-decarg + bindkey -a "^E" vim-backward-incarg + bindkey -a "^Y" vim-backward-decarg unset TMUX_PANE ITERM_SESSION_ID tmux() { echo "$TMUX_PANE" @@ -29,26 +31,40 @@ %test +# Basic increment & decrement + zletest $'0\C-n' -0:increment an integer with incarg +0:incarg increments an integer >BUFFER: 1 >CURSOR: 1 zletest $'0\C-p' -0:decrement an integer with decarg +0:decarg decrements an integer >BUFFER: -1 >CURSOR: 2 zletest $'echo 0\e0\C-n' -0:increment an integer with vim-incarg +0:vim-incarg increments an integer >BUFFER: echo 1 >CURSOR: 5 zletest $'echo 0\e0\C-p' -0:decrement an integer with vim-decarg +0:vim-decarg decrements an integer >BUFFER: echo -1 >CURSOR: 6 + zletest $'echo 0 foo\e\C-e' +0:vim-backward-incarg increments an integer +>BUFFER: echo 1 foo +>CURSOR: 5 + + zletest $'echo 0 foo\e\C-y' +0:vim-backward-decarg decrements an integer +>BUFFER: echo -1 foo +>CURSOR: 6 + +# sync- variants + zletest $'0\C-f' 0:sync-incarg does nothing on unsupported terminals >BUFFER: 0 @@ -57,42 +73,42 @@ zpty_run 'TMUX_PANE=0' zletest $'0\C-f' zpty_run 'unset TMUX_PANE' -0:sync-incarg on tmux in pane 0 +0:sync-incarg does nothing on tmux in pane 0 >BUFFER: 0 >CURSOR: 1 zpty_run 'TMUX_PANE=1' zletest $'0\C-f' zpty_run 'unset TMUX_PANE' -0:sync-incarg on tmux in pane 1 +0:sync-incarg increments by 1 on tmux in pane 1 >BUFFER: 1 >CURSOR: 1 zpty_run 'TMUX_PANE=2' zletest $'0\C-f' zpty_run 'unset TMUX_PANE' -0:sync-incarg on tmux in pane 2 +0:sync-incarg increments by 2 on tmux in pane 2 >BUFFER: 2 >CURSOR: 1 zpty_run 'ITERM_SESSION_ID=w0t0p0:00000000-0000-0000-0000-000000000000' zletest $'0\C-f' zpty_run 'unset ITERM_SESSION_ID' -0:sync-incarg on tmux in pane 0 +0:sync-incarg does nothing on tmux in pane 0 >BUFFER: 0 >CURSOR: 1 zpty_run 'ITERM_SESSION_ID=w0t0p1:00000000-0000-0000-0000-000000000000' zletest $'0\C-f' zpty_run 'unset ITERM_SESSION_ID' -0:sync-incarg on tmux in pane 1 +0:sync-incarg increments by 1 on tmux in pane 1 >BUFFER: 1 >CURSOR: 1 zpty_run 'ITERM_SESSION_ID=w0t0p2:00000000-0000-0000-0000-000000000000' zletest $'0\C-f' zpty_run 'unset ITERM_SESSION_ID' -0:sync-incarg on tmux in pane 2 +0:sync-incarg increments by 2 on tmux in pane 2 >BUFFER: 2 >CURSOR: 1 @@ -100,200 +116,155 @@ zpty_run 'ITERM_SESSION_ID=w0t0p2:00000000-0000-0000-0000-000000000000' zletest $'0\C-f' zpty_run 'unset TMUX_PANE ITERM_SESSION_ID' -0:tmux pane number takes precedence over iTerm2's +0:sync-incarg prioritizes tmux pane number over iTerm2's >BUFFER: 1 >CURSOR: 1 zletest $'0\e2\C-n' -0:Providing a numeric argument will change the incremented amount +0:incarg changes the incremented amount based on the numeric argument >BUFFER: 2 >CURSOR: 0 zpty_run 'incarg=3' zletest $'0\e\C-n' zpty_run 'unset incarg' -0:Setting the incarg variable will change the default incremented amount +0:incarg changes the default incremented amount based on the incarg variable >BUFFER: 3 >CURSOR: 0 zpty_run 'incarg=3' zletest $'0\e2\C-n' zpty_run 'unset incarg' -0:A numeric argument will take precedence over the incarg variable +0:incarg prioritizes the numeric argument over the incarg variable >BUFFER: 2 >CURSOR: 0 zpty_run 'TMUX_PANE=2' zletest $'0\e2\C-f' zpty_run 'unset TMUX_PANE' -0:Providing a numeric argument will work for the sync- variants of incarg +0:The sync- variants of incarg takes the numeric argument into account >BUFFER: 4 >CURSOR: 0 +# Leading zeros + zletest $'000\C-n' -0:Incrementing a decimal integer preserves leading zeros +0:incarg preserves leading zeros of decimal integers >BUFFER: 001 >CURSOR: 3 zletest $'-001\C-n\C-n' -0:Leading zeros are preserved when the digit turns from negative to positive +0:incarg preserves leading zeros when the digit turns from negative to positive >BUFFER: 001 >CURSOR: 3 zletest $'001\C-p\C-p' -0:Leading zeros are preserved when the digit turns from positive to negative +0:incarg preserves leading zeros when the digit turns from positive to negative >BUFFER: -001 >CURSOR: 4 zletest $'001\e1000\C-n' -0:Incrementing an integer works when the result has more zeros than the original +0:incarg works when the result has more number of digits than the original >BUFFER: 1001 >CURSOR: 3 zletest $'001\e2000\C-p' -0:Decrementing an integer with leading zeros works when the result has more digits than the original +0:decargs works on integers with leading zeros when the result has more digits than the original >BUFFER: -1999 >CURSOR: 4 +# Binaries + zletest $'0b11\C-n' -0:Increment a binary integer +0:incarg can increment a binary integer >BUFFER: 0b100 >CURSOR: 5 zletest $'0B11\C-n' -0:Increment a binary integer with an upper case prefix +0:incarg can increment a binary integer with an upper case prefix >BUFFER: 0B100 >CURSOR: 5 zletest $'0b100\C-p' -0:Decrement a binary integer +0:decarg can decrement a binary integer >BUFFER: 0b11 >CURSOR: 4 zletest $'0b0011\C-n' -0:Increment a binary integer preserves leading zeros +0:incarg can preserve leading zeros of binaries >BUFFER: 0b0100 >CURSOR: 6 zletest $'0b001\e8\C-n' -0:Incrementing a binary integer work when the result has more zeros than the original +0:incarg works on binaries when the result has more zeros than the original >BUFFER: 0b1001 >CURSOR: 5 zletest $'0b0\C-p' -0:Decrementing a binary integer to a negative value will fail +0:decarg fails to produce a negative binary value >BUFFER: 0b0 >CURSOR: 3 +# Octals + zletest $'0o7\C-n' -0:Increment an octal integer +0:incarg can increment an octal integer >BUFFER: 0o10 >CURSOR: 4 zletest $'0O7\C-n' -0:Increment an octal integer with an upper case prefix +0:incarg can increment an octal integer with an upper case prefix >BUFFER: 0O10 >CURSOR: 4 zletest $'0o10\C-p' -0:Decrement an octal integer +0:decarg can decrement an octal integer >BUFFER: 0o7 >CURSOR: 3 zletest $'0o0\C-p' -0:Decrementing an octal integer to a negative value will fail +0:decarg fails to produce a negative octal value >BUFFER: 0o0 >CURSOR: 3 +# Hexadecimals + zletest $'0x9\C-n' -0:Increment a hexadecimal integer +0:incarg can increment a hexadecimal integer >BUFFER: 0xa >CURSOR: 3 zletest $'0X9\C-n' -0:Increment a hexadecimal integer with an upper case prefix +0:incarg can increment a hexadecimal integer with an upper case prefix >BUFFER: 0XA >CURSOR: 3 zletest $'0xf\C-n' -0:Increment a hexadecimal integer with no numeric digit +0:incarg can increment a hexadecimal integer with no numeric digit >BUFFER: 0x10 >CURSOR: 4 zletest $'0x10\C-p' -0:Decrement a hexadecimal integer +0:decarg can decrement a hexadecimal integer >BUFFER: 0xf >CURSOR: 3 zletest $'0x0\C-p' -0:Decrementing an octal integer to a negative value will fail +0:decarg fails to produce a negative hexadecimal value >BUFFER: 0x0 >CURSOR: 3 zletest $'0x0b1\C-n' -0:a number that starts with 0x0b is interpreted as a hexadecimal integer +0:incarg interprets integers starting with 0x0b as a hexadecimal >BUFFER: 0x0b2 >CURSOR: 5 - zletest $'10x9\e0\C-n' -0:[0-9]0x[0-9a-f] will become [0-9]1x[0-9a-f] when incremented from the left of x ->BUFFER: 11x9 ->CURSOR: 1 - - zletest $'10x9\eFx\C-n' -0:[0-9]0x[0-9a-f] will increment the hexadecimal 0x[0-9a-f] when the cursor is on x ->BUFFER: 10xa ->CURSOR: 3 - - zletest $'10x9\e\C-n' -0:[0-9]0x[0-9a-f] will increment the hexadecimal 0x[0-9a-f] when the cursor is on the right of x ->BUFFER: 10xa ->CURSOR: 3 - - zletest $'10b1\e0\C-n' -0:[0-9]0b[01] will become [0-9]1b[01] when incremented from the left of b ->BUFFER: 11b1 ->CURSOR: 1 - - zletest $'10b1\eFb\C-n' -0:[0-9]0b[01] will increment the binary 0b[01] when the cursor is on b ->BUFFER: 10b10 + zletest $'0x0b1\e\C-e' +0:vim-backward-incarg interprets integers starting with 0x0b as a hexadecimal +>BUFFER: 0x0b2 >CURSOR: 4 - zletest $'10b1\e\C-n' -0:[0-9]0b[01] will increment the binary 0b[01] when the cursor is on the right of b ->BUFFER: 10b10 ->CURSOR: 4 - - zletest $'10o7\e0\C-n' -0:[0-9]0o[0-7] will become [0-9]1o[0-7] when incremented from the left of o ->BUFFER: 11o7 ->CURSOR: 1 - - zletest $'10o7\eFo\C-n' -0:[0-9]0o[0-7] will increment the octal 0o[0-7] when the cursor is on o ->BUFFER: 10o10 ->CURSOR: 4 - - zletest $'10o7\e\C-n' -0:[0-9]0o[0-7] will increment the octal 0o[0-7] when the cursor is on the right of o ->BUFFER: 10o10 ->CURSOR: 4 - - zletest $'0b0x9\eF0\C-n' -0:0b0x[0-9a-f] will increment the binary 0b0 when the cursor is on the left of x ->BUFFER: 0b1x9 ->CURSOR: 2 - - zletest $'0b0x9\eFx\C-n' -0:0b0x[0-9a-f] will increment the hexadecimal 0x[0-9a-f] when the cursor is on top of x ->BUFFER: 0b0xa ->CURSOR: 4 - - zletest $'0b0x9\e\C-n' -0:0b0x[0-9a-f] will increment the hexadecimal 0x[0-9a-f] when the cursor is on the right of x ->BUFFER: 0b0xa ->CURSOR: 4 +# Cursor position - incarg zletest $'echo 012ab\eF i\C-n' 0:incarg does nothing when the cursor is placed just to the left of an integer @@ -325,6 +296,68 @@ >BUFFER: echo 012ab >CURSOR: 9 + zletest $'10x9\e0\C-n' +0:incarg turns [0-9]0x[0-9a-f] into [0-9]1x[0-9a-f] when the cursor is at the left of x +>BUFFER: 11x9 +>CURSOR: 1 + + zletest $'10x9\eFx\C-n' +0:incarg takes [0-9]0x[0-9a-f] and increments the hexadecimal part when the cursor is on x +>BUFFER: 10xa +>CURSOR: 3 + + zletest $'10x9\e\C-n' +0:incarg takes [0-9]0x[0-9a-f] and increments the hexadecimal part when the cursor is at the right of x +>BUFFER: 10xa +>CURSOR: 3 + + zletest $'10b1\e0\C-n' +0:incarg turns [0-9]0b[01] into [0-9]1b[01] when the cursor is at the left of b +>BUFFER: 11b1 +>CURSOR: 1 + + zletest $'10b1\eFb\C-n' +0:incarg takes [0-9]0b[01] and increments the binary part when the cursor is on b +>BUFFER: 10b10 +>CURSOR: 4 + + zletest $'10b1\e\C-n' +0:incarg takes [0-9]0b[01] and increments binary part when the cursor is at the right of b +>BUFFER: 10b10 +>CURSOR: 4 + + zletest $'10o7\e0\C-n' +0:incarg turns [0-9]0o[0-7] into [0-9]1o[0-7] when the cursor is at the left of o +>BUFFER: 11o7 +>CURSOR: 1 + + zletest $'10o7\eFo\C-n' +0:incarg takes [0-9]0o[0-7] and increments the octal part when the cursor is on o +>BUFFER: 10o10 +>CURSOR: 4 + + zletest $'10o7\e\C-n' +0:incarg takes [0-9]0o[0-7] and increments the octal part when the cursor is at the right of o +>BUFFER: 10o10 +>CURSOR: 4 + + zletest $'0b0x9\eF0\C-n' +0:incarg takes 0b0x[0-9a-f] and increments the binary part when the cursor is at the left of x +>BUFFER: 0b1x9 +>CURSOR: 2 + + zletest $'0b0x9\eFx\C-n' +0:incarg takes 0b0x[0-9a-f] and increments the hexadecimal part when the cursor is on x +>BUFFER: 0b0xa +>CURSOR: 4 + + zletest $'0b0x9\e\C-n' +0:incarg takes 0b0x[0-9a-f] and increments the hexadecimal part when the cursor is at the right of x +>BUFFER: 0b0xa +>CURSOR: 4 + +# Cursor position - vim-incarg + zletest $'echo 012ab\eF \C-n' 0:vim-incarg works when the cursor is placed to the left of an integer >BUFFER: echo 013ab @@ -355,6 +388,141 @@ >BUFFER: echo 012ab >CURSOR: 9 +# Cursor position - vim-backward-incarg + + zletest $'echo 012ab\eF \C-e' +0:vim-backward-incarg does nothing when the cursor is placed just to the left of an integer +>BUFFER: echo 012ab +>CURSOR: 4 + + zletest $'echo 012ab\eF0\C-e' +0:vim-backward-incarg works when the cursor is placed at the leftmost digit of an integer +>BUFFER: echo 013ab +>CURSOR: 7 + + zletest $'echo 012ab\eF1\C-e' +0:vim-backward-incarg works when the cursor is placed at the inner digit of an integer +>BUFFER: echo 013ab +>CURSOR: 7 + + zletest $'echo 012ab\eF2\C-e' +0:vim-backward-incarg works when the cursor is placed at the rightmost digit of an integer +>BUFFER: echo 013ab +>CURSOR: 7 + + zletest $'echo 012ab\eFa\C-e' +0:vim-backward-incarg works when the cursor is placed just to the right of an integer +>BUFFER: echo 013ab +>CURSOR: 7 + + zletest $'echo 012ab\e\C-e' +0:vim-backward-incarg works when the cursor is placed more than a single letter away to the right +>BUFFER: echo 013ab +>CURSOR: 7 + + zletest $'10x9\eFx\C-e' +0:vim-backward-incarg will take [0-9]0x[0-9a-f] and increment the hexadecimal part when the cursor is on x +>BUFFER: 10xa +>CURSOR: 3 + + zletest $'10x9\e\C-e' +0:vim-backward-incarg will take [0-9]0x[0-9a-f] and increment the hexadecimal part when the cursor is on the right of x +>BUFFER: 10xa +>CURSOR: 3 + + zletest $'10b1\e0\C-e' +0:vim-backward-incarg will turn [0-9]0b[01] into [0-9]1b[01] when the cursor is at the left of b +>BUFFER: 11b1 +>CURSOR: 1 + + zletest $'10b1\eFb\C-e' +0:vim-backward-incarg will take [0-9]0b[01] and increment the binary part when the cursor is on b +>BUFFER: 10b10 +>CURSOR: 4 + + zletest $'10b1\e\C-e' +0:vim-backward-incarg will take [0-9]0b[01] and increment the binary part when the cursor is on the right of b +>BUFFER: 10b10 +>CURSOR: 4 + + zletest $'10o7\e0\C-e' +0:vim-backward-incarg will turn [0-9]0o[0-7] into [0-9]1o[0-7] when the cursor is at the left of o +>BUFFER: 11o7 +>CURSOR: 1 + + zletest $'10o7\eFo\C-e' +0:vim-backward-incarg will take [0-9]0o[0-7] and increment the octal part when the cursor is on o +>BUFFER: 10o10 +>CURSOR: 4 + + zletest $'10o7\e\C-e' +0:vim-backward-incarg will take [0-9]0o[0-7] and increment the octal part when the cursor is at the right of o +>BUFFER: 10o10 +>CURSOR: 4 + + zletest $'0b0x9\eF0\C-e' +0:vim-backward-incarg will take 0b0x[0-9a-f] and increment the binary 0b0 when the cursor is on the left of x +>BUFFER: 0b1x9 +>CURSOR: 2 + + zletest $'0b0x9\eFx\C-e' +0:vim-backward-incarg will take 0b0x[0-9a-f] and increment the hexadecimal part when the cursor is on x +>BUFFER: 0b0xa +>CURSOR: 4 + + zletest $'0b0x9\e\C-e' +0:vim-backward-incarg will take 0b0x[0-9a-f] and increment the hexadecimal part when the cursor is at the right of x +>BUFFER: 0b0xa +>CURSOR: 4 + +# Repeats + + zletest $'echo 0\e0\C-n.' +0:vim-incarg is compatible with the repeat command +>BUFFER: echo 2 +>CURSOR: 5 + + zletest $'echo 0\e0\C-p.' +0:vim-decarg is compatible with the repeat command +>BUFFER: echo -2 +>CURSOR: 6 + + zletest $'echo 0 foo\e\C-e.' +0:vim-backward-incarg is compatible with the repeat command +>BUFFER: echo 2 foo +>CURSOR: 5 + + zletest $'echo 0\e010\C-n.' +0:Repeats of vim-incarg takes the numeric argument into account +>BUFFER: echo 20 +>CURSOR: 6 + + zletest $'echo 0 foo\e10\C-e.' +0:Repeats of vim-backward-incarg takes the numeric argument into account +>BUFFER: echo 20 foo +>CURSOR: 6 + + zpty_run 'TMUX_PANE=0' + zletest $'echo 0\e0\C-f.' + zpty_run 'unset TMUX_PANE' +0:Repeats of vim-sync-incarg work in pane 0 +>BUFFER: echo 0 +>CURSOR: 5 + + zpty_run 'TMUX_PANE=1' + zletest $'echo 0\e0\C-f.' + zpty_run 'unset TMUX_PANE' +0:Repeats of vim-sync-incarg work in pane 1 +>BUFFER: echo 2 +>CURSOR: 5 + + zpty_run 'TMUX_PANE=2' + zletest $'echo 0\e0\C-f.' + zpty_run 'unset TMUX_PANE' +0:Repeats of vim-sync-incarg work in pane 2 +>BUFFER: echo 4 +>CURSOR: 5 + %clean zmodload -ui zsh/zpty base-commit: 69c58874611a586c68be14ce7965029dc00f41b7