-
Notifications
You must be signed in to change notification settings - Fork 27
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
Include guard refactors #63
Draft
nbfalcon
wants to merge
14
commits into
Wilfred:master
Choose a base branch
from
nbfalcon:feature/include-guard-refactors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Include guard refactors #63
nbfalcon
wants to merge
14
commits into
Wilfred:master
from
nbfalcon:feature/include-guard-refactors
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Refactor the code to jump to the start of a header skipping comments and whitespace into a separate function, since that is used by 4 functions now.
Refactor `emr-cc-delete-*' to return t if they deleted something. Based on this, `emr-cc-toggle-include-guard' can see if there was an include guard/#pragma once and insert the other.
`emr-cc-include-guard-suffix' can now also be a format string.
`emr-cc-pragma-once-space', which behaves exactly like `emr-cc-include-guard-space' now controls whether there should be a space after the # of `emr-cc-add-pragma-once'. Refactor `emr-cc--include-guard-space' to take a variable instead of using `emr-cc-include-guard-space' directly.
Use `beginning-of-defun' so that a \ continued statement will be handled correctly. Add a docstring.
Refactor the code to `looking-at' the include guards and #pragma once directives into a separate function, since it is needed to delete those directives and to check if they are present (for the context-sensitive refactor menu).
Now a space before the # in include-guard or pragma once directives is properly handled, so `emr-cc-delete-*' will work in such cases. Supporting generating that in `emr-cc-add-*' isn't worth it though, because include guards are at the top-level, so need not be indented.
The attempt to make comment skipping more robust caused a regression, because `beginning-of-defun' also goes to the start of a comment. Use the old `forward-sexp' + `backward-sexp' heuristic instead, even though it fails if a header starts with a delimited statement (e.g. in\\nt). This is pretty obscure though. Finding #endif should not suffer from that problem. Move the code to go the end of the buffer skipping comments into a separate function, even though it is used only once, so that such functions can be close together (`emr-cc--beggining-of-header' and `emr-cc--end-of-header').
Handle the in\\x by temporarily modifying the syntax table to have ?\\ as space.
Use `emr-cc--end-of-header' + `forward-line' for #endif. This way, trailing header comments are not encased in the include guard, which would allow something like "LocalWords: " to not be wrapped.
nbfalcon
changed the title
Include guard refactors
Jan 9, 2021
emr-cc-add-include-guard
: skip trailing comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
include guards" if there are none)
boilerplates, "LocalWords: ")
after
#endif
, spaces after#
, ...)Fixes #62.