-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent syntax highlighting for C funcitons in the same stdio.h header #2973
Comments
Why does the code posted here have consistent highlight of |
See also bug filed on Meta-StackOverflow - Why is our highlightjs syntax highlight inconsistent while Code filed with bugs to highlightjs on GitHub is consistent? Also, I don't know how StackOverflow is using |
Ok, there does seem to be a problem here, but the solution isn't 100% clear. If we're going to highlight functions in the stdlib then we should do it consistency, but I'm also not certain what that surface area would be to do this completely. I'm sure the current list was just someones idea of what was "common" vs being at all exhaustive. If we did try for an exhaustive list... should we only cover It may be that we instead need a rule to match general function dispatch (rather than a huge list of all "built-ins") and then a shorter list of "common" keywords just to help our auto-detect decide what is and isn't C code. |
Well, this is where we have had lots of problems on StackOverflow since switching from prettify to highlightjs. I don't know how each do the highlight, but I do understand highlightjs was attempting to be relatively general rather than syntax for everything. But that brings in problems like this. In C there are really only a handful of standard header files. By far the most commonly included is Those alone would cover 90% of the new-user questions I run into on StackOverflow. In each case there are no more than 20 or so function in each. If we could add those a key words (or whatever the correct terminology is for "Highlight This"), that would be a big improvement and cover most to the new user-questions (where consistent highlight is most important -- eliminating the lingering question in their mind of "why is this function this color and the other function from the same header not?") I can use the C-standard an pull out all the function names from each header if that would help. I'm just not sure what to do with them then? Let me know if that would be helpful. |
What was the prior behavior?
I'm not sure what this is saying... one possibly problem here is that C/C++ are a single grammar for us, but that's diverging now... otherwise I don't know how to understand this comment.
A possibility, but please first answer my original question. Why not just highlight all the function invocations the same? (as seen here in VS Code): Doing so we cover all those libraries in one fell swoop. |
Ping. |
Ping. Also tagging to auto-close if there is no future engagement. |
Agreed. Hard-coding standard library functions in the highlighter always seems excessive to me (they’re, in my mind, not quite the same as built-ins), and there are hundreds of them. I’m also fundamentally not convinced of the value of specifically highlighting these functions: semantically they are regular functions, even if the compiler treated them specially (but it generally doesn’t). |
Full list:
@klmr Do any of these stand out to you as deserving of special treatment... what about It's sounding like we should move many of these from |
#3005 steps towards just highlighting all dispatch so we only need a decision on which built_ins might truly be special/unique (for differentiation in the future)... and which are only good for relevance. And if a |
I’m quite opinionated, but for me the answer is a hard no — except, potentially, for reserved identifiers (i.e. everything with double underscore, or starting with underscore + capital letter etc.; i.e. stuff like But I’d like to make the point that this “full list” is currently completely arbitrary. It contains a wild mix of C and C++ names, of functions, macros and types, it only contains a tiny subset of all standard library names, and I can’t discern a pattern of what is and isn’t included. In particular, these aren’t all defined in one particular header file. I would scrap this list. |
I think you forget we must also auto-detect languages. Lists like this are critical to doing so - even if we don't use them for highlighting individual identifiers. I just glanced at that list and to me (with my limiting experience with C/C++) I see a lot of stuff that looks much like C/C++ code, which is exactly the goal. I suppose one could argue keywords might be "enough" to serve this purpose but I always tend to be conservative with changes like this... so to me scraping the list means preserving it but simplifying and using it for relevancy vs highlighting. IE: f0073f2 Now if someone had suggestions for trimming it to ONLY strong C/C++ signals I'd be happy removing 70% of the cruft... I have a feeling some of these (like the ones I mentioned earlier) are much more signal than others like say |
well... C standard for example says that the standard library functions are pretty much builtins; even in absense of |
The full list of keywords for C11/C18 is
|
These (types) should probably all be |
@josh True, I hadn’t considered auto-detection. Can we use identifiers for auto-detection without applying highlighting? And then we obviously need to get this right: neither 1 The only reason that the (intentionally ugly) |
That's what the PR does now.
Yeah, see #3010. Cleaning up C is a whole sep task.
I'm happy for your (or others) help with this. :-)
Re: |
That’s #3005?
I started (by writing some markup tests) yesterday, starting off from the C++ test cases and making them relevant for C. Unfortunately I didn’t get very far yet … |
Yes. The
That's a great start. :) |
Is this not resolve by #3005? |
Inconsistent Syntax Highlight for C functions from stdio.h
On StackOverflow when answering questions, highlightjs fails to apply consistent syntax highlighting to many functions, but this is particularly acute when it applies (or fails to apply) consistent syntax highlighting to functions from the same standard header
stdio.h
For example:The functions
fputs()
andputs()
are highlighted, butfopen()
,fgetc()
andfclose()
all have no highlight applied at all. The is confusing to new programmers wondering why some functions are one color and some are not.This applies to C, but is applicable to C++ as well
Here is the link to the answer: Strncat causes exception
Are you using
highlight
orhighlightAuto
?Sample Code to Reproduce
Expected behavior
All functions, especially from the same standard header
stdio.h
should have consistent highlight applied.The text was updated successfully, but these errors were encountered: