How can I set the character "&" as a trigger for a sublime completions list? - sublimetext

I'm trying to make a .sublime-completions file where all the commands start with "&". The general format for this is:
{
"trigger": "&Command",
"annotation": "basic function",
"contents": "&Command",
"kind": "function",
"details": "Command description"
},
The problem is that the trigger isn't picking up the & symbol so it'll only show after typing the first letter of the command (in this example, it's "C") and outputs an extra "&" symbol.
How can I get the "&" to be included with the trigger? I tried putting \ infront of the & symbol but that didn't work.

Open your preferences (Win/Lin - Preferences → Settings, Mac - Sublime Text → Preferences → Settings) and add the following:
"auto_complete_triggers":
[
{
"characters": "&",
"selector": "source",
}
]
You can add additional scopes to "selector" to make it more specific. For example, if you only want this behavior in Javascript, you could change that line to "selector": "source.js". If you want it in JS and HTML, the value would become "source.js, text.html". To find the full scope at any point in a document, place your cursor and select Tools → Developer → Show Scope Name. The first line describes the document as a whole, and is generally all you need for this rule. However, feel free to make the rule as specific as you want.
You may also want to remove & from the list of word separation characters. This means that when you double-click on a word starting with &, that character is selected along with the rest of the word.
"word_separators": "./\\()\"'-:,.;<>~!##$%^*|+=[]{}`~?"
The settings file needs to be valid JSONC, meaning that comments are allowed, and each setting needs to be separated by a comma ,.

Related

What is the meaning of semantic_escape_chars?

I believe I have done an extensive google for semantic_escape_chars, but i have failed to find what the meaning of that config is. When are semantic_escape_chars used?
The sample configuration says the semantic_escape_chars configuration option is used to specify a string of characters that are used to separate "semantic words". These are words that are seen as a single unit when you perform any actions on them, similar to the concept of words in vim.
This is used by the vi binding actions (SemanticLeft, SemanticRight, SemanticLeftEnd, etc.) which under allow the cursor to be moved semantically based on boundaries specified by semantic_escape_chars.
More concretely, in your alacritty.yml, if you have
selection:
semantic_escape_chars: " ,:;()[]{}"
key_bindings:
- { key: B, mode: Vi|~Search, action: SemanticLeft }
- { key: W, mode: Vi|~Search, action: SemanticRight }
And you enter vi mode (Ctrl+Shift+Space) with the following in your prompt
foo.png bar,baz
Assuming your cursor is at the first character, hitting "w" would take you to the beginning of the next semantic word, which would be the "b" in "bar".
If instead, you included an . in the semantic_escape_chars, pressing "w" would take you to the "o" at the end of "foo" since that is the end of the boundary for that semantic word as it is followed by the semantic escape character ..

Take X Symbols After a Marker and Save to Variable in AppleScript

I'm looking for a way via AppleScript to take 11 symbols after ?v= part in an URL that's in clipboard and save them into a variable. Here's an example of a link:
https://www.youtube.com/watch?v=PxDK95Q5qN0&ab_channel=TheLateShowwithStephenColbert
So I need a little script that would take a link in clipboard, identify 11 symbols after ?v=, take those 11 symbols (PxDK95Q5qN0) from that link and save it into a variable (e.g. extract).
I did find a partial solution here — but that one only works when it's BETWEEN two parts e.g. ?v= and &. The problem with that solution is that many links are short and do not have the last & symbol (e.g. https://www.youtube.com/watch?v=PxDK95Q5qN0)
I'd appreciate any help or pointers here! :]
Whether you set the clipboard to, e.g.,:
set the clipboard to "https://www.youtube.com/watch?v=PxDK95Q5qN0&ab_channel=TheLateShowwithStephenColbert"
Or, e.g.,:
set the clipboard to "https://www.youtube.com/watch?v=PxDK95Q5qNO"
The following example AppleScript code returns the eleven characters after ?v=:
set extract to do shell script ¬
"sed -Ee 's/.*[?]v[=]([a-zA-Z0-9_-]{11}).*/\\1/'<<<" & ¬
(the clipboard as text)'s quoted form
Note that \\?v\\= can be used instead of the [?]v[=] portion of the sed command as in either case the ? and = are treated as regular characters instead of shell special characters.
Additionally, if the number of target characters changes from 11 yet ?v= and & are still in play, as in your examples, then this regex, with explanation shown further below, handles it:
.*[?]v[=]([a-zA-Z0-9_-]+[^&]).*
Notes:
If the 11 target characters contain other than what is shown in the capturing group:
([a-zA-Z0-9_-]{11})
Then modify it as needed.
Using info from https://regex101.com to explain the regex used in the sed command:
The main part of interest is the Capturing Group ([a-zA-Z0-9_-]{11}), as this is what's returned, if it exists directly after ?v= in the URL.
When Capturing Group is: ([a-zA-Z0-9_-]+)
That macsripter link points you in the right direction (though it's a lot of information to digest). As long as you're running 10.6 or later, you can use this routine:
on getTheV(link_text)
set {tid, my text item delimiters} to {my text item delimiters, {"=", "&"}}
set theV to second text item of link_text
set my text item delimiters to tid
return theV
end getTheV
which breaks the link up into text items — split on '=' and '&' — and returns the second item.
Use it like so:
set theV to getTheV("http://...")
Both the links you provided return the correct value.

Need to strip out invalid characters in CSV file

I am generating a CSV file from a Microsoft SQL database that was provided to me, but somehow there are invalid characters in about two dozen places throughout the text (there are many thousands of lines of data). When I open the CSV in my text editor, they display as red, upside-down question marks (there are two of them in the attached screenshot).
When I copy the character and view the "find/replace" dialog in my text editor, I see this:
\x{0D}
...but I have no idea what that means. I need to modify my script that generates the CSV so it strips these characters out, but I don't know how to identify them. My script is written in Classic ASP.
You can also use RegEx to remove unwanted characters:
Set objRegEx = CreateObject(“VBScript.RegExp”)
objRegEx.Global = True
objRegEx.Pattern = “[^A-Za-z]”
strCSV = objRegEx.Replace(strCSV, “”)
This code is from the following article which explains in details what it does:
How Can I Remove All the Non-Alphabetic Characters in a String?
In your case you will want to add some characters to the Pattern:
^[a-zA-Z0-9!##$&()\\-`.+,/\"]*$
You can simply use the Replace function and specify Chr(191) (or "¿" directly):
Replace(yourCSV, Chr(191), "")
or
Replace(yourCSV, "¿", "")
This will remove the character. If you need to replace it with something else, change the last parameter from "" to a different value ("-" for example).
In general, you can use charmap.exe (Character Map) from Run menu, select Arial, find a symbol and copy it to the clipboard. You can then check its value using Asc("¿"), this will return the ASCII code to use with Chr().

Sphinx alias support (substitutions ?)

I'm considering to move my documentation from Doxygen to Sphinx and looking for an alternative for Doxygen alias.
In Doxygen I have an alias that replaces complex command like a table to a more readable format like this (this just an examples and i have more complex and nested ones) :
table_row2{2}=<tr><td align= center>\1</td><td align= center>\2</td></tr>
or
limited_res{1}=The number of supported \1 depends on the specific platform. See the \ref appendixes section"
It can be used in the documentation like this:
...
table_h2{ Resource Name, Value }
table_row2{ MAC Entries , 256}
table_row2{ Ingress Flow , \limited_res { Ingress Flow } }
...
The closest thing I found in Sphinx is substitutions, but I have trouble to get it to work even for simple command substitutions one like below:
.. |H1| replace:: `*****************************************************`
My section
|H1|
H1 either does not compile or just print the '*...*'.
I'm not sure if this is a syntax problem or just can't be done. I trying to avoid remembering which of the */ +/ -/ = means what and name it by the level of the nesting. My memory is not very good this days :)
And the more important problem: substitutions does not seem to accept parameters which I found essential.
Another option I can think about is to write extensions like this, but I hope for a more simple method.
To get the asterisks to appear below "My section", you need to have at least one blank line separating "My section" from "|H1|". White space in Sphinx/docutils has meaning, and the separated content gets interpreted as two paragraphs instead of inline text.
.. |H1| replace:: `*****************************************************`
My section
|H1|
To display the backticks, escape them with the backslash character \.
.. |H1| replace:: \`*****************************************************\`
My section
|H1|
In case you want to insert raw, you may use the raw directive.
EDIT
This creates a section.
My section
==========
A blank line between two paragraphs will generate paragraphs, as noted above.

Is there a way to delete all comments in a file using Notepad++?

Notepad++ obviously recognizes all comments as such. Is there a way to simply delete all?
Edit: Stat-R's bookmark method has helped greatly, not only for removing comments but for conditionally removing lines in general.
For a general file, first of all you need to know the comment operator of the language you are writing the file in. For example, in java script the comment operator is //.
For the following code...
In NP++, you need to
Mark the lines that contains '//'. Make sure the bookmark option is enabled.
Then, choose from NP++ menu Search>Bookmark>Remove Bookmarked lines
EDIT:
Another solution after #Chris Mirno 's suggestion is as follows:
Use regular expression. See the image below. It is self explanatory
To understand it better, refer to these
In the Find & Replace Dialog, put the following regex and adjust the search options as depicted.
/\*.*?\*/
Replace with: (empty)
Select Mode: Regular Expression AND .(dot) matches newline
This should remove all your C style comments spanned across lines.
Star-R and Chris Mirno Answer are also Correct and Good.
But For Line Comment:
//.*?(?=\r?$)
Explanation:
// will be the Starting Position
.*? Will be any character
(?=\r?$) will search to the end of the line (as it is required in line comment)
Note:
But Still check each of the line because for example if your code contains soap format like
//www.w3.org/2001/XMLSchema-instance\x2......");
it will capture this line because the starting is // and it goes to end of the line so watch out for this :)
Warning to all using Stat-R's solution:
This method will remove lines of code if formatted like this:
echo "hello"; //This comment will be detected
Following his method, the entire line will be removed.
Therefore make sure to go through and make these comments, their own line before doing this method.
I have had some luck running a macro for the above. Basically:
search for // (F3)
select to end of line (shift+end)
delete (delete)
Put // into the search dialog by just searching for it once. Then record the three steps in a macro, then play it back until EOF.
The first time I did it I had a problem, but then it worked, not sure what I did differently.
Anton Largiader's answer was the most reliable one, including complex inline comments.
However, it will leave many empty lines, including ones with empty characters (space, tabs...) so I would just add another step to make it almost perfect:
After running the macro, just do:
Edit > Line Operations > Remove Empty Lines
OR
Edit > Line Operations > Remove Empty Lines (Containing Blank Characters)
1st option is good if you wish to remove only really empty lines
2nd options will remove every empty line even containing space etc. so there will be no more actual spacing left between code blocks. 1st option might be the safest with some manual cleanup afterwards.
As someone suggested in another post, the simplest and most reliable is maybe to export the all text in .RTF format using Menu Plugin-->NppExport-->Export to RTF and then:
-Open the newly created file in Word
-Select any part of any comment
-On the top-right side of Word clic Select--> Select all texts with similar formatting
-Remove the selected comments all at once (del or cut if doesn't work)
To remove Powershell comments if someone find it handy:
Removing Comment in a Powershell using Notepad ++
To find just lines beginning with # (and not with # elsewhere in the line).
Notepad++ SEARCH Menu > Find
‘Mark‘ Tab – fill in as below.
Select ‘Mark All’ (clear all marks if used previously).
Regex ^[#}
enter image description here
SEARCH Menu > bookmark > Remove (or do anything on the list with
them)
Clear all marks to reset
You can select no comments just code by doing the following:
Regex ^[^#}
enter image description here
Enter ctrl+shift+K to remove comment

Resources