How to know in which patch a feature was added

12 views
Skip to first unread message

Enan Ajmain

unread,
Jun 18, 2023, 1:15:54 PM6/18/23
to vim...@googlegroups.com
In the beginning, I used a simple vimrc, basically ":se nu", etc. Those
features were available in all available Vim installations. Later when
I got into tweaking, I used nightly builds of Vim, so I always had the
latest features. But nowadays I have to work in a few ssh machines,
some of which have slightly older versions of Vim. Which means some of
my settings emit errors.

The proper way to handle this is with ":has()" and ":exists()". For
checking the existence of things like functions, autocommand events,
variables, etc., they work fine. Even for options, I can use exists().
But what about option values? Let's say I want to set 'wildoptions' to
use 'popupmenu'. This was introduced in a late patch of 8.2. The only
way I can include this setting with sanity check is by using ":if
has('patch-8.2.4325')". The problem is: I had to find the patch number
by using "git grep --log=pum".

Is there an easier way to find the patch number where an option was
introduced? Perhaps with ":helpgrep"?

--
Enan

Tony Mechelynck

unread,
Jun 18, 2023, 2:29:59 PM6/18/23
to vim...@googlegroups.com
See
:help version5.txt
:help version6.txt
:help version7.txt
:help version8.txt
:help version9.txt

Each of these begins with a section explaining what was new in version
n.0, then lower down there are a series of sections about versions
n.1, n.2 etc., each containing a series of short paragraphs about each
new patch concerning that section.

I suppose that anything added earlier than version 5.0 can now be
assumed to be "always present". For later features, the simplest is,
as you said, to take advantage, when possible, of the has() and
exists() functions. Only when neither of these gives the clear-cut
result you need, will you have to resort to checking by patch number,
after having searched (possibly with the Normal-mode / command) some
or all of the five helpfiles mentioned above.

Best regards,
Tony.

Salman Halim

unread,
Jun 18, 2023, 2:40:36 PM6/18/23
to Vim Users
This isn't exactly what you asked for, but how about a custom command, such as Set, that calls a function to do the option set in a try/catch? If it succeeds, great. If it fails, you can just ignore it or use an echomsg or something.

You won't know when a feature was introduced, but you also won't have to have existence checks around everything. 

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXsMg_Kk77G785oVt4jXaTFkiUvFWUZ6-4-e5SML08QjGQ%40mail.gmail.com.

Tony Mechelynck

unread,
Jun 18, 2023, 2:41:31 PM6/18/23
to vim...@googlegroups.com
P.S. Beware that has('patch-m.n.p') only works in Vim 7.4.237 or
later. If there is a possibility that you are running an earlier Vim,
the equivalent

if (version > 701 || version == 701 && has('patch103'))

will check for equal or later than patchlevel 7.1.103 including some
builds which would not recognize what has('patch-7.1.103') means. I
use "version" rather than "v:version" because the former is an older
synonym, now deprecated but recognized by older versions of Vim. (Of
course if you run the risk of having to use Vim 8 or even Vim 7 you
won't use Vim 9 language.)

Best regards,
Tony.

Tony Mechelynck

unread,
Jun 18, 2023, 2:55:31 PM6/18/23
to vim...@googlegroups.com
On Sun, Jun 18, 2023 at 8:40 PM Salman Halim <salma...@gmail.com> wrote:
>
> This isn't exactly what you asked for, but how about a custom command, such as Set, that calls a function to do the option set in a try/catch? If it succeeds, great. If it fails, you can just ignore it or use an echomsg or something.
>
> You won't know when a feature was introduced, but you also won't have to have existence checks around everything.
>
> Salman

This would work great… as long as you are certain in advance that the
Vim you're running on has a built-in (and non-buggy) try-catch
feature. This can be checked, of course, with
:if exists(':try') == 2
but I remember a time when that feature (introduced when? At some
point in Vim 7, I think) didn't exist. As a belt-and-suspenders man, I
try to make the fewest possible unsupported assumptions. ;-)

Best regards,
Tony.

Enan Ajmain

unread,
Jun 18, 2023, 3:14:49 PM6/18/23
to Salman Halim, vim...@googlegroups.com
On Sun, 18 Jun 2023 14:40:20 -0400
Salman Halim <salma...@gmail.com> wrote:
> This isn't exactly what you asked for, but how about a custom command, such
> as Set, that calls a function to do the option set in a try/catch? If it
> succeeds, great. If it fails, you can just ignore it or use an echomsg or
> something.
>
> You won't know when a feature was introduced, but you also won't have to
> have existence checks around everything.

Great idea! I learned about try-catch in VimScript only a few days ago.
Don't know why it slipped my mind so soon. Thanks!

I'll set up an user function, as you said, and iteratively replace "set"
with "Set" for the options that I get an error for.

--
Enan

Gary Johnson

unread,
Jun 18, 2023, 3:47:04 PM6/18/23
to vim...@googlegroups.com
If all you care about is avoiding the error message, just use
:silent!, e.g.,

:silent! set wildoptions+=pum

Regards,
Gary

Marius Gedminas

unread,
Jun 19, 2023, 5:00:24 AM6/19/23
to vim...@googlegroups.com
I usually rely on helpful.vim (https://github.com/tweekmonster/helpful.vim)
when I need to find a version because I can't use has()/exists() to
detect a feature. Unfortunately I don't know if it can help with new
option values.

I've used git blame on the help file to roughly find the date, but help
file changes are sometimes committed separately from code changes.

Marius Gedminas
--
Seen on a button at an SF Convention:
Veteran of the Bermuda Triangle Expeditionary Force. 1990-1951.
signature.asc
Reply all
Reply to author
Forward
0 new messages