zsh-workers
 help / color / mirror / code / Atom feed
* accept-line question
@ 2015-04-01  7:36 Dave Yost
  2015-04-01  8:20 ` Peter Stephenson
  2015-04-02 17:12 ` Dave Yost
  0 siblings, 2 replies; 5+ messages in thread
From: Dave Yost @ 2015-04-01  7:36 UTC (permalink / raw)
  To: zsh-workers

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

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
0 Wed 0:29:58 yost DaveBook ~
239 Z% source accept-line-test.zsh
0 Wed 0:30:03 yost DaveBook ~
240 Z% echo 2
2
0 Wed 0:30:04 yost DaveBook ~
241 Z% 

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% 


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

* Re: accept-line question
  2015-04-01  7:36 accept-line question Dave Yost
@ 2015-04-01  8:20 ` Peter Stephenson
  2015-04-02 17:12 ` Dave Yost
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2015-04-01  8:20 UTC (permalink / raw)
  To: zsh-workers

On Wed, 1 Apr 2015 00:36:32 -0700
Dave Yost <Dave@Yost.com> wrote:
> There must be something more I have to do besides “accept-line”. But what?

(This is a zsh-users, not a zsh-workers, question. Unlike the
completion bugs, which are zsh-workers, not zsh-users question...)

I've read through that several times, and don't really have a clue what
you're trying to do.

accept-line has one purpose: transfer the current contents of the line
editor during editing to where it's going --- usually the main shell,
unless you're in some recursive mode which I don't think you are.  At
that point you leave the editor and its internal state is lost.

Are you trying to stack up input for later use?  For that you need
push-line, which manipulates a stack that's saved over zle sessions.

pws


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

* Re: accept-line question
  2015-04-01  7:36 accept-line question Dave Yost
  2015-04-01  8:20 ` Peter Stephenson
@ 2015-04-02 17:12 ` Dave Yost
  2015-04-03 16:09   ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Dave Yost @ 2015-04-02 17:12 UTC (permalink / raw)
  To: zsh-workers

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

Sorry, that email was flawed. Let me try again.

Below, after sourcing a script, I type ^a then ^b.
The ^a works as expected, but not the ^b

There must be something more I have to do besides “accept-line”. But what?

0 Thu 9:59:38 yost DaveBook ~
206 Z% cat accept-line-test.zsh 
function xxx {
  BUFFER="$1"
  zle -R
  zle accept-line
}

function x1 {
  xxx echo\ 1
}

function x2 {
  xxx echo\ 2
  xxx echo\ 3
}

zle -N x1
zle -N x2

bindkey ^a x1
bindkey ^b x2
0 Thu 9:59:47 yost DaveBook ~
207 Z% source accept-line-test.zsh
0 Thu 9:59:54 yost DaveBook ~
208 Z% echo 1
1
0 Thu 9:59:55 yost DaveBook ~
209 Z% echo 3
3
0 Thu 9:59:59 yost DaveBook ~
210 Z% 

The output I want from ^b is

0 Wed 0:30:03 yost DaveBook ~
240 Z% echo 2
2
0 Wed 0:30:04 yost DaveBook ~
241 Z% echo 3
3
0 Wed 0:30:04 yost DaveBook ~
242 Z% 

Extra credit:

Is there a way to write a function x3 that calls x2, such that I can issue x3 from the command line get the result above instead of the result below?

0 Thu 10:04:32 yost DaveBook ~
216 Z% x2
xxx:zle:3: widgets can only be called when ZLE is active
xxx:zle:3: widgets can only be called when ZLE is active
1 Thu 10:05:55 yost DaveBook ~
217 Z% 

Thanks


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

* Re: accept-line question
  2015-04-02 17:12 ` Dave Yost
@ 2015-04-03 16:09   ` Bart Schaefer
  2015-04-03 17:03     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2015-04-03 16:09 UTC (permalink / raw)
  To: zsh-workers

[How did we end up back on -workers again?]

On Apr 2, 10:12am, Dave Yost wrote:
}
} Extra credit:
} 
} Is there a way to write a function x3 that calls x2, such that I can
} issue x3 from the command line get the result above instead of
}
} xxx:zle:3: widgets can only be called when ZLE is active
} xxx:zle:3: widgets can only be called when ZLE is active

Not as a stand-alone function, no.  There is no way to "queue up" an
accept-line (or any other widget action) from outside ZLE.  You can
put things on the LIFO buffer stack but they are treated as contents
of $BUFFER, not executed as keystrokes.

You can do it with some collusion from zle-line-init:

zle-line-init() {
  local -a queue
  while [[ -n "$BUFFER" ]]
  do
    queue=("$BUFFER" "${(@)queue}")
    BUFFER=
    zle get-line
  done
  for BUFFER in "${(@)queue}"
  do
    zle execute-now
  done
}

zle -N zle-line-init

xxx() {
  if zle
    BUFFER="$1"
    zle execute-now
  else
    print -z "$1"
  fi
}


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

* Re: accept-line question
  2015-04-03 16:09   ` Bart Schaefer
@ 2015-04-03 17:03     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2015-04-03 17:03 UTC (permalink / raw)
  To: zsh-workers

Important note ...

On Apr 3,  9:09am, Bart Schaefer wrote:
}
} zle-line-init() {
}   local -a queue
}   while [[ -n "$BUFFER" ]]
}   do
}     queue=("$BUFFER" "${(@)queue}")
}     BUFFER=
}     zle get-line
}   done
}   for BUFFER in "${(@)queue}"
}   do
}     zle execute-now
}   done
} }

This completely breaks push-line-or-edit and makes the other push-*
widgets significantly less useful.  So don't try the above if you
use those widgets for anything.


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

end of thread, other threads:[~2015-04-03 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-01  7:36 accept-line question Dave Yost
2015-04-01  8:20 ` Peter Stephenson
2015-04-02 17:12 ` Dave Yost
2015-04-03 16:09   ` Bart Schaefer
2015-04-03 17:03     ` Bart Schaefer

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