Every time I search for a function inside of hundreds of files, I see so many matches for comments which have no effect in the code.
Can someone limit Sublime Text's search scope to real code, and exclude comments?
I use Sublime Text 3 for developing a C++ program.
I created a Plugin that search for a given string inside a given scope.
The default scope selector is -comment effectively searching outside of comments. The text to search for is taken from the current selection. The results are presented in the drop-down menu
Basically I combined two API methods:
view.find_all(pattern) that searches for a pattern in the given view.
view.match_selector(position, scope_selecor) that check if the given position is inside the given scope.
You could use regex to find patters matching the regex you give.
Design the regex according to match your.
You can give regex by turning on the 'Regular Expression' flag
Example
You can have this regex to match your case if you want to match alone in single line comments.
^(?!\/\/)([^\/\n]*)YOUR_SEARCH_TERM
If you want to match also in multi line comments use this.
^(?!(\/\/|(\/\*(.|\n)*([^\*])(?=\/))))YOUR_SEARCH_TERM
Related
I have a flow that pulls a list of filenames from an Excel file and then looks for them in a folder. Sometimes the filenames have parentheses in them, which causes issues with the search query and it doesn't even look for the file. I'm not sure how to handle the parentheses, but I don't want to remove the parentheses from the filenames (and ergo the search query). I thought about trimming the parentheses from the search query, but I want to make sure the right file is found. Perhaps I just need a way to escape the parentheses? I'm not sure how to do that though.
Here's a picture of the flow section in question:
I tried to find another post on this but after searching for a while I couldn't find anything, so I'm sorry if this has been answered already!
Any help is appreciated!
Edit: I'm going to try replacing any parentheses found with %28/%29 per Expiscornovus' suggestion.
Can you use a different search mode in the settings of your Find Files in Folder action (OneDriveSearch instead of Pattern)?
Ignore my previous suggested encoding. Inputting the Search query with parentheses should work. Look at the example below.
There's a unique, made-up word in a book I am editing. I need to italicize the first three letters of this word every time it occurs.
So far I have determined that GREP styles are my best shot at automatically formatting this word, but I have not been able to create a GREP string that works. Any help would be welcome!
Edit:
I managed to get a working GREP query, but this only works for me in the Find/Change dialog. I believe that these GREP strings need to be written a little differently depending on where they are used in the program...
By the way, the specific word I am looking for is youniverse. I need you to always be italicized.
My current working Find/Change GREP query is:
you(?=niverse)
This is a basic way to get the result I am looking for. Ideally this would be a GREP Style in my main paragraph style so I could procedurally apply this style every time the word occurs
If you need to match the first "Dan" of DankFarrik use this in your GREP search and apply appropriate character style:
(Dan|DankFarrik)
You can also try this one
((Dan)(?=kFarrik))
I'm trying to create a simple macro to render a text item in red in asciidoctor.
The following does not work:
:redtext: [red]#some important text in red that occurs a lot#
{redtext}
or for an even simpler example:
:redcross: [red]#✘#
I am not clear on the rules for what can and cannot be substituted by a macro. The asciidoctor manual has a blank space for macros at present (http://asciidoctor.org/docs/user-manual/#macros). The asciidoc manual (http://www.methods.co.nz/asciidoc/chunked/ch21.html) isn't that clear either but may not apply to asciidoctor anyway.
A related unanswered question is Resuable markup fragments with Asciidoctor.
A related question to that suggests using includes which is overkill for this.
What are the limitations of macros?
What you have defined is not a macro, it's an attribute. (When you use it, it's called an attribute reference).
You can perform substitution eagerly in the definition of an attribute using the inline pass macro. In the target position, it accepts a comma-separated list of substitution names (or substitution letters).
In your case, you can write:
:redtext: pass:q[[red]#some important text in red that occurs a lot#]
The relevant part is:
pass:q[...]
See substitutions in an attribute entry for details.
I think includes work well enough. We have a single glossary.asciidoc file to contain all the re-usable snippets, for example:
tag::redtext[]
[red]#some important text in red that occurs a lot#
end::redtext[]
In index.asciidoc you can add a little helper:
:g: glossary.asciidoc
Then wherever you need this snippet:
include::{g}[tag=redtext]
One thing that constantly annoys me about VS is that when I do a Find or Find all, it looks in comments, strings, and other places. When I'm trying to find a particular bit of code, like and rent, it finds it all over. Is there a way to limit searches just to code?
Not sure if there is a specific setting to ignore comments, but you could do a regex find. For example, assuming you want to find "text", you could use this:
^(?!\s*?//).*?text
Caveats:
Assumes comments start with // as first non-whitespace characters. E.g. C# comment types
Doesn't work for comments at the end of code lines (only comments on their own lines)
Doesn't work with block comments, for example /* comment */
So overall it isn't perfect by any means, but depending how many hits you are getting, it might help to cut them down which can be useful if you have a lot of false positives in one-liner comments
The 'Find All References' function may suit you : it ignores all commented-out code and text in strings. CTRL+K, R is the keyboard shortcut.
(Note that it's designed for going from a specific instance of a search string to all other instances. so if you haven't already found an instance of what you're searching for, you would have to (temporarily) type one in to the editor window, then search. Also it's not available for all languages : I know it works fine for C#, though.)
When I read large open source project, I think the author's comment will be very useful, so I want to search for the keyword in the comment.
I already search the answer on the stackoverflow, I get the method to search the keyword in the // comment.
But things is: it will be a little troublesome when you want to search the multiline comment like /* multiline-comment */ by using regex,
StartOfExpression.*\r?\n.*EndOfExpression and this way seems just work in the two line comment, there are many comments have more than 2 lines.
So, is there a better way to get the keyword in this multi line comment ?
To search in multi line comments try this regex
\/\*[\S\s]*?(yourSearchTerm)[\S\s]*?\*\/