5

NOTE: This question is a "manual migration" from here: https://superuser.com/q/875751/199803


My Vim syntax highlighter for ft=cpp is prematurely ending some macros mid-line. For example:

highlighting error example

(The italicization may make this example a little hard to understand; the final character in the second line is \.)

This is part of a multi-line macro; note that the transition from blue (the "macro" style) to grey and italicized (the "comment" style) occurs *mid-word.

Does anyone have any ideas what's going on here? I tried googling to see if this was a known issue, but I didn't see anyone stating that they had this particular problem.

I'm using vim-gtk (Vim 7.4) from the Wheezy-Backports repo.


It appears that the macro highlighting style ends as soon as the first 0 is encountered anywhere other than at the start of a token. For instance, the number 0 itself does not end the macro, nor does the word 0DIAGNOSTIC, but DIAGNOSTIC0 does (regardless of what follows the 0).


Since the problem is reproducible even with -N -u NONE (see comments on Ingo Karkat's answer), here's the complete output of vim --version, just in case it's helpful:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 14 2014 15:36:29)
Included patches: 1-488
Modified by [email protected]
Compiled by buildd@
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
+balloon_eval    +float           +mouse_urxvt     -tag_any_white
+browse          +folding         +mouse_xterm     +tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
+clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      +toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con_gui  +lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      +X11
+dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     +xim
+emacs_tags      +mouseshape      -sniff           +xsmp_interact
+eval            +mouse_dec       +startuptime     +xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    +xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12     -g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1     -I/usr/include/tcl8.5  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_LARGEFILE64_SOURCE=1  
Linking: gcc   -L. -Wl,-z,relro -rdynamic -Wl,-export-dynamic -Wl,-E  -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.14/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  -L/usr/lib -ltcl8.5 -ldl -lpthread -lieee -lm -lruby-1.9.1 -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib   

I'm using the SyntaxAttr plugin to get information about the last macro-highlighted character and the first comment-highlighted character.

Last macro character: group: cDefine->PreProc guifg=5(5) guibg=-1(-1) First non-macro character: cCppOut2->Comment guifg=6(6) guibg=-1(-1)


The output of :scriptnames:

1: /usr/share/vim/vim74/menu.vim
2: /usr/share/vim/vim74/autoload/paste.vim
3: /usr/share/vim/vim74/syntax/syntax.vim
4: /usr/share/vim/vim74/syntax/synload.vim
5: /usr/share/vim/vim74/syntax/syncolor.vim
6: /usr/share/vim/vim74/filetype.vim
7: /usr/share/vim/vim74/syntax/cpp.vim
8: /usr/share/vim/vim74/syntax/c.vim
2
  • What is the value of c_no_cformat?
    – user72
    Commented Feb 25, 2015 at 19:39
  • @JoshPetrie It's undefined when I launch with -u -NONE and then turn on syntax. Commented Feb 25, 2015 at 19:56

2 Answers 2

5

cCppOut2 comes from c.vim:

syn region  cCppOut2    contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip

It is contained, and the definition for cDefine is:

syn region  cDefine     start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell

The use of the special ALLBUT value at the start of the contains list means that everything except the listed groups can be contained in cDefine... including cCppOut2.

Prior to October 2nd, 2014, the definition of cCppOut2 was guarded by c_no_cformat existing (which is not the case by default) and thus you could only experience this by setting that option to some value. You can thus fix it by unletting that option (reload the file via :e afterwards).

As of the October 2nd change, however, cCppOut2 is always defined, so this bug will be much more prevalent. This was reported as a bug in c.vim (here).

If your version of vim is built with the October 2nd changes, your options are to:

  • Re-link cCppOut2 to cDefine to "hide" the problem until an official fix makes it in. To do this in .vimrc:

    `hi link cCppOut2 PreProc`
    
  • Attempt the fix yourself, as described below.

It appears that @cStringGroup should be listed in the contains set of the cDefine and cPreProc regions (added at the end, here):

syn region  cDefine     start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell,@cStringGroup
syn region  cPreProc    start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell,@cStringGroup
8
  • I tried :let c_no_cformat = 0; is that what you meant by setting it to false? It apparently had no effect. Commented Feb 25, 2015 at 19:55
  • No, use unlet (per the docs, see :help ft-c-syntax) and then reload the file.
    – user72
    Commented Feb 25, 2015 at 20:01
  • I get "no such variable" (consistent with my previous comment that it's undefined). Commented Feb 25, 2015 at 20:04
  • Well, that's obnoxious. I can definitely reproduce your behavior and then fix it that way, and it's consistent with the vim_dev thread I linked. It's possible your runtime files differ from mine (I'm on Windows, using gVim) in such a way as to also affect the way the syntax file evaluates.
    – user72
    Commented Feb 25, 2015 at 20:08
  • 1
    cCppOut2 comes from c.vim (oddly enough):. Seems legit to have this in C provided that "Cpp" stands for C PreProcessor in this context.
    – xaizek
    Commented Feb 26, 2015 at 10:24
2

This looks like issue 281 and should be fixed with the latest runtime updates. So make sure to update your runtime files and check again.

4
  • This probably explains why I wasn't able to reproduce the issue. Commented Feb 26, 2015 at 10:08
  • 2
    Unfortunately, the version of Vim that's in Debian's wheezy-backports (and will be in jessie) doesn't have the fix for this. I'll upload a fixed version to jessie-backports once jessie is released, but not much else that can be done.
    – jamessan
    Commented Feb 26, 2015 at 15:23
  • Yes, this would be appreciated. Also for bug 774492 which I understand can be very disturbing for people. Commented Feb 26, 2015 at 19:57
  • @ChristianBrabandt The fix for 774492 will make it into Jessie. The syntax highlighting will have to wait for a backport.
    – jamessan
    Commented Apr 2, 2015 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.