Determine vim feature size (tiny, small, normal, etc.) in vimscript

105 views
Skip to first unread message

So8res

unread,
Dec 3, 2013, 2:00:43 PM12/3/13
to vim...@googlegroups.com
I would like to, in vimscript, determine whether vim was compiled as 'tiny'.

Specifically, I would like to determine the message history size (20 or 200, according as vim is tiny or larger) in vimscript.

Is there any way I can do this? Is there some feature I can check using has() to see how large the message history is? I browsed through the feature-list help docs and did not see one.

I know that I can check has('+visual') or has('+windows') or some other feature that is in small but not tiny, but this is not quite accurate: It's possible to compile --with-features=tiny --enable-visual --enable-windows.

Tim Chase

unread,
Dec 3, 2013, 2:12:24 PM12/3/13
to vim...@googlegroups.com
On 2013-12-03 11:00, So8res wrote:
> Specifically, I would like to determine the message history size
> (20 or 200, according as vim is tiny or larger) in vimscript.

Am I missing something, or can you just test

if &history > 20
call do_fancy_stuff()
endif

Alternatively, if you want to detect how much a given history
currently has in it, you can use histnr() for the corresponding
history-name to see how many it currently holds.

-tim



Nate Soares

unread,
Dec 3, 2013, 2:13:31 PM12/3/13
to vim...@googlegroups.com
Those are precisely what I was looking for. I didn't know about &history -- it's not referenced in the :message-history docs, which is where I was looking. Thanks!





--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/FfIdmnAPWBs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Nate Soares

unread,
Dec 3, 2013, 2:14:59 PM12/3/13
to vim...@googlegroups.com
Actually, wait -- &history is for *command* history. I'm looking for *message* history. Is there an analogous variable that I can use to query the message history size (which, to my knowledge, depends upon the vim compile featureset)?

Tim Chase

unread,
Dec 3, 2013, 2:18:33 PM12/3/13
to vim...@googlegroups.com, na...@so8r.es
On 2013-12-03 11:13, Nate Soares wrote:
> Those are precisely what I was looking for. I didn't know about
> &history -- it's not referenced in the :message-history docs, which
> is where I was looking. Thanks!

The "&" notation is a way of accessing settings which you can read
about at

:help :let-option

Glad it helps.

-tim



Nate Soares

unread,
Dec 3, 2013, 2:23:12 PM12/3/13
to vim...@googlegroups.com
I know about '&'. The problem is that &history is about command history, not message history: is there a &history analog for messages?



-tim



Christian Brabandt

unread,
Dec 3, 2013, 2:37:47 PM12/3/13
to vim...@googlegroups.com

On Di, 03 Dez 2013, Nate Soares wrote:

> I know about '&'. The problem is that &history is about command history,
> not message history: is there a &history analog for messages?

It doesn't actually matter, as the tiny version won't be able to run any
viml commands, so I guess it is safe to assume a size of 100 then.

Best,
Christian
--
Meine Albernheiten nehme ich selbst nicht wichtiger, als sie es
verdienen. Das ist ihr Gl�ck.
-- Michel Eyquem de Montaigne (Die Essais)

Nate Soares

unread,
Dec 3, 2013, 2:40:14 PM12/3/13
to vim...@googlegroups.com
I don't think that's the case. I can compile --with-features=tiny and then --enable a whole bunch of other features manually, and the message history queue will still be 20 messages. I want a way to determine, in vimscript, what the message history queue size is.


On Tue, Dec 3, 2013 at 11:37 AM, Christian Brabandt <cbl...@256bit.org> wrote:

On Di, 03 Dez 2013, Nate Soares wrote:

> I know about '&'. The problem is that &history is about command history,
> not message history: is there a &history analog for messages?

It doesn't actually matter, as the tiny version won't be able to run any
viml commands, so I guess it is safe to assume a size of 100 then.

Best,
Christian
--
Meine Albernheiten nehme ich selbst nicht wichtiger, als sie es
verdienen. Das ist ihr Glück.

                -- Michel Eyquem de Montaigne (Die Essais)

Christian Brabandt

unread,
Dec 3, 2013, 2:58:04 PM12/3/13
to vim...@googlegroups.com
(please don't top poste)

On Di, 03 Dez 2013, Nate Soares wrote:

> I don't think that's the case.

Yes it is.

> I can compile --with-features=tiny and then
> --enable a whole bunch of other features manually, and the message history
> queue will still be 20 messages. I want a way to determine, in vimscript,
> what the message history queue size is.

Eval feature will only be enabled if you have at least a normal built,
as indicated by :h +eval

See also feature.h in the vim src directory.

Best,
Christian
--
Paris ist offen; Italien wird's auch werden; solang' uns der
Atem bleibt, werden wir den K�nstler in das Weite der Welt und Kunst
und in die Beschr�nktheit seiner selbst weisen.
-- Goethe, Maximen und Reflektionen, Nr. 1358

So8res

unread,
Dec 3, 2013, 3:03:24 PM12/3/13
to vim...@googlegroups.com
>
> Eval feature will only be enabled if you have at least a normal built,
>
> as indicated by :h +eval

If I configure --with-features=tiny --enable-eval, what is the message queue size? I believe it will be 20.

Christian Brabandt

unread,
Dec 3, 2013, 3:09:55 PM12/3/13
to vim...@googlegroups.com

On Di, 03 Dez 2013, So8res wrote:

> If I configure --with-features=tiny --enable-eval, what is the message queue size? I believe it will be 20.

Why don't you try it out or read the source?

#v+ ./configure --with-features=tiny --enable-eval
[....]
configure: WARNING: unrecognized options: --enable-eval
#v-

Besides, I don't think it compiles, even it you manually alter feature.h

Best,
Christian
--
Letzte Worte eines Henkers:
"Das Fallbeil klemmt? Kein Problem, ich schau mal nach"

Nate Soares

unread,
Dec 3, 2013, 3:27:33 PM12/3/13
to vim...@googlegroups.com
./configure --with-features=tiny --enable-pythoninterp is sufficient to get a tiny vim configured with +eval, though this does indeed fail to compile. That said, I'm not confident that there is no possible compiling configuration in which vim is in "tiny" mode and eval is on.

Charles Campbell

unread,
Dec 3, 2013, 3:36:39 PM12/3/13
to vim...@googlegroups.com
Use redir...

fun GetVersion()
redir @a
version
redir END
endfunction
sil call GetVersion()

This function puts the output of :version into register "a".

Regards,
Chip Campbell

Tim Chase

unread,
Dec 3, 2013, 3:40:17 PM12/3/13
to vim...@googlegroups.com, na...@so8r.es
On 2013-12-03 12:27, Nate Soares wrote:
> ./configure --with-features=tiny --enable-pythoninterp is
> sufficient to get a tiny vim configured with +eval, though this
> does indeed fail to compile. That said, I'm not confident that
> there is *no possible* compiling configuration in which vim is in
> "tiny" mode and eval is on.


While hackish, it depends on the particular source I'm looking at,
according to feature.h:

#ifdef FEAT_SMALL
# define FEAT_CMDHIST
#endif

/*
* Message history is fixed at 200 message, 20 for the tiny version.
*/
#ifdef FEAT_SMALL
# define MAX_MSG_HIST_LEN 200
#else
# define MAX_MSG_HIST_LEN 20
#endif

So the MAX_MSG_HIST_LEN is set based on whether FEAT_SMALL has been
defined. Coincidentally, if FEAT_SMALL is set, then FEAT_CMDHIST is
also defined, and if you look in eval.c, you'll see that you can test
for has('cmdline_hist') which is also only defined if FEAT_SMALL is
set. Thus

:echo has('cmdline_hist')?200:20

should be a reliable indicator of message-history size.

-tim



Tony Mechelynck

unread,
Dec 3, 2013, 6:37:19 PM12/3/13
to vim...@googlegroups.com
One problem which invalidates some of the replies given so far, is that
normally _neither_ Small _nor_ Tiny builds have expression evaluation
built in.

This means that an :if statement, up to the corresponding :endif, and
with any :elseif and :else in between, is treated as a nestable comment.
_Both_ the "true" path and the "else" path will be skipped. Any
expression, any :let statement, etc., appearing *outside* the range of
an :if (and also not commented-out by a single double-quote character)
will trigger an error in _both_ Small and Tiny builds.

For instance,

if 1
DoSomething
else
DoNothing
endif

(where :DoSomething and :DoNothing are predefined user-commands) will
never execute :DoNothing, but in _either_ a Small or a Tiny build it
won't execute :DoSomething either: the _whole_ :if statement (including
any :if nested inside it) will be skipped.

(The above is, maybe in somewhat more detailed language, essentially
what is documented at ":help no-eval-feature". See also ":help +eval".)

You can apparently use :redir even in Tiny builds, to save the output of
:version to a register or a file; but you cannot check the result by
means of an :if… You will probably have to do a :substitute on the file
or register (after reading or copying it into a buffer), but even so you
can not even count the number of occurrences of the word "Tiny" (i.e. of
the regexp /\<Tiny\>/ ) since any _counting_ (followed by :if) would
require expression evaluation… I suppose you will have to _assume_ some
featureset, and then write your code in such a way that any smaller
featureset would error out. Ugly, I know; but for the love of me I can't
come out with anything better.


Best regards,
Tony.
--
Yow! Is this sexual intercourse yet?? Is it, huh, is it??

Reply all
Reply to author
Forward
0 new messages