:tearoff command not available in Vim 9.0.1664 for Linux even when exists(':tearoff') == 2

21 views
Skip to first unread message

Tony Mechelynck

unread,
Jun 25, 2023, 4:58:18 AM6/25/23
to Bram Moolenaar, vim_dev
• In Normal gvim with Motif GUI in GUI mode, :echo exists(':tearoff')
gives 0 but menus can be teared off from the menu bar with the mouse
• In the same in Console mode, :echo exists(':tearoff') gives 2
• In Huge gvim with GTK3 GUI (where menus cannot be teared off with
the mouse), :echo exists(':tearoff') gives 2 even in the GUI.
• In all these cases, :tearoff PopUp (or with any other menu name)
gives error "E319: Sorry, the command is not available in this
version."

In my humble opinion, E319 ought never to happen if a prior check with
exists(':command') has given 2.

:help tear-off-menus says that tearoff menus are available with Motif
or GTK2 GUIs but not GTK3 version 3.4 or later and indeed, I can tear
off menus (but only with the mouse) in Motif gvim but not in GTK3
3.24.38.

• Maybe the Motif Vim should evaluate exists(':tearoff') to zero even
when not in GUI mode?
• Maybe the GTK3 GUI with GTK3 3.4 or later should evaluate
exists('tearoff') to zero in all cases?
• Maybe the help for :tearoff (which is in gui_w32.txt) should insist
on the fact that this command applies only to Windows?

• Or, contrariwise, maybe the :tearoff command should be extended to
Motif and GTK2 GUIs, which have tearoff menus (but only by mouse
AFAICT)?


Best regards,
Tony.

Bram Moolenaar

unread,
Jun 26, 2023, 7:31:33 AM6/26/23
to vim...@googlegroups.com, Tony Mechelynck

Tony wrote:

> • In Normal gvim with Motif GUI in GUI mode, :echo exists(':tearoff')
> gives 0 but menus can be teared off from the menu bar with the mouse
> • In the same in Console mode, :echo exists(':tearoff') gives 2
> • In Huge gvim with GTK3 GUI (where menus cannot be teared off with
> the mouse), :echo exists(':tearoff') gives 2 even in the GUI.
> • In all these cases, :tearoff PopUp (or with any other menu name)
> gives error "E319: Sorry, the command is not available in this
> version."
>
> In my humble opinion, E319 ought never to happen if a prior check with
> exists(':command') has given 2.

This is a special case: The command is in the list of supported
commands, but it is only actually implemented for MS-Windows.

> :help tear-off-menus says that tearoff menus are available with Motif
> or GTK2 GUIs but not GTK3 version 3.4 or later and indeed, I can tear
> off menus (but only with the mouse) in Motif gvim but not in GTK3
> 3.24.38.
>
> • Maybe the Motif Vim should evaluate exists(':tearoff') to zero even
> when not in GUI mode?

Having exists() return non-zero for a command that doesn't work is
misleading. However, returning zero also isn't correct, since Vim does
know about the command. Currently the returned values are:

1 for match with start of a command
2 full match with a command
3 matches several user commands

That doesn't leave room for a new value. The best I can think of would
be to return one:

1 for match with start of a command
and full match with command that is
not implemented

Any better ideas?

> • Maybe the GTK3 GUI with GTK3 3.4 or later should evaluate
> exists('tearoff') to zero in all cases?
> • Maybe the help for :tearoff (which is in gui_w32.txt) should insist
> on the fact that this command applies only to Windows?

It won't hurt to state that explicitly.

> • Or, contrariwise, maybe the :tearoff command should be extended to
> Motif and GTK2 GUIs, which have tearoff menus (but only by mouse
> AFAICT)?

I do not know how to do that. Perhaps there is a function for that, I
haven't attempted finding it.

--
Google is kind of like Dr. Who's Tardis; it's weirder on the
inside than on the outside...

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Tony Mechelynck

unread,
Jun 26, 2023, 7:12:03 PM6/26/23
to Bram Moolenaar, vim...@googlegroups.com
On Mon, Jun 26, 2023 at 1:31 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Tony wrote:
>
> > • In Normal gvim with Motif GUI in GUI mode, :echo exists(':tearoff')
> > gives 0 but menus can be teared off from the menu bar with the mouse
> > • In the same in Console mode, :echo exists(':tearoff') gives 2
> > • In Huge gvim with GTK3 GUI (where menus cannot be teared off with
> > the mouse), :echo exists(':tearoff') gives 2 even in the GUI.
> > • In all these cases, :tearoff PopUp (or with any other menu name)
> > gives error "E319: Sorry, the command is not available in this
> > version."
> >
> > In my humble opinion, E319 ought never to happen if a prior check with
> > exists(':command') has given 2.
>
> This is a special case: The command is in the list of supported
> commands, but it is only actually implemented for MS-Windows.
>
> > :help tear-off-menus says that tearoff menus are available with Motif
> > or GTK2 GUIs but not GTK3 version 3.4 or later and indeed, I can tear
> > off menus (but only with the mouse) in Motif gvim but not in GTK3
> > 3.24.38.
> >
> > • Maybe the Motif Vim should evaluate exists(':tearoff') to zero even
> > when not in GUI mode?
>
> Having exists() return non-zero for a command that doesn't work is
> misleading. However, returning zero also isn't correct, since Vim does
> know about the command.

Hm… Vim does know about the command, but it is not implemented in the
current build. Similarly, Vim knows about the +python and +python3
features, and in a Vim built with -python -python3 the expressions
has('python') has('python3') both return 0 (which is what I expected)
but "echo exists(':python') exists(':python3') exists(':pythonx')"
returns 2 0 0 which I find even more misleading. I would have expected
them all to be "undefined" (and therefore zero, as mentioned at
builtin.txt line 2307) whenever they are excluded at compile-time in
the current Vim.

> Currently the returned values are:
>
> 1 for match with start of a command
> 2 full match with a command
> 3 matches several user commands
>
> That doesn't leave room for a new value. The best I can think of would
> be to return one:
>
> 1 for match with start of a command
> and full match with command that is
> not implemented
>
> Any better ideas?

I would have preferred 0 for "unknown, or not included in the current
build" similarly to how has() behaves, but the above is better than
nothing.
>
> > • Maybe the GTK3 GUI with GTK3 3.4 or later should evaluate
> > exists('tearoff') to zero in all cases?
> > • Maybe the help for :tearoff (which is in gui_w32.txt) should insist
> > on the fact that this command applies only to Windows?
>
> It won't hurt to state that explicitly.

OK. Maybe it could have been regarded as "implicit" but me too I
believe that saying it explicitly won't hurt.
>
> > • Or, contrariwise, maybe the :tearoff command should be extended to
> > Motif and GTK2 GUIs, which have tearoff menus (but only by mouse
> > AFAICT)?
>
> I do not know how to do that. Perhaps there is a function for that, I
> haven't attempted finding it.

Well, at least we can tear off menus by mouse (but only in these two
GUIs and only in GUI mode). OK, leave that for "whoever whenever,
low-priority" then.
>
> --
> Google is kind of like Dr. Who's Tardis; it's weirder on the
> inside than on the outside...

Best regards,
Tony.

Bram Moolenaar

unread,
Jun 27, 2023, 11:13:24 AM6/27/23
to vim...@googlegroups.com, Tony Mechelynck
Looking at this again, changing exists() in a way that the returned
value is not very clear is not a good solution. exists() is more for a
runtime check anyway, we have has() for compile time checks. So we can
make has(':tearoff') return 0 or 1, depending on whether the command is
supported or not. And not change exists(). That is backwards
compatible and gives a clear answer.

It might be worth doing this for all Ex commands, when the has()
argument starts with a colon.


--
"After a few years of marriage a man can look right at a woman
without seeing her and a woman can see right through a man
without looking at him."
- Helen Rowland
Reply all
Reply to author
Forward
0 new messages