zsh-users
 help / color / mirror / code / Atom feed
* Adding to the history from within a widget
@ 2020-01-02 17:14 Piers Powlesland
  2020-01-03  3:37 ` dana
  0 siblings, 1 reply; 8+ messages in thread
From: Piers Powlesland @ 2020-01-02 17:14 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 461 bytes --]

Hi,

I tried to use "print -s xxxxx" to add entries to the history from within a
widget but it doesn't seem to work, although executing the function not as
a widget does allow me to add entries to the history.

Is there any way to add an entry to the history from within a widget.

For now I have resorted to setting hist_ignore_space and then binding the
function using "bindkey -s" and providing a preceding space, but this feels
a bit hacky.

Thanks,

Piers

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-02 17:14 Adding to the history from within a widget Piers Powlesland
@ 2020-01-03  3:37 ` dana
  2020-01-03 11:03   ` Piers Powlesland
  0 siblings, 1 reply; 8+ messages in thread
From: dana @ 2020-01-03  3:37 UTC (permalink / raw)
  To: Piers Powlesland; +Cc: zsh-users

On 2 Jan 2020, at 11:14, Piers Powlesland <pierspowlesland@gmail.com> wrote:
> I tried to use "print -s xxxxx" to add entries to the history from within a
> widget but it doesn't seem to work, although executing the function not as
> a widget does allow me to add entries to the history.

Maybe i misunderstand, but it seems to work for me:

  % zsh -f
  % foo() { print -s foo test }; zle -N foo; bindkey '^r' foo
  % # Press Ctrl+R
  % fc -l
      1  foo() { print -s foo test }; zle -N foo; bindkey '^r' foo
      2  foo test
  %

What exactly are you doing that's not working?

dana


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-03  3:37 ` dana
@ 2020-01-03 11:03   ` Piers Powlesland
  2020-01-03 23:11     ` dana
  0 siblings, 1 reply; 8+ messages in thread
From: Piers Powlesland @ 2020-01-03 11:03 UTC (permalink / raw)
  To: dana; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1195 bytes --]

Hi Dana,

The example you posted works, and also my widget works if i use 'fc -l' to
view the history after executing it.

What doesn't work for me though is pressing up after executing the widget,
I don't see the entry added with 'print -s'.

If I execute another command in the shell I am then able to see the entry
added with 'print -s' by pressing up twice.

I'm wondering if you experience the same, possibly this has been fixed in
newer versions of zsh?

I'm on - zsh 5.4.2 (x86_64-ubuntu-linux-gnu)

On Fri, Jan 3, 2020 at 3:35 AM dana <dana@dana.is> wrote:

> On 2 Jan 2020, at 11:14, Piers Powlesland <pierspowlesland@gmail.com>
> wrote:
> > I tried to use "print -s xxxxx" to add entries to the history from
> within a
> > widget but it doesn't seem to work, although executing the function not
> as
> > a widget does allow me to add entries to the history.
>
> Maybe i misunderstand, but it seems to work for me:
>
>   % zsh -f
>   % foo() { print -s foo test }; zle -N foo; bindkey '^r' foo
>   % # Press Ctrl+R
>   % fc -l
>       1  foo() { print -s foo test }; zle -N foo; bindkey '^r' foo
>       2  foo test
>   %
>
> What exactly are you doing that's not working?
>
> dana
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-03 11:03   ` Piers Powlesland
@ 2020-01-03 23:11     ` dana
  2020-01-03 23:46       ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: dana @ 2020-01-03 23:11 UTC (permalink / raw)
  To: Piers Powlesland; +Cc: zsh-users

On 3 Jan 2020, at 05:03, Piers Powlesland <pierspowlesland@gmail.com> wrote:
> If I execute another command in the shell I am then able to see the entry
> added with 'print -s' by pressing up twice.
>
> I'm wondering if you experience the same, possibly this has been fixed in
> newer versions of zsh?

It's the same in master. I'm not positive, but i don't think it's possible to
make new history entries actually selectable until the next prompt. You would
have to make your widget run `zle .accept-line` or `zle .send-break` (which
will cause whatever's currently on the line to be accepted or discarded,
respectively)

dana


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-03 23:11     ` dana
@ 2020-01-03 23:46       ` Bart Schaefer
  2020-01-04  0:17         ` Piers Powlesland
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2020-01-03 23:46 UTC (permalink / raw)
  To: dana; +Cc: Piers Powlesland, Zsh Users

On Fri, Jan 3, 2020 at 3:10 PM dana <dana@dana.is> wrote:
>
> On 3 Jan 2020, at 05:03, Piers Powlesland <pierspowlesland@gmail.com> wrote:
> > If I execute another command in the shell I am then able to see the entry
> > added with 'print -s' by pressing up twice.
> >
> > I'm wondering if you experience the same, possibly this has been fixed in
> > newer versions of zsh?
>
> It's the same in master. I'm not positive, but i don't think it's possible to
> make new history entries actually selectable until the next prompt.

That's essentially correct.  Everything that happens from when zle is
initialized to when it exits (on accept-line or send-break) is part of
the current history event, and up-history moves to the previous event.

What's the end result you're trying to achieve by adding to the
history from your widget?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-03 23:46       ` Bart Schaefer
@ 2020-01-04  0:17         ` Piers Powlesland
  2020-01-04  1:41           ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Piers Powlesland @ 2020-01-04  0:17 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: dana, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]

I've bound ctrl+o to open fzf (a fuzzy finder) which is populated with the
output of find and then open the selected file in vim.

I'd like to be able to add the vim command to the history, so that pressing
up lets me re-open the same file in vim.


On Fri, 3 Jan 2020, 23:46 Bart Schaefer, <schaefer@brasslantern.com> wrote:

> On Fri, Jan 3, 2020 at 3:10 PM dana <dana@dana.is> wrote:
> >
> > On 3 Jan 2020, at 05:03, Piers Powlesland <pierspowlesland@gmail.com>
> wrote:
> > > If I execute another command in the shell I am then able to see the
> entry
> > > added with 'print -s' by pressing up twice.
> > >
> > > I'm wondering if you experience the same, possibly this has been fixed
> in
> > > newer versions of zsh?
> >
> > It's the same in master. I'm not positive, but i don't think it's
> possible to
> > make new history entries actually selectable until the next prompt.
>
> That's essentially correct.  Everything that happens from when zle is
> initialized to when it exits (on accept-line or send-break) is part of
> the current history event, and up-history moves to the previous event.
>
> What's the end result you're trying to achieve by adding to the
> history from your widget?
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-04  0:17         ` Piers Powlesland
@ 2020-01-04  1:41           ` Bart Schaefer
  2020-01-06 13:40             ` Piers Powlesland
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2020-01-04  1:41 UTC (permalink / raw)
  To: Piers Powlesland; +Cc: dana, Zsh Users

On Fri, Jan 3, 2020 at 4:17 PM Piers Powlesland
<pierspowlesland@gmail.com> wrote:
>
> I've bound ctrl+o to open fzf (a fuzzy finder) which is populated with the output of find and then open the selected file in vim.
>
> I'd like to be able to add the vim command to the history, so that pressing up lets me re-open the same file in vim.

Then why not just assign the vim command to $BUFFER and zle
accept-line, rather than run vim from inside the widget?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding to the history from within a widget
  2020-01-04  1:41           ` Bart Schaefer
@ 2020-01-06 13:40             ` Piers Powlesland
  0 siblings, 0 replies; 8+ messages in thread
From: Piers Powlesland @ 2020-01-06 13:40 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: dana, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

Hi Bart¸

I'm new to zsh and it's widget sytem so didn't realise I could do that.
That solution seems to work fine.

Thanks!

On Sat, Jan 4, 2020 at 1:41 AM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Fri, Jan 3, 2020 at 4:17 PM Piers Powlesland
> <pierspowlesland@gmail.com> wrote:
> >
> > I've bound ctrl+o to open fzf (a fuzzy finder) which is populated with
> the output of find and then open the selected file in vim.
> >
> > I'd like to be able to add the vim command to the history, so that
> pressing up lets me re-open the same file in vim.
>
> Then why not just assign the vim command to $BUFFER and zle
> accept-line, rather than run vim from inside the widget?
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-01-06 13:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-02 17:14 Adding to the history from within a widget Piers Powlesland
2020-01-03  3:37 ` dana
2020-01-03 11:03   ` Piers Powlesland
2020-01-03 23:11     ` dana
2020-01-03 23:46       ` Bart Schaefer
2020-01-04  0:17         ` Piers Powlesland
2020-01-04  1:41           ` Bart Schaefer
2020-01-06 13:40             ` Piers Powlesland

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