I found an odd bug in the MultiMarkDown list sibling generation:
It will strip out any number preceded by a "$" after I hit enter at the end of the line.
EXAMPLE: - Here is a number (1234) and here are some a dollar amounts ($123), ($123.00), (-$123). - Here is a number (1234) and here are some a dollar amounts (), (. 00), (-).
I think the problem lies in this line:
# Strip Marker $old_line =~ s/^\s*((*|+|-|\d+.)\s*)//;
...but I'm still new to Perl and Regex
---- Brian H binarynomad@gmail.com http://www.binarynomad.com
On 12 Mar 2008, at 19:12, Brian H wrote:
I found an odd bug in the MultiMarkDown list sibling generation:
It will strip out any number preceded by a "$" after I hit enter at the end of the line.
EXAMPLE:
- Here is a number (1234) and here are some a dollar amounts ($123),
($123.00), (-$123).
- Here is a number (1234) and here are some a dollar amounts (), (.
00), (-).
I think the problem lies in this line:
# Strip Marker $old_line =~ s/^\s*((*|+|-|\d+.)\s*)//;
...but I'm still new to Perl and Regex
It sounds more like lack of snippet-escaping in the output.
But I cannot reproduce this, Are you using the default (out of the box) MultiMarkdown support, or the bundle by Fletcher?
Sorry for the delay - I was traveling...
The problem does occur with my bundle - not sure about with the default Markdown bundle.
It appears to be that TextMate is interpreting the '$' as a variable indicator, since the output is inserted as a snippet..
This should fix the problem - change the "List - New Sibling" command to:
#!/usr/bin/env perl
$line = $ENV{'TM_CURRENT_LINE'};
# If a list item contains '$' it gets treated as a variable by TextMate # This fixes that problem
$add_to_index = 0; while ($line =~ s/(?<!\)$/\$/m) { $add_to_index++; }
$old_line = $line; $original = $old_line;
if ($ENV{'TM_MARKDOWN_LONG_LIST'} =~ /^y(e|es)?$/i) { $newline = "\n\n"; } else { $newline = "\n"; }
# Strip Marker $old_line =~ s/^\s*((*|+|-|\d+.)\s*)//;
if ($old_line !~ /^\s*$/) { # The item was not empty if ($line =~ s/^(\s*(*|+|-|\d+.)\s*).*/$1/) { # Line was a list item $line =~ s{ (\d+) }{ $1+1; }ex; } else { # Not list item, perhaps a run-on item? $line = ""; }
$index = $ENV{'TM_LINE_INDEX'}; $index = $index + $add_to_index; $original =~ s/^(.{$index})/$1$newline$line$0/;
$original =~ s/`/\`/g; print $original;# . "\n" . $line . "$0"; } else { # The item was empty, so end the list print "\n"; }
Let me know if this works, and I will release an updated version. Thanks!!
Fletcher
On Mar 15, 2008, at 5:40 AM, Allan Odgaard wrote:
On 12 Mar 2008, at 19:12, Brian H wrote:
I found an odd bug in the MultiMarkDown list sibling generation:
It will strip out any number preceded by a "$" after I hit enter at the end of the line.
EXAMPLE:
- Here is a number (1234) and here are some a dollar amounts
($123), ($123.00), (-$123).
- Here is a number (1234) and here are some a dollar amounts (), (.
00), (-).
I think the problem lies in this line:
# Strip Marker $old_line =~ s/^\s*((*|+|-|\d+.)\s*)//;
...but I'm still new to Perl and Regex
It sounds more like lack of snippet-escaping in the output.
But I cannot reproduce this, Are you using the default (out of the box) MultiMarkdown support, or the bundle by Fletcher?
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 16 Mar 2008, at 00:44, Fletcher T. Penney wrote:
[...] It appears to be that TextMate is interpreting the '$' as a variable indicator, since the output is inserted as a snippet..
[...] $add_to_index = 0; while ($line =~ s/(?<!\)$/\$/m) { $add_to_index++; }
You want to escape $, `, and \ (all three are interpreted when inserting as snippet).
So probably this regexp subst. is more appropriate:
s/(?=[$`\])/\/
On 16 Mar 2008, at 03:35, Allan Odgaard wrote:
[...] So probably this regexp subst. is more appropriate:
s/(?=[$`\])/\/
Actually, that was crafted as a global subst. and not iteratively run on the line, as your code did.
Probably would be best to just count matches (for your $add_to_index) and then run this subst. with /g (and it seems for perl, you need to escape $ even when inside a character class).
I decided just to rewrite the whole command, to make it easier to fix and maintain in the future. But when I used your substitution, it didn't seem to fix anything with the '$' problem:
#!/usr/bin/env perl
# get current line, and break into what is left and right of caret
$line = $ENV{'TM_CURRENT_LINE'};
$index = $ENV{'TM_LINE_INDEX'}; $line =~ /^(.{$index})(.*)$/; $left = $1; $right = $2;
# Escape special characters since we will paste as snippet $left =~ s/(?=[$`\])/\/g; $right =~ s/(?=[$`\])/\/g;
$left =~ s/(?<!\)$/\$/m;
# Print out left and right sides to see how it's working so far (routine is not finished yet) print "$left\n\n$right\n";
If I leave out the "$left =~ s/(?<!\)$/\$/m;" line (my original substitution, it doesn't work. When I add it back, it does.
What am I doing wrong here?
F-
On Mar 15, 2008, at 10:59 PM, Allan Odgaard wrote:
On 16 Mar 2008, at 03:35, Allan Odgaard wrote:
[...] So probably this regexp subst. is more appropriate:
s/(?=[$`\])/\/
Actually, that was crafted as a global subst. and not iteratively run on the line, as your code did.
Probably would be best to just count matches (for your $add_to_index) and then run this subst. with /g (and it seems for perl, you need to escape $ even when inside a character class).
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 16 Mar 2008, at 13:33, Fletcher T. Penney wrote:
I decided just to rewrite the whole command, to make it easier to fix and maintain in the future. But when I used your substitution, it didn't seem to fix anything with the '$' problem: [...]
Yeah, the regexp subst. should have been s/(?=[$`\])/\/g (escaping the dollar for unknown reasons).
OK, I think the following works. Anyone who uses the MMD bundle, please try it out in various circumstances. My testing indicates that it works, but I may have missed something.
If I don't hear of any bugs, I'll update the bundle on my web site....
Replace the command for "List - New Sibling" with:
#!/usr/bin/env perl
# New, cleaned up, improved list sibling command # Thanks to Allan Odgaard and Brian H for finding and # helping to fix problem with special characters in list items
# get current line, and break into what is left and right of caret
$line = $ENV{'TM_CURRENT_LINE'};
$index = $ENV{'TM_LINE_INDEX'}; $line =~ /^(.{$index})(.*)$/; $left = $1; $right = $2;
# Escape special characters since we will paste as snippet $left =~ s/(?=[$`\])/\/g; $right =~ s/(?=[$`\])/\/g;
# Now, figure out what to paste back
if ($left =~ /^\s*((*|+|-|\d+.)\s*)\S+/) { # We appear to have a list item with content, so create a new sibling $marker = $1; # What was used as a list item marker? # If the marker included a counter, increment it $marker =~ s{ (\d+) }{ $1+1; }ex; print "$left\n$marker$right$0"; } else { # Not a list item with content, so strip marker (if any) and add a newline $left =~ s/^\s*((*|+|-|\d+.)\s*)//; print "$left\n$right$0"; }
On 3/16/08 7:35 AM, in article AD62E4E7-6C10-4B29-9C86-5437902B23EB@fletcherpenney.net, "Fletcher T. Penney" fletcher@fletcherpenney.net wrote:
OK, I think the following works. Anyone who uses the MMD bundle, please try it out in various circumstances. My testing indicates that it works, but I may have missed something.
Sorry for hijacking off of this thread, but I've got a question: since installing the latest MultiMarkdown bundle from Fletcher, I've got *two* MultiMarkdowns in TM, one that appears independently, one that appears hierarchically from Markdown. What should I be doing about this? Thx - m.
The hierarchical one is included in the default Markdown bundle, and may or may not work for you.
Mine is an independent bundle, but builds off of the Markdown syntax included in the default bundle. If installed properly, all the MMD features should work.
The reason I created a separate bundle is that I couldn't get the MMD commands in the default bundle to actually work. I couldn't get PDF generation via LaTeX to work, as well as other things. Since I created MMD, and am pretty familiar with how it works, I took that as a bad sign and created my own bundle that does work for me.
This does create some confusion, and I am open to ways to improve this (either merging the two bundles, or removing the MMD specific stuff from the default Markdown bundle and having them remain distinct.
For what it's worth, I simply remove the MMD language definition from within the default Markdown bundle, and then install my own bundle.
i welcome feedback on ways to improve this.
F-
On Mar 16, 2008, at 11:24 AM, Matt Neuburg wrote:
On 3/16/08 7:35 AM, in article AD62E4E7-6C10-4B29-9C86-5437902B23EB@fletcherpenney.net, "Fletcher T. Penney" fletcher@fletcherpenney.net wrote:
OK, I think the following works. Anyone who uses the MMD bundle, please try it out in various circumstances. My testing indicates that it works, but I may have missed something.
Sorry for hijacking off of this thread, but I've got a question: since installing the latest MultiMarkdown bundle from Fletcher, I've got *two* MultiMarkdowns in TM, one that appears independently, one that appears hierarchically from Markdown. What should I be doing about this? Thx
- m.
-- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! One of the 2007 MacTech Top 25: http://tinyurl.com/2rh4pf AppleScript: the Definitive Guide - Second Edition! http://www.amazon.com/gp/product/0596102119
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Hi Fletcher,
Thanks so much for looking into this bug. I use your bundle on a daily basis and it is wonderful.
I tested the new sibling command and it no longer strips out any of the "$", but now I found that it will not recognize the level of the list item. If I indent a sibling, the new sibling always resets itself back to the beginning (or top level) of the list, I have to keep manually indenting the level of the list items:
PREVIOUS - item1 - item2 - item3 - item4
CURRENT - item1 - item2 - item3 - item4
---- Brian H binarynomad@gmail.com http://www.binarynomad.com
On Mar 16, 2008, at 7:35 AM, Fletcher T. Penney wrote:
OK, I think the following works. Anyone who uses the MMD bundle, please try it out in various circumstances. My testing indicates that it works, but I may have missed something.
If I don't hear of any bugs, I'll update the bundle on my web site....
Replace the command for "List - New Sibling" with:
#!/usr/bin/env perl
# New, cleaned up, improved list sibling command # Thanks to Allan Odgaard and Brian H for finding and # helping to fix problem with special characters in list items
# get current line, and break into what is left and right of caret
$line = $ENV{'TM_CURRENT_LINE'};
$index = $ENV{'TM_LINE_INDEX'}; $line =~ /^(.{$index})(.*)$/; $left = $1; $right = $2;
# Escape special characters since we will paste as snippet $left =~ s/(?=[$`\])/\/g; $right =~ s/(?=[$`\])/\/g;
# Now, figure out what to paste back
if ($left =~ /^\s*((*|+|-|\d+.)\s*)\S+/) { # We appear to have a list item with content, so create a new sibling $marker = $1; # What was used as a list item marker? # If the marker included a counter, increment it $marker =~ s{ (\d+) }{ $1+1; }ex; print "$left\n$marker$right$0"; } else { # Not a list item with content, so strip marker (if any) and add a newline $left =~ s/^\s*((*|+|-|\d+.)\s*)//; print "$left\n$right$0"; }
-- Fletcher T. Penney fletcher@fletcherpenney.net
You're not drunk if you can lie on the floor without holding on.
- Dean Martin
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
See - that's why I ask for more testing... :)
Change the first left parenthesis as included in the following:
# Now, figure out what to paste back
if ($left =~ /^(\s*(*|+|-|\d+.)\s*)\S+/) {
(The first opening parenthesis now includes the first \s*...
That seems to fix the problem
F-
On Mar 16, 2008, at 11:40 AM, Brian H wrote:
Hi Fletcher,
Thanks so much for looking into this bug. I use your bundle on a daily basis and it is wonderful.
I tested the new sibling command and it no longer strips out any of the "$", but now I found that it will not recognize the level of the list item. If I indent a sibling, the new sibling always resets itself back to the beginning (or top level) of the list, I have to keep manually indenting the level of the list items:
PREVIOUS
- item1
- item2
- item3
- item4
CURRENT
- item1
- item2
- item3
- item4