How does $TM_CURRENT_WORD operate in Sublime Text? - sublimetext

In the Sublime Text documents, I see the following definition for TM_CURRENT_WORD
$TM_CURRENT_WORD Current word under the cursor when the snippet was triggered.
I'm confused as to how I would use this in practice. Wouldn't the word under the cursor always be the one in the tabTrigger? I'm trying to use this argument to pass in an argument into the Sublime snippet but can't get it to run properly.

This snippet works fine for me:
<snippet>
<content><![CDATA[
Before you insert snippet cursor was in this "$TM_CURRENT_WORD" word.${0}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>word</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>text</scope>
</snippet>
there you can find very interesting example:
<snippet>
<content><![CDATA[ = $TM_CURRENT_WORD + 1]]></content>
<tabTrigger>++</tabTrigger>
<description>i = i + 1</description>
<scope>source.fortran</scope>
</snippet>

Related

Thymeleaf custom dialect - nested attributes

I would like to ask if it is possible to have nested attributes in HTML tag which can reuse result of previous one. For example
<p custom:one="some text to process" custom:two="process result of custom:one">
where custom:one can be used standalone but custom:two have to be used with custom:one. The final result will be produced by custom:two
if I got you right, you can do it with local variables
You need to specify th:with to declare a variable.
Note that the declared variable is available within the element.
<div th:with="newValue = 'Hello ' + ${val}">
<span th:text="${val}">One</span>
<span th:text="${newValue}>Two</span>
</div>
Let me know if that's what you're looking for.

How to Find replace in HTML using VBS

I've got many HTML files in a folder, for each file I want to replace n-dash and m-dash with linefeed or paragrah mark, but only for specific html class.
For example, I would like to find/replace only text in class "Center".
Original:
class=Center <p class="Center">« Sentence1 — Sentence2 – Sentence3</p>
class=Aligned <p class="Aligned">«Other Sentence4 — Other Sentence5 – OtherSentence6«</p>
Desired result:
<p class="Center">« Sentence1 </p><p></p><p> Sentence2 </p><p></p><p> Sentence3«</p>
<p class="Aligned">«Other Sentence4 — Other Sentence5 – OtherSentence6«</p>
So far I'm using this solution by Helen: https://stackoverflow.com/a/1758239/5471234
But implementing this "strText = Replace(strText, "–", "< /p>< p>< /p>< p>")" performs F/R in the whole text.
How can I limit it to class=Center? Any way to use RegEx? and/or html object .innerText to grab only specific class?

Sublime text - snippet with capitalization of param first letter

I want to make snippet for Sublime Text 2 or 3 which will produce the following code:
initial - somename
with upper case - Somename
and somename is text which will be always different.
My draft for this:
<snippet>
<content><![CDATA[
initial - ${2:somename}
with upper case - ${2:somename}
]]></content>
</snippet>
But how can I uppercase only first letter in parameter?
Final variant:
<snippet>
<content><![CDATA[
initial - ${1:somename}
with upper case - ${1/(.+)/\u$1/g}
]]></content>
</snippet>

How to update item's title with Yahoo Pipes?

I use the feed with items like below:
<item xmlns:hhvac="http://hh.ru/spec/hhvac">
<pubDate>2013-02-04T10:13:51.616+04:00</pubDate>
<hhvac:creationTime>2013-02-04T10:13:51.616+04:00</hhvac:creationTime>
<hhvac:vacancyId>6887864</hhvac:vacancyId>
<title>Title</title>
<link>http://example.com/vacancy/6887864</link>
<description>Description</description>
<hhvac:compensationFrom/><hhvac:compensationTo/>
<hhvac:compensationCurrency/>
<hhvac:areaName>New York</hhvac:areaName>
<hhvac:employerId>12345</hhvac:employerId>
<hhvac:employerName>Employer Name</hhvac:employerName>
</item>
I would like to replace item's title with value like Employer Name: Title. Firstly, I've tried just to add Rename method and indicated there (just to test) item.title Rename item.hhvac:employerName, but in results titles became named as 1, 2, 3, 4 etc.
What it wrong with my approach?
Use the Loop module. Then put a String Builder module in the middle of it. Put item.hhvac:employerName in the first field, click plus to get another field, put : in that field, click plus again to get another field, then put item.title in that field
Then put item.title as the value for "Assign results to:" (and check the radio button next to it).

XQuery ancestor axis doesn't work, but explicit XPath does

Consider the following XML snippet:
<doc>
<chapter id="1">
<item>
<para>some text here</para>
</item>
</chapter>
</doc>
In XQuery, I have a function that needs to do some things based on the ancestor chapter of a given "para" element that is passed in as a parameter, as shown in the stripped down example below:
declare function doSomething($para){
let $chapter := $para/ancestor::chapter
return "some stuff"
};
In that example, $chapter keeps coming up empty. However, if I write the function similar to the follwing (i.e., without using the ancestor axis), I get the desired "chapter" element:
declare function doSomething($para){
let $chapter := $para/../..
return "some stuff"
};
The problem is that I cannot use explicit paths as in the latter example because the XMl I will be searching is not guaranteed to have the "chapter" element as a grandparent every time. It may be a great-grandparent or great-great-grandparent, and so on, as shown below:
<doc>
<chapter id="1">
<item>
<subItem>
<para>some text here</para>
</subItem>
</item>
</chapter>
</doc>
Does anyone have an explanation as to why the axis doesn't work, while the explicit XPath does? Also, does anyone have any suggestions on how to solve this problem?
Thank you.
SOLUTION:
The mystery is now solved.
The node in question was re-created in another function, which had the result of stripping it of all of its ancestor information. Unfortunately, the previous developer did not document this wonderful, little function and has cost us all a good deal of time.
So, the ancestor axis worked exactly as it should - it was just being applied to a deceptive node.
I thank all of you for your efforts in answering my questions.
The ancestor axis does work fine. I suspect your problem is namespaces. The example you showed and that I ran (below) has XML without any namespaces. If your XML have a namespace then you would need to provide that in the ancestor XPath, like this: $para/ancestor:foo:chapter where in this case the prefix _foo_ is bound to the correct namespace for the chapter element.
let $doc := <doc>
<chapter id="1">
<item>
<para>some text here</para>
</item>
</chapter>
</doc>
let $para := $doc//para
return $para/ancestor::chapter
RESULT:
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="1">
<item>
<para>some text here</para>
</item>
</chapter>
These things almost always boil down to namespaces! As a daignostic to confirm 100% that namespace are not the issue, can you try:
declare function local:doSomething($para) {
let $chapter := $para/ancestor::*[local-name() = 'chapter']
return $chapter
};
This seems surprising to me; which XQuery implementation are you using? With BaseX, the following query...
declare function local:doSomething($para) {
let $chapter := $para/ancestor::chapter
return $chapter
};
let $xml :=
<doc>
<chapter id="1">
<item>
<para>some text here</para>
</item>
</chapter>
</doc>
return local:doSomething($xml//para)
...returns...
<chapter id="1">
<item>
<para>some text here</para>
</item>
</chapter>
I suspect namespaces too. If $para/../.. works but $para/parent::item/parent::chapter turns up empty, then you know it's a question of namespaces.
Look for an xmlns declaration at the top of your content, e.g.:
<doc xmlns="http://example.com">
...
</doc>
In your XQuery, you then need to bind that namespace to a prefix and use that prefix in your XQuery/XPath expressions, like this:
declare namespace my="http://example.com";
declare function doSomething($para){
let $chapter := $para/ancestor::my:chapter
return "some stuff"
};
What prefix you use doesn't matter. The important thing is that the namespace URI (http://example.com in the above example) matches up.
It makes sense that ../.. selects the element you want, because .. is short for parent::node() which selects the parent node regardless of its name (or namespace). Whereas ancestor::chapter will only select <chapter> elements that are not in a namespace (unless you have declared a default element namespace, which is usually not a good idea in XQuery because it affects both your input and your output).

Resources