Closed Error7Studios closed 2 years ago
Would regex support in the search-and-replace tool work too? That would be a more general-purpose solution than a magic button that does everything.
If you accidentally replace '#' instead of '# ', '#//', etc., you just deleted all forms of comments. And you may not notice it until it's too late to undo.
Also, I don't want to do (Replace: \n\n
With: \n
) 10 times to remove big sections of blank space.
It may work, but I think the regex to make sure you're not deleting something inside a multiline string would be pretty complex.
Should the user be expected to know how to type advanced regex to handle that case? It would also delete strings that start with '#' unless they check for that with the regex.
Doesn't seem worth it to just use regex.
When I have a section of code that I want to change, I often:
- Copy the section of code
- Comment it out
- Paste it below the original commented-out version
- Test changes until stable
- Delete the old commented-out code
You may want to look into using version control instead. This way, you can display staged/unstaged changes and pick stuff from old revisions if you need it.
(You can use Git without pushing your project to any remote service.)
I don't know how I feel about this. The difference between #
and #
is very small; most projects contain both styles due to small typos that aren't worth fixing. This proposal would then make these small typos into extremely important syntax that controls where a comment will be deleted or not.
I would prefer if it was really, really hard to opt-in. Something like ###
would still mistakenly delete people's stylized comment blocks. Maybe, instead of deleting lines based on a specific string, you could use a tool in the script editor to explicitly mark what will and won't be deleted.
Still, I don't think I would use this that much. I don't think the added complexity will be worth the time saved clicking and dragging to delete sections of code. I also think it's too prone to mistakes right now, and that a delete-tool based solution would be too complicated.
You may want to look into using version control instead
I could use version control for this, but I like having the commented line(s) right there for direct comparison, instead of just changing it and then checking the diff later if I need to revert.
I also think it's too prone to mistakes right now
What about adding a secondary comment symbol and shortcut?
For example, pressing Control+Shift+Alt+K
could toggle the line as a temporary comment, prefixed by some character combination the user would never accidentally type, like #!|
.
Then, there would just be a single option to remove only the temporary comments, so that all other comments would be safe.
@Error7Studios I don't know of any editor/IDE that has a "temporary comment" feature built-in. I'm kind of wary about implementing features that have no prior art in other IDEs, as it will most likely only be used sparsely by people.
If it does come to pass, from that conversation, that doc-comments end up with a distinct syntax compared to regular comments (for example, as was suggested in https://github.com/godotengine/godot-proposals/issues/993#issuecomment-645097039), then it would be fairly simple to have a quick utility to auto-remove all comments which are not doc-comments, since the language would already be distinguishing between which is which.
Closing due to lack of support (see the above comments and reactions on OP).
Describe the project you are working on: (N/A) (Applies to any project)
Describe the problem or limitation you are having in your project: When I have a section of code that I want to change, I often: 1) Copy the section of code 2) Comment it out 3) Paste it below the original commented-out version 4) Test changes until stable 5) Delete the old commented-out code
However, after doing this a lot, I end up with a lot of commented lines which I need to remove. Previously, I had been doing this by: 1) Trimming the trailing whitespace from the script I want to clean 2) Copy/pasting it into Notepad++ 3) Removing all lines beginning with '#' 4) Pasting the cleaned up code back into my project.
This does the job, but it's tedious, and actually dangerous because it removes ALL comments, even those you may wish to keep for documentation. It also deletes multiline string lines that begin with '#'
Describe the feature / enhancement and how it helps to overcome the problem or limitation: I created a simple script which handles all of this for you. It also has these additional features: 1) Replaces consecutive blank lines with X number of blank lines (0, 1, 2, etc.) 2) Allows for defining custom symbols to indicate commented lines which should be preserved (#//, etc.) 3) Preserves custom multi-line comments (#/ ... #/) 4) Preserves comments inside strings (single or multi-line strings) 5) Preserves spaced comments by default("# ")
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: (code provided below) Currently, this code works by dragging and dropping the script to be cleaned onto an export variable of the tool node containing this script.
The cleaned-up code is copied to the OS clipboard, and the user then simply replaces the old code with the new code (Ctrl+A, Ctrl+V)
If this enhancement will not be used often, can it be worked around with a few lines of script?: I think people would use this a lot. I certainly do.
Is there a reason why this should be core and not an add-on in the asset library?: This could help speed up people's workflow, and also automatically reduces the number of blank lines, which makes it easier to see more of the code on the screen at once.
If this was a built-in shortcut in the script editor, it would be even quicker/easier to do than using a tool node to handle this.
Note: While I put in checks to make this code as safe as I could, it is not without risk. The user should be responsible for backing up their code before using this tool. Being built into the editor should allow undo functionality if they made a mistake.
Working Example: (Before)
(After, with
max_blank_lines
set to 1)Code: