Comments (14)
from vim-cpp.
I'm not sure, but removing ^
fixes this syntax.
diff --git a/syntax/c.vim b/syntax/c.vim
index 85042e4..b7dedb3 100644
--- a/syntax/c.vim
+++ b/syntax/c.vim
@@ -388,11 +388,11 @@ if !exists("c_no_if0")
endif
syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
syn match cIncluded display contained "<[^>]*>"
-syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
+syn match cInclude display "\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
"syn match cLineSkip "\\$"
syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti,cBadBlock
-syn region cDefine start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
-syn region cPreProc start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
+syn region cDefine start="\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
+syn region cPreProc start="\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
" Highlight User Labels
syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
from vim-cpp.
I think \s*
at the head of pattern should be removed as well.
from vim-cpp.
right
from vim-cpp.
Since when is putting a comment before #if valid C?
from vim-cpp.
@brammool This should fix it.
diff --git a/syntax/c.vim b/syntax/c.vim
index cc99f67..82148e7 100644
--- a/syntax/c.vim
+++ b/syntax/c.vim
@@ -358,8 +358,8 @@ if !exists("c_no_c99") " ISO C99
endif
" Accept %: for # (C99)
-syn region cPreCondit start="^\s*\zs\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
-syn match cPreConditMatch display "^\s*\zs\(%:\|#\)\s*\(else\|endif\)\>"
+syn region cPreCondit start="\s*\zs\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
+syn match cPreConditMatch display "\s*\zs\(%:\|#\)\s*\(else\|endif\)\>"
if !exists("c_no_if0")
syn cluster cCppOutInGroup contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
syn region cCppOutWrapper start="^\s*\zs\(%:\|#\)\s*if\s\+0\+\s*\($\|//\|/\*\|&\)" end=".\@=\|$" contains=cCppOutIf,cCppOutElse,@NoSpell fold
from vim-cpp.
@brammool or, do you ask me why need this change?
from vim-cpp.
@brammool Ah, I understanded it just now. vim/vim#1257 (comment)
from vim-cpp.
I rebased this repository. And reverted 8976dec
So this issue still are remaining.
from vim-cpp.
@brammool: This was likely always valid C/C++, you can check yourself with gcc
or g++
. The requirement seems to be the line needs to be devoid of statements before the preprocessor directive.
(void)0; #ifdef POSIX
#endif
error: stray # in program
(void)0; #ifdef POSIX
^
and an ensuing error about the mismatched #endif
.
from vim-cpp.
from vim-cpp.
@brammool: That was a counterexample, the bug was about this case:
/**/ #ifdef POSIX
#endif
Which isn't highlighted properly by Vim (or GitHub), despite being valid C/C++. There may be any amount of whitespace before a preprocessor directive on a line and comments seem to count as part of this whitespace. This will compile whereas the other example does not.
from vim-cpp.
@brammool: Okay, but C89 comments are properly detected already. It seems like the fix involves relaxing the requirement that the # start the line, and the directive text follow immediately after it.
This one is more of a syntactic oddity but there are other issues open (#43, #49) about syntax highlighting deficiencies that are related to this one. I don't understand Vim enough to fix them, but I can vouch that most of what has been reported are actual things found in many projects.
But that's kind of besides the point - the standard allows such syntax, and the highlighter should, ideally, support it. I understand there will be limitations but this isn't yet trying to parse and understand C/C++.
from vim-cpp.
To fix this, it need the regexp pattern enough to be confusable. And it will take heavy load.
from vim-cpp.
Related Issues (20)
- send patch 2014/05/14 HOT 3
- C++1y binary literals and digit separator HOT 2
- send patch 2014/05/23 HOT 14
- リポジトリ名を cpp-vim から vim-cpp にする? HOT 4
- Add g:cpp_no_cpp14 HOT 2
- Autoindenting still happens in raw string literals HOT 2
- C の #define 文で 0 が現れるとハイライトが壊れる HOT 7
- nullptr_t
- [TODO]separate cppType and cppTypeEx
- Should not highlight "restrict" keyword HOT 1
- C++ syntax highlighting misses certain include directives.
- Cursor jumping after calling ccomplete#Complete() HOT 1
- Wrong coloring in `hi Float` HOT 1
- C++ syntax highlighting misses include directives with space after the octothorpe. HOT 1
- Raw string literals highlighting is broken HOT 5
- Highlight C++11+ attribute specifications HOT 2
- Incorrect highlighting for C++ special identifiers
- [syntax/cpp.vim] Different scientific notation coloring between 'E' and 'e'
- Incorrect highlighting HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-cpp.