TextMate: Highlight matching tags of caret location - html

Is it possible for TextMate to syntax highlight the opening and closing tags of your current caret location? And I am talking about constantly, not by pressing a key combo.
Furthermore, if it possible, how can I do it? There doesn't seem to be any way that I know of except by using selectors in the theme, but I don't know if selectors can be context-sensitive.

currently, the TextMate language grammar has no concept of cursor position. Therefore, this is not achievable right now.
A workaround that I use is to define macros that select a block of text whose boundaries I define with regular expressions. You have to be handy with regular expressions, but you can make it work.
Essentially, record a new macro (option-command-m), use the find dialog to search for the beginning of the tag. Then, use the find dialog and provide a reg-ex that will match the entire contents you want to select. Press option-command-m again to stop the macro, and then save the macro to a bundle.
An example here:
http://github.com/timcharper/vines.tmbundle/blob/master/Macros/Select%20Tag.tmMacro
Tim

Related

VSCode How do I skip past an automatically generated end </tag>?

Say I were typing
<h2>Show Subject*</h2>
How would I jump to the end of the brackets if my cursor was at the *. Usually I would just arrow key right 4 times or use my mouse to select the next line. I see others on youtube doing this easily.
example: https://youtu.be/PlxWf493en4?t=567
Her cursor instantly jumps to the end of the . My < > also do not highlight as hers does when I autogenerate them.
The magics you're seeing in the linked video are features of Emmet. For example there's Emmet: Go to matching pair, which you can bind to something convenient using the Keyboard Shortcuts dialog (Ctrl-k Ctrl-s). Try Ctrl-Shift-p to bring up the command pallete and then type Emmet to see all of the available commands. I would suggest taking some time to read the docs and discover what functionality is available to you.
What looks like jumping to the outside of the end tag in the video is really just jumping to the end of the line, which is bound by default to the End key. Also useful is word jumping (Ctrl+RightArrow/Ctrl+LeftArrow) and word selection (Ctrl+Shift+RightArrow/Ctrl+Shift+LeftArrow). You might take a look at this wiki article for a fairly comprehensive list of common shortcuts.

PhpStorm shortcut to wrap text with function call

I'm in PhpStorm and I need to select some text, press some shortcut and have that text wrapped in a function call (that I would have defined somewhere in the settings beforehand).
For example:
"Hello World" would become input("Hello World").
$_GET["foo"] would become input($_GET["foo"]).
I don't know if this is even possible, but it could help me save so much time if so.
Applying regex to solve this problem is unfortunately not possible. Manually selecting what I need to wrap isn't an issue.
Will the function name be the same every time or different?
In any case: it can be done this way:
Make a Live Template of "surround template" type with the following content:
$FUN$($SELECTION$)$END$
The $SELECTION$ variable here tells that it's a surround template.
Apply correct Context (where this template can be used)
Give it an abbreviation (name used to locate & invoke it) and brief description.
Here is mine:
NOTE: replace $FUN$ by a fixed function name if the function will always be the same. You can have additional templates with different abbreviations (that will have different hardcoded function names).
To use it:
Make a selection and invoke Code | Surround with... action where you select the right template. On Windows keymap it's Ctrl + Alt + T
In action (NOTE: it's without hardcoding the function name hence me typing the myFunc part):
(HINT: you can select the desired entry in a few keypresses if the name is unique -- just start typing the name in the popup -- the standard Speed Search work here)
P.S. Code | Surround with... can have other (possibly irrelevant for you in this case) entries. To list Live Templates only, use the shortcut for Surround with Live Template... action (Ctrl + Alt + J here on my Windows keymap). You can check the shortcut or change it in the Settings/Preferences | Keymap:
This way the popup menu will be a bit shorter:
Less keypresses:
You may be able to use Macros functionality to record the invoking the popup and selecting the right entry. You can then assign a custom shortcut to that Macros: select the text, hit the shortcut and it will playback the recorded sequence.
Sadly I cannot 100% guarantee that Macros will always work nicely (sometimes/on some setups it can "eat" keypresses).
P.S. It would be much easier if the IDE would support assigning keyboard shortcuts to specific Live Templates .. but it's in the backlog and no ideas on when this might be implemented. Anyway: https://youtrack.jetbrains.com/issue/IDEA-67811 -- watch this ticket (star/vote/comment) to get notified on any progress.
P.S. You can also try Postfix completion. It's good for writing the code and not really suitable for your case (editing small parts of it), but who knows. You will have to make a custom postfix for this -- should not be an issue though.
https://www.jetbrains.com/help/phpstorm/2021.3/auto-completing-code.html#postfix_completion

How to highlight all instances of a string using Chrome's Text Fragments feature?

I recently found out about the new Chrome feature called "Text Fragments" that allows links to point directly to a certain text inside an URL and have it highlighted. For example:
https://www.nytimes.com/#:~:text=Magazine
But if I point to a work that appears multiple times, only the first instance gets highlighted.
Is there any way that I can ask it to highlight all occurrences of a given string?
From what I can tell, the spec only allows for highlighting the first instance found on a page. You can specify multiple strings, but they'll all always match to the first occurrence (as of Chrome 83).
The best I can think of is expanding the matching region such that each occurrence is a unique substring. For instance, on this page one could use something like:
#:~:text=highlight%20all&text=highlighted&text=it%20to%20highlight&text=for%20highlighting
And generate these URLs via javascript.
I found a website where a syntax like [URL]?s[]=MySearchTerm&s[]=MyOtherSearchTerm works:
https://www.ipwiki.de/arbeitnehmererfinderrecht:beschraenkte_inanspruchnahme?s[]=inanspruchnahme&s[]=Arbeitgeber&s[]=Diensterfindung
However, this syntax doesn't seem to work anywhere else, so it's probably not a feature of Chrome but a function of that website.

PhpStorm combine multiple Predefined Live Template functions

I have a project where my files are in "lisp-case" (hyphen delimited) and I would like to use the filename as a variable in a live template, but it must be converted to CamelCase first.
I found out that you can set the expression fileNameWithoutExtension() under "Edit Template Variables" and there is also a function called camelCase() which should be able to turn my filenames into CamelCase. But I cannot figure out how to combine those two. I tried doing camelCase(fileNameWithoutExtension()) but that does not work, unfortunately.
Is it possible to achieve this some other way?
camelCase(fileNameWithoutExtension())
It's a correct syntax.
Is it possible to achieve this some other way?
Please ensure that Skip if defined checkbox is checked for this variable.
If I try to wrap fileNameWithoutExtension() inside camelCase() and press enter to save the entry the window is closed but the change is not saved
It's an IDE bug (https://youtrack.jetbrains.com/issue/IDEA-132965 -- supposed to be fixed in current 2017.1.x version).
In any case: either press Enter before leaving the field ... or click on OK button straight away (you may then reopen this window to do further changes).
Also, when editing the field it's rendered like a select box which is kind of weird. Maybe it's a bug in this specific version. I'm on PhpStorm 10.0.4 for Mac.
Not a Mac user here .. but it is an editable drop-down box indeed (it lists all possible functions).

Is there any way to switch multiple cursors with tab?

The situation is: in my html-file I have a lot of "href" attributes to be filled with specific links. And I can get multiple cursors on every needed place.(via Ctrl+D, or Alt+Enter).
Now it would be very helpful if I could switch between this cursors with tab(like emmet plugin does with self-generated html-content, if you know what I'm talking about).
You can have multi cursor, and switch between them in using :
Ctrl + F3
or
Ctrl + Shift + F3
You can get the behavior I believe you want by selecting all the "href" attributes using ctrl+d. If you are selecting all of them, you cna run the find_all_under command (alt + f3 in windows, unsure of other platforms but you can search for the command). Then, bookmark the cursor positions (ctrl+f2 in windows). You can then use f2 to cycle through the bookmarks. You could bind the appropriate command to tab if you want also, though you would have to do some work do you don't break normal tab behavior.
As a side note, I believe emmet simply inserts a snippet, so it defines various locations for the cursor to jump to through the built in snippet behavior.
#Jahnux solution may be more ideal since you wouldn't have to select initially, but I believe you would have to move the cursor back to the "href" attribute for continuing to the next token.
You may also want to investigate simply using the find functionality, though perhaps you have run into some limitations with that.