zsh-workers
 help / color / mirror / code / Atom feed
* zle-line-finish behavior and documentation
@ 2016-01-14 14:56 Vincent Lefevre
  2016-01-15  2:22 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Lefevre @ 2016-01-14 14:56 UTC (permalink / raw)
  To: zsh-workers

The zsh man pages say:

  zle-line-finish
    This is similar to zle-line-init but is executed every time the
    line editor has finished reading a line of input.

but this is not very clear. If the command line is aborted with Ctrl-C,
zle-line-finish is not executed. According to past discussions, it
seems to be the expected behavior, but the documentation is not clear
on what "has finished reading a line of input" means exactly.

BTW, is there something similar executed when the command line is
aborted?

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


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

* Re: zle-line-finish behavior and documentation
  2016-01-14 14:56 zle-line-finish behavior and documentation Vincent Lefevre
@ 2016-01-15  2:22 ` Bart Schaefer
  2016-01-21 12:46   ` Vincent Lefevre
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2016-01-15  2:22 UTC (permalink / raw)
  To: zsh-workers

On Jan 14,  3:56pm, Vincent Lefevre wrote:
}
} BTW, is there something similar executed when the command line is
} aborted?

There's not.  All you can do is test [[ -n $ZLE_LINE_ABORTED ]] when
you get back to zle-line-init.


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

* Re: zle-line-finish behavior and documentation
  2016-01-15  2:22 ` Bart Schaefer
@ 2016-01-21 12:46   ` Vincent Lefevre
  2016-01-21 19:04     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Lefevre @ 2016-01-21 12:46 UTC (permalink / raw)
  To: zsh-workers

On 2016-01-14 18:22:56 -0800, Bart Schaefer wrote:
> On Jan 14,  3:56pm, Vincent Lefevre wrote:
> }
> } BTW, is there something similar executed when the command line is
> } aborted?
> 
> There's not.  All you can do is test [[ -n $ZLE_LINE_ABORTED ]] when
> you get back to zle-line-init.

OK, but if the goal is to reset the previous prompt, that's too late.
There would also be other two problems:
1) $ZLE_LINE_ABORTED gets empty when one does Ctrl-C on an empty line.
2) $ZLE_LINE_ABORTED is not reset when a command line is not aborted.

FYI, I currently have:

  zle reset-prompt

in zle-line-finish() to update the time. However that's mainly useful
to have the correct time when I started some command. After doing
Ctrl-C on the command line, this is less useful.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


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

* Re: zle-line-finish behavior and documentation
  2016-01-21 12:46   ` Vincent Lefevre
@ 2016-01-21 19:04     ` Bart Schaefer
  2016-01-22  1:32       ` Vincent Lefevre
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2016-01-21 19:04 UTC (permalink / raw)
  To: zsh-workers

On Jan 21,  1:46pm, Vincent Lefevre wrote:
}
} OK, but if the goal is to reset the previous prompt, that's too late.

I guess the assumption was that if you're aborting the line there's no
reason to update the previous prompt.

} There would also be other two problems:
} 1) $ZLE_LINE_ABORTED gets empty when one does Ctrl-C on an empty line.
} 2) $ZLE_LINE_ABORTED is not reset when a command line is not aborted.

Hmm.  I think it *should* work to do e.g. this:

  zle-line-init() {
    (( $+ZLE_LINE_ABORTED )) && RPS1=ABORT || unset RPS1
    unset ZLE_LINE_ABORTED
    zle reset-prompt
  }

And indeed ZLE_LINE_ABORTED is set-but-emtpy after an interrupt on a blank
command line, and is unset after an accept-line.  For some reason, though,
reset-prompt doesn't redraw the right prompt until the second consecutive
interrupt.

The PS1 prompt does get updated on reset-prompt, it works with:

  PS1="%1v$PS1"
  zle-line-init () {
    (( $+ZLE_LINE_ABORTED )) && psvar[1]='ABORT ' || psvar[1]=''
    unset ZLE_LINE_ABORTED
    zle reset-prompt
  }


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

* Re: zle-line-finish behavior and documentation
  2016-01-21 19:04     ` Bart Schaefer
@ 2016-01-22  1:32       ` Vincent Lefevre
  0 siblings, 0 replies; 5+ messages in thread
From: Vincent Lefevre @ 2016-01-22  1:32 UTC (permalink / raw)
  To: zsh-workers

On 2016-01-21 11:04:49 -0800, Bart Schaefer wrote:
> The PS1 prompt does get updated on reset-prompt, it works with:
> 
>   PS1="%1v$PS1"
>   zle-line-init () {
>     (( $+ZLE_LINE_ABORTED )) && psvar[1]='ABORT ' || psvar[1]=''
>     unset ZLE_LINE_ABORTED
>     zle reset-prompt
>   }

Thanks. It works also together with my previous code related to the
exit status. My code now has:

precmd()
{
  psvar[1]=$?
  if [[ $psvar[1] -gt 128 ]] then
    local sig=$signals[$(($psvar[1]-127))]
    [[ -n $sig ]] && psvar[1]=$sig
  fi
  [...]
}

zle-line-init()
{
  [...]
  (( $+ZLE_LINE_ABORTED )) && psvar[1]+=!
  unset ZLE_LINE_ABORTED
  zle reset-prompt
}

zle-line-finish()
{
  zle reset-prompt
}

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


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

end of thread, other threads:[~2016-01-22  1:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-14 14:56 zle-line-finish behavior and documentation Vincent Lefevre
2016-01-15  2:22 ` Bart Schaefer
2016-01-21 12:46   ` Vincent Lefevre
2016-01-21 19:04     ` Bart Schaefer
2016-01-22  1:32       ` Vincent Lefevre

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