zsh-workers
 help / color / mirror / code / Atom feed
* Add IGNORE_EOF_ALWAYS option?
@ 2011-09-21  8:07 Nikolai Weibull
  2011-09-21 16:10 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2011-09-21  8:07 UTC (permalink / raw)
  To: Zsh Workers

Hi!

So I’m cooking up this weird set-up where I use ^D for

1. Exiting insert mode in Emacs (running Evil, a Vim emulation layer)
2. Suspending Emacs when in normal mode
3. Exiting insert mode in Zle (running in vi mode)
4. Placing the most recently suspended job in the foreground, if there
is one, otherwise exiting the shell, when in normal mode in Zle

This is set up with

(define-key evil-insert-state-map "\C-d" 'evil-normal-state)
(define-key evil-normal-state-map "\C-d" 'suspend-frame)
bindkey '^D' vi-cmd-mode
bindkey -a '^D' zle/foreground-or-exit

where zle/foreground-or-exit is defined as

emulate -L zsh

if (( $#jobdirs > 0 )); then
  (( $+functions[set-terminal-title-from-command] )) &&
    set-terminal-title-from-command fg
  fg
else
  exit
fi

This works fine except for number 4.  Zsh wants to be helpful and print

zsh: use 'exit' to exit.

when I press ^D when the following conditions hold (Src/Zle/zle_main.c:1290):

1. ^D is bound to a user-defined command
2. The command line is empty
3. No arguments have been given (unclear exactly what this actually means)
4. IGNORE_EOF has been set

The problem is that I don’t want this behavior.  Since IGNORE_EOF
doesn’t actually ignore EOF in all cases, I propose that
IGNORE_EOF_ALWAYS be added that acts exactly like IGNORE_EOF, but will
never print a message and simply invoke the user-defined command.

My current workaround is to add

stty eof undef

to my .zshrc, but that doesn’t feel like an ideal solution.


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

* Re: Add IGNORE_EOF_ALWAYS option?
  2011-09-21  8:07 Add IGNORE_EOF_ALWAYS option? Nikolai Weibull
@ 2011-09-21 16:10 ` Bart Schaefer
  2011-09-21 16:33   ` Nikolai Weibull
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2011-09-21 16:10 UTC (permalink / raw)
  To: Zsh Workers

On Sep 21, 10:07am, Nikolai Weibull wrote:
}
} bindkey -a '^D' zle/foreground-or-exit
} 
} zsh: use 'exit' to exit.
} 
} when I press ^D when the following conditions hold (Src/Zle/zle_main.c:1290):
} 
} 1. ^D is bound to a user-defined command
} 2. The command line is empty
} 3. No arguments have been given (unclear exactly what this actually means)
} 4. IGNORE_EOF has been set
} 
} The problem is that I don't want this behavior.

If you are correct, then (1) would be a bug.  The comment in zle_main.c
explicitly says 

     The rule is that "zle -N" widgets suppress EOF warnings.

And the doc says

     Also, if this option is set and the Zsh Line Editor is used,
     widgets implemented by shell functions can be bound to EOF
     (normally Control-D) without printing the normal warning message.
     This works only for normal widgets, not for completion widgets.

So the behavior you want is the one you are supposed to get; we should
not need another option.

However, I can't make a simple case that reproduces your error.  Have
you defined zle/foreground-or-exit with zle -C rather than zle -N ?

Or perhaps the problem is not where you think it is?

} 3. Exiting insert mode in Zle (running in vi mode)

% bindkey -v
% bindkey '^D' vi-cmd-mode
% ^D
zsh: use 'exit' to exit.

You can easily fix that like this:

silent-vi-cmd-mode() { zle vi-cmd-mode }
zle -N silent-vi-cmd-mode
bindkey -v
bindkey ^D silent-vi-cmd-mode


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

* Re: Add IGNORE_EOF_ALWAYS option?
  2011-09-21 16:10 ` Bart Schaefer
@ 2011-09-21 16:33   ` Nikolai Weibull
  2011-09-21 17:25     ` S. Cowles
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2011-09-21 16:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Workers

On Wed, Sep 21, 2011 at 18:10, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Sep 21, 10:07am, Nikolai Weibull wrote:
> }
> } bindkey -a '^D' zle/foreground-or-exit
> }
> } zsh: use 'exit' to exit.
> }
> } when I press ^D when the following conditions hold (Src/Zle/zle_main.c:1290):
> }
> } 1. ^D is bound to a user-defined command
> } 2. The command line is empty
> } 3. No arguments have been given (unclear exactly what this actually means)
> } 4. IGNORE_EOF has been set
> }
> } The problem is that I don't want this behavior.
>
> If you are correct, then (1) would be a bug.  The comment in zle_main.c
> explicitly says
>
>     The rule is that "zle -N" widgets suppress EOF warnings.
>
> And the doc says
>
>     Also, if this option is set and the Zsh Line Editor is used,
>     widgets implemented by shell functions can be bound to EOF
>     (normally Control-D) without printing the normal warning message.
>     This works only for normal widgets, not for completion widgets.
>
> So the behavior you want is the one you are supposed to get; we should
> not need another option.
>
> However, I can't make a simple case that reproduces your error.  Have
> you defined zle/foreground-or-exit with zle -C rather than zle -N ?
>
> Or perhaps the problem is not where you think it is?
>
> } 3. Exiting insert mode in Zle (running in vi mode)
>
> % bindkey -v
> % bindkey '^D' vi-cmd-mode
> % ^D
> zsh: use 'exit' to exit.
>
> You can easily fix that like this:
>
> silent-vi-cmd-mode() { zle vi-cmd-mode }
> zle -N silent-vi-cmd-mode
> bindkey -v
> bindkey ^D silent-vi-cmd-mode

Wow, I am impressively stupid.  Yes, it was the built-in command that
was making all the noise.  Sorry about that.


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

* Re: Add IGNORE_EOF_ALWAYS option?
  2011-09-21 16:33   ` Nikolai Weibull
@ 2011-09-21 17:25     ` S. Cowles
  0 siblings, 0 replies; 4+ messages in thread
From: S. Cowles @ 2011-09-21 17:25 UTC (permalink / raw)
  To: Zsh Workers

On Wed, 21 Sep 2011, Nikolai Weibull wrote:

> Date: Wed, 21 Sep 2011 09:33:23
> From: Nikolai Weibull <now@bitwi.se>
> To: Bart Schaefer <schaefer@brasslantern.com>
> Cc: Zsh Workers <zsh-workers@zsh.org>
> Subject: Re: Add IGNORE_EOF_ALWAYS option?
> On Wed, Sep 21, 2011 at 18:10, Bart Schaefer <schaefer@brasslantern.com> wrote:
>> On Sep 21, 10:07am, Nikolai Weibull wrote:
>
> Wow, I am impressively stupid.  Yes, it was the built-in command that
> was making all the noise.  Sorry about that.


not noise.  this is worthwhile material.  thank you for the exchange.


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

end of thread, other threads:[~2011-09-21 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-21  8:07 Add IGNORE_EOF_ALWAYS option? Nikolai Weibull
2011-09-21 16:10 ` Bart Schaefer
2011-09-21 16:33   ` Nikolai Weibull
2011-09-21 17:25     ` S. Cowles

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