zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: accept-line question
Date: Wed, 1 Apr 2015 08:39:46 -0700	[thread overview]
Message-ID: <150401083946.ZM30879@torch.brasslantern.com> (raw)
In-Reply-To: <FF62FDC6-BDD8-4BF3-AD44-F36E834D3B4F@yost.com>

[redirecting to zsh-users as others may find this interesting]

On Apr 1, 12:36am, Dave Yost wrote:
} 
} There must be something more I have to do besides "accept-line". But what?
} 
} I type control-a after sourcing my script, and it doesn't work as I expect.
} 
} 0 Wed 0:29:51 yost DaveBook ~
} 238 Z% cat accept-line-test.zsh
} function x1 {
}   BUFFER="$1"
}   zle -R
}   zle accept-line
} }
} 
} function x2 {
}   x1 echo\ 1
}   x2 echo\ 2
} }
} 
} zle -N xxx
} 
} bindkey ^a xxx

There is something missing here, because "zle -N xxx" creates a widget
that calls the function "xxx", but you don't show a function named that.

Also x2 as shown is calling itself recursively, which will eventually
die of stack overflow.

} The output I want is
} 
} 0 Wed 0:30:03 yost DaveBook ~
} 240 Z% echo 1
} 1
} 0 Wed 0:30:04 yost DaveBook ~
} 241 Z% echo 2
} 2
} 0 Wed 0:30:04 yost DaveBook ~
} 242 Z% 

That's now how it works; accept-line in x1 does not run the command and
then resume ZLE inside the x2 function, and even if it did it would not
reprint the prompt in that way.

All "accept-line" does is assert that the buffer is now in its final
state, so that after ZLE finishes, the regular shell parser should read
that line as the input.  However, ZLE does not finish until the current
active widget has also finished, so if accept-line is run again it can
still change the previously-accepted buffer.

You'd need something like this:

--- 8< ---
execute-now() {
  zle -I
  eval "$BUFFER"
  BUFFER=
  zle -R
}

zle -N execute-now
--- 8< ---

Then replace any "zle accept-line" with "zle execute-now".

However, *that* does not push the buffer onto the history stack, so even
more may be necessary depending on what you intend to accomplish.

-- 
Barton E. Schaefer


       reply	other threads:[~2015-04-01 15:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <FF62FDC6-BDD8-4BF3-AD44-F36E834D3B4F@yost.com>
2015-04-01 15:39 ` Bart Schaefer [this message]
     [not found] ` <E00A4521-8A4E-486C-BB2E-5D8D80639156@yost.com>
2015-04-02 20:58   ` Mikael Magnusson
2015-04-02 21:30     ` Bart Schaefer
2015-04-02 21:50   ` Dave Yost
2015-04-02 22:40     ` Bart Schaefer
2015-04-02 23:19       ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150401083946.ZM30879@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).