Dear regexeperts,
I'm trying to write a snippet for wikimedia for applying bold (wrapping a string in **str**)
I've attached cmd-B to the snippet, and I'd like it to bold the CURRENT_WORD if there is no selection. Sounds like a job for:
**${TM_SELECTED_TEXT:$TM_CURRENT_WORD}**
Works fine for the selected text, but not for the current word, where it returns things like this:
he|re -->cmd-B--> he**here**re
Any pointers, or do I need to be made into a command? (in that case, what use does $TM_CURRENT_WORD have in snippets?
cheerio, tim
On 23.09.2008, at 00:34, Timothy Bates wrote:
I'm trying to write a snippet for wikimedia for applying bold (wrapping a string in **str**)
I've attached cmd-B to the snippet, and I'd like it to bold the CURRENT_WORD if there is no selection. Sounds like a job for:
**${TM_SELECTED_TEXT:$TM_CURRENT_WORD}**
Works fine for the selected text, but not for the current word, where it returns things like this:
he|re -->cmd-B--> he**here**re
Any pointers, or do I need to be made into a command? (in that case, what use does $TM_CURRENT_WORD have in snippets?
TM's snippet system 'only' inserts something. It only replaces something if you invoke it via 'foo' and pressing TAB. Ad hoc I do not know whether one needs $TM_CURRENT_WORD in a snippet but one never knows. In a snippet one could write **${1:${TM_SELECTED_TEXT:text}}**
Or even a command à la:
input: selection or word echo -n "**`cat`**" output: replace selection
if you don't select something in beforehand.
--Hans
Dear all,
Looking some more into this, the new environment variables for italic, bold, and underline markup are imported into commands in the ENV[] array, so that makes building those commands more generic. So far so good.
My roadblock now is that to get the format commands to act as toggles (i.e. they remove or add markup as appropriate), the "word" environment variable should let the formatting though, but it doesn't, (so '*bold*' comes in as 'bold').
Before I reinvent the wheel, does anyone have code to use the "TM_LINE_INDEX" to parse "TM_CURRENT_LINE", extracting the current word plus markers such as "TM_BOLD_MARKER" on either side if present?
My stumbling block is writing a regex to find the "TM_CURRENT_WORD" but only when it is at the "TM_LINE_INDEX" location (to avoid making mistakes when a line contains multiple copies of the current word).
tim
On 23 Sep 2008, at 7:25 AM, Hans-Jörg Bibiko wrote:
On 23.09.2008, at 00:34, Timothy Bates wrote:
I'm trying to write a snippet for wikimedia for applying bold (wrapping a string in **str**)
I've attached cmd-B to the snippet, and I'd like it to bold the CURRENT_WORD if there is no selection. Sounds like a job for:
**${TM_SELECTED_TEXT:$TM_CURRENT_WORD}**
Works fine for the selected text, but not for the current word, where it returns things like this:
he|re -->cmd-B--> he**here**re
Any pointers, or do I need to be made into a command? (in that case, what use does $TM_CURRENT_WORD have in snippets?
TM's snippet system 'only' inserts something. It only replaces something if you invoke it via 'foo' and pressing TAB. Ad hoc I do not know whether one needs $TM_CURRENT_WORD in a snippet but one never knows. In a snippet one could write **${1:${TM_SELECTED_TEXT:text}}**
Or even a command à la:
input: selection or word echo -n "**`cat`**" output: replace selection
if you don't select something in beforehand.
--Hans
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 23/09/2008, at 10:40 PM, Timothy Bates wrote:
Looking some more into this, the new environment variables for italic, bold, and underline markup are imported into commands in the ENV[] array, so that makes building those commands more generic. So far so good.
My roadblock now is that to get the format commands to act as toggles (i.e. they remove or add markup as appropriate), the "word" environment variable should let the formatting though, but it doesn't, (so '*bold*' comes in as 'bold').
Before I reinvent the wheel, does anyone have code to use the "TM_LINE_INDEX" to parse "TM_CURRENT_LINE", extracting the current word plus markers such as "TM_BOLD_MARKER" on either side if present?
My stumbling block is writing a regex to find the "TM_CURRENT_WORD" but only when it is at the "TM_LINE_INDEX" location (to avoid making mistakes when a line contains multiple copies of the current word).
Hi Timothy,
The goal of unified formatting commands is pretty much only that at the moment, a goal.
As you have worked out, this is a tricky problem to crack. I have had several rounds of discussions with Allan and Michael about this which pretty much resulted in us spinning on the problems. The reason for creating the branch was to work through these issues. The point is, the current code is not a solution, only a start.
What is making things harder for you is that I didn't commit everything when I branched, apologies for that.
I just added the Un* commands. These should solve the problem you are seeing. However, you need to make sure your grammar scopes `markup.bold.*` correctly. This scope should be the bolded content as well as the bold markers.
Give that a try and see if that works for you. =
--
LD.
On 23/09/2008, at 10:40 PM, Timothy Bates wrote:
Dear all,
Looking some more into this, the new environment variables for italic, bold, and underline markup are imported into commands in the ENV[] array, so that makes building those commands more generic. So far so good.
My roadblock now is that to get the format commands to act as toggles (i.e. they remove or add markup as appropriate), the "word" environment variable should let the formatting though, but it doesn't, (so '*bold*' comes in as 'bold').
Before I reinvent the wheel, does anyone have code to use the "TM_LINE_INDEX" to parse "TM_CURRENT_LINE", extracting the current word plus markers such as "TM_BOLD_MARKER" on either side if present?
My stumbling block is writing a regex to find the "TM_CURRENT_WORD" but only when it is at the "TM_LINE_INDEX" location (to avoid making mistakes when a line contains multiple copies of the current word).
I had similar issue, and I have used the following ruby code (just for what precede the cursor). The regexp were too complex. The idea is instead of looking for a word (or in my case a string), you can look for delimeters of the string (current word). The code split the current line in 3 parts pre, input and post.
line = " " + ENV['TM_CURRENT_LINE'] cursor = ENV['TM_LINE_INDEX'].to_i
separator = Regexp.new(/[ ][({$})\]/)
if line[0..cursor].reverse.split(separator).empty? or line[0..cursor].reverse.split(separator)[0].empty? input = e_sn(line[cursor..cursor]) else input = line[0..cursor].reverse.split(separator)[0].reverse end
post = e_sn(line[cursor+1..-1]) pre = e_sn(line[1..cursor-input.size])
All the best
Guido
-- Dr Guido Governatori http://www.governatori.net http://www/governatori.net/TextMate http://www.defeasible.org
On 23 Sep 2008, at 00:34, Timothy Bates wrote:
I'm trying to write a snippet for wikimedia for applying bold (wrapping a string in **str**) [...]
Just a FYI we’re going to provide this via a unified system, see:
http://lists.macromates.com/textmate-dev/2008-September/012845.html
On 23.09.2008, at 08:46, Allan Odgaard wrote:
On 23 Sep 2008, at 00:34, Timothy Bates wrote:
I'm trying to write a snippet for wikimedia for applying bold (wrapping a string in **str**) [...]
Just a FYI we’re going to provide this via a unified system, see:
http://lists.macromates.com/textmate-dev/2008-September/012845.html
Would this approach also make sense to provide a boolean negator?
It's quite often the case that one wants negate a boolean value like
-YES to NO or visa versa -TRUE to FALSE or visa versa -true to false or visa versa -T to F or visa versa etc.
according to the chosen langauge grammar.
Cheers,
--Hans
Thank you Allan and Hans! Two questions:
Allan: I added { name = 'TM_BOLD_MARKER'; value = '**'; },
to the shellVariables for my language, and reloaded the bundle,. But taking the key binding off my bold snippet sees cmd-B not inserting the behavior for html (<strong>), the parent scope of wikiMedia. Is that supposed to suppressed for variables found in the shellVariable list?
Also, (as I can't get it operating), does the unified system handle unmarking already marked selections, and grabbing the currentWord when there is no selection?
On 23 Sep 2008, at 8:55 AM, Hans-Jörg Bibiko wrote:
On 23.09.2008, at 08:46, Allan Odgaard wrote:
On 23 Sep 2008, at 00:34, Timothy Bates wrote:
I'm trying to write a snippet for wikimedia for applying bold (wrapping a string in **str**) Just a FYI we’re going to provide this via a unified system, see:
http://lists.macromates.com/textmate-dev/2008-September/012845.html