Isn't that what the 'term' option is for? My vimrc includes the following:
if (&term == "pcterm") || (&term == "win32")
" if exists("+guicursor")
" Console cursor shape (Windows only)
set guicursor=n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30
set guicursor+=sm:block,a:blinkwait750-blinkoff750-blinkon750
elseif (...)
What is 'term' set to in a "classical" cygwin bash terminal (like I used
to have on XP SP2, when that was still state-of-the-art)? Can you call
SetConsoleCursorInfo() there?
> 2. I believe cygwin vim can be compiled for GUI mode, so the code
> wouldn't work in that case either; should we include a preprocessor
> test to exclude the code if compiling for GUI mode?
In GUI mode you should set 'guicursor' the normal way (allowing vertical
bar in addition to horizontal bar or block), shouldn't you?
> 3. I'm not sure about how much testing needs to be done for a new
> patch (this is the first patch I've ever submitted); I've only tested
> it on one Windows 7 machine.
>
> Any feedback is appreciated.
>
> Thanks,
> Ben
>
Best regards,
Tony.
--
Q: How many IBM cpu's does it take to do a logical right shift?
A: 33. 1 to hold the bits and 32 to push the register.
Well, when I still had a Windows box some time ago, when the latest
Windows OS was XP SP2, I had Cygwin on it, with only one kind of
Unix-like environment, namely a terminal running Cygwin bash, and I
never knew if cmd.exe was "under" it or not. My "usual" cmd.exe box had
nonstandard colours (bright cyan on blue), my Cygwin bash box had the
default light grey on black, and so they were easy to tell apart. And
yes, that's the bash terminal that I meant in my earlier post. I suppose
the "new Cygwin terminal" didn't yet exist back then?
Just make sure you don't test &term before it's set (from $TERM etc.):
this is a case when the order of initializations counts.
>
> +
> + void
> +mch_update_cursor(void)
> +{
> + int idx;
> + int thickness;
> +
> + /*
> + * It's possible to run cygwin vim from various different
> terminals,
> + * however, the cursor shape code only works in the DOS box, i.e.
> when
> + *&term == "cygwin". This is because it uses the Windows API
> function
> + * SetConsoleCursorInfo() to set the cursor shape, which only
> applies
> + * to the DOS box.
> + */
> + char_u* term = 0;
> + get_option_value((char_u *)"term", 0,&term, 0 );
> + if (STRCMP(term, (char_u *)"cygwin" ) != 0)
> + return;
> +
> + /*
> + * How the cursor is drawn depends on the current mode.
> + */
> + idx = get_shape_idx(FALSE);
> +
>
>>> 2. I believe cygwin vim can be compiled for GUI mode, so the code
>>> wouldn't work in that case either; should we include a preprocessor
>>> test to exclude the code if compiling for GUI mode?
>>
>> In GUI mode you should set 'guicursor' the normal way (allowing vertical
>> bar in addition to horizontal bar or block), shouldn't you?
>
> I'm not sure what you mean by setting 'guicursor' the normal way; do
> you mean the cursor is already updated correctly in GUI mode? I
> haven't tried the GUI in cygwin, so I'm not sure. Doesn't that mean we
> should include a preprocessor condition to exclude the new code for
> GUI mode?
I mean that in all flavours of gvim, including Cygwin-X11 GUI, the
'guicursor' option defines a graphical cursor which can be either a full
block, a horizontal bar of selectable height near the bottom, or a
vertical bar of selectable width near the left. I would assume that this
already works. And yes, you should disable the console-cursor code (if
it isn't yet) when running in GUI mode, either at run-time (if a single
Cygwin executable can run in both Console mode or GUI mode, which I
don't expect), or at compile-time (otherwise). Check first if it isn't
already excluded by an outer #ifdef or by not compiling that module in a
GUI build.
Also, IIRC, during gvim startup (when it's known that we're going to
start gvim, has('gui_running') returns true, but we haven't yet (e.g.
we're still sourcing the vimrc), setting 'guicursor' to values typical
of the GUI gives no error even if the new values are invalid in console
mode, they are remembered, and applied when starting the GUI (about when
the GUIEnter event is triggered).
>
>>> 3. I'm not sure about how much testing needs to be done for a new
>>> patch (this is the first patch I've ever submitted); I've only tested
>>> it on one Windows 7 machine.
I suppose that it should be tested as extensively as possible, to ensure
that:
- it works in all Cygwin versions you could lay hands on, in as many
Windows versions as possible;
- it doesn't introduce new bugs in non-Cygwin Windows builds (which you
can test) or in non-Windows builds (meaning Linux and Mac OSX at the
very least, others if possible; here I suppose other people would have
to do the testing)
And of course Bram has the last word on which patches are judged stable
enough to be included in the official Vim code.
>>
>>> Any feedback is appreciated.
>>
>>> Thanks,
>>> Ben
>>
>> Best regards,
>> Tony.
>> --
>> Q: How many IBM cpu's does it take to do a logical right shift?
>> A: 33. 1 to hold the bits and 32 to push the register.
>
> Thanks,
> Ben
>
Best regards,
Tony.
--
Hand, n.:
A singular instrument worn at the end of a human arm and
commonly thrust into somebody's pocket.
-- Ambrose Bierce, "The Devil's Dictionary"
IIUC, to make a gvim "for Cygwin" you need the Cygwin X11 libraries and
development environment, and at least one of the GUI packages (Motif,
GTK, etc.) which can be compiled into gvim. Then to make it run you
first need a Cygwin X11 server. IMHO it is usually not worth the
trouble: a Cygwin console-mode vim, and a vim.exe and gvim.exe for
"native Windows", are usually all one needs.
Under Mac OSX, Bj�rn Winckler maintains the MacVim port, which is a
"flavour" of gvim for current versions of the Mac operating system.
Check the vim_mac list if you're interested.
hm, no, Bram does not maintain experimental branches of the code, except
temporarily when exploring a soon-to-come new point release, and I
haven't yet seen any sign of a 7.4 or 8.0 release of Vim; but you could
upload your patch (in context diff form with Unix line endings) anywhere
convenient, so that any interested tester can have a go at it. I see you
have copied it to the end of your post, but if you can get it a "place
to live" on the web that would be more permanent.
One thing you might also try is compiling a Windows gvim (not for
Cygwin) from your modified source, to check that there's no missing #ifdef
A small nit about that patch: Bram's "house style" indents preprocessor
conditionals by one space per level after the #, as follows:
#ifdef MCH_CURSOR_SHAPE
# if defined(__CYGWIN__) && !defined(FEAT_GUI)
# include <windows.h>
...
# endif /* Cygwin console */
#endif /* MCH_CURSOR_SHAPE */
and avoids C++ comments in C source. I know, most modern compilers
accept both kinds of comments, but there are so many different OSes and
compilers supported by Vim, we have to be particularly "conservative in
what we emit". There's no way we can test them all ourselves, from
VAX/VMS to zOS to smartphone Linux to whatever, so Bram's custom is to
bend over backwards to make the code as compatible as possible, if
necessary by means of a coding style so obsolete that all C compilers
are guaranteed to support it; and (notwithstanding my pejorative
phrasing) I believe that it's the right thing to do.
Best regards,
Tony.
--
There are three ways to get something done: do it yourself, hire
someone, or forbid your kids to do it.