I take class notes on my laptop in Markdown and organize them in a locally-hosted blog. Last week was the first week I used TextMate instead of BBEdit for this, and I was occassionaly getting an extra level of indentation while typing in code blocks. For example, in one section of my notes I typed this:
| #include<vector> | | vector<int> v; // vector of zero elements | vector<int> v(250); // vector of 250 elements, initialized to zero | vector<time24> t(10); // 10 elements, all set to 00:00
Each line is indented by four spaces (the pipe characters are meant to represent the left margin), which Markdown will wrap in <pre> and <code> tags. I have TM (version 1.5 [906]) set to use soft tabs of 2 characters each.
I found that hitting the Return key after each of these lines (other than the blank one) would put the cursor on the next line with an indentation of 6 spaces instead of 4. This may be a red herring, but the extra indentation seemed to occur only after lines that had an angle-bracked pair, like <xxx>, in them. So in this excerpt
| #include<iostream> | #include<vector> | #include "d_random.h" | using namespace std;
the extra indentation occurred after the first two lines, but not after the second two.
Can anyone tell me why this is happening and what I can do to fix it?
-- Dr. Drang
On Feb 28, 2006, at 9:22 PM, Dr. Drang wrote:
Each line is indented by four spaces (the pipe characters are meant to represent the left margin), which Markdown will wrap in <pre> and <code> tags. I have TM (version 1.5 [906]) set to use soft tabs of 2 characters each.
I found that hitting the Return key after each of these lines (other than the blank one) would put the cursor on the next line with an indentation of 6 spaces instead of 4. This may be a red herring, but the extra indentation seemed to occur only after lines that had an angle-bracked pair, like <xxx>, in them. So in this excerpt
| #include<iostream> | #include<vector> | #include "d_random.h" | using namespace std;
the extra indentation occurred after the first two lines, but not after the second two.
Can anyone tell me why this is happening and what I can do to fix it?
I can explain what is happening and suggest some ideas on how to fix it. The scope for the entire markdown bundle is text.html.markdown This means that it inherits stuff from the html bundle, in general a good thing. In this case, it inherits the indentPattern behavior, that you would see for instance if you type <html> and press enter. This is dictated in the Miscellaneous preferences file in the HTML bundle, by the following code:
increaseIndentPattern = '(?x) (<(?!area|base|br|col|frame|hr|html|img|input|link|meta|param|[^>]*/>) ([A-Za-z0-9]+)\b[^>]*>(?!.*</\2>) |<!--(?!.*-->) |{[^}"'']*$ )';
I think what you have to do is create such a file in the Markdown bundle, with an appropriate increase indent pattern and scope text.html.markdown, and hope that this will override the pattern from html. The problem with that of course is that then the html indenting will not work in markdown. I don't think that there is a simple answer here, in that we do want such indenting in markdown in general, and in fact in code blocks too, since the code blocks might often be html. It just happens to have this weird behavior if your code happens to have what looks like the opening of an html tag.
-- Dr. Drang
Haris
On 2/28/06, Charilaos Skiadas cskiadas@uchicago.edu wrote:
I can explain what is happening and suggest some ideas on how to fix it. The scope for the entire markdown bundle is text.html.markdown This means that it inherits stuff from the html bundle, in general a good thing. In this case, it inherits the indentPattern behavior, that you would see for instance if you type <html> and press enter.
[snip]
I think what you have to do is create such a file in the Markdown bundle, with an appropriate increase indent pattern and scope text.html.markdown, and hope that this will override the pattern from html. The problem with that of course is that then the html indenting will not work in markdown.
I don't think that there is a simple answer here, in that we do want such indenting in markdown in general, and in fact in code blocks too, since the code blocks might often be html. It just happens to have this weird behavior if your code happens to have what looks like the opening of an html tag.
Haris, I hope you're getting paid for the good work you do on this list. You seem to be helping out in every thread.
I haven't thought about this issue before, but I think I'm going to disagree with your last paragraph. Certainly we'd all like indenting in our code blocks, but I don't think HTML code should get special treatment in TM because it doesn't get special treatment in Markdown itself. I suppose I wouldn't mind if this special treatment of HTML were benign, but it isn't: it messes up the input of other types of code.
Should Markdown be inheriting from HTML? My tendency is to say no. Markdown is not a subset or superset of HTML; it is something different. Yes, you can insert HTML directly (outside of a code block) when Markdown itself can't give you what you want, but those insertions are usually very short. I don't think TM's Markdown mode benefits from this inheritance.
-- Dr. Drang
On Mar 1, 2006, at 12:29 AM, Dr. Drang wrote:
I haven't thought about this issue before, but I think I'm going to disagree with your last paragraph. Certainly we'd all like indenting in our code blocks, but I don't think HTML code should get special treatment in TM because it doesn't get special treatment in Markdown itself. I suppose I wouldn't mind if this special treatment of HTML were benign, but it isn't: it messes up the input of other types of code.
I will agree with you that in markup.raw.block.markdown it perhaps should not get special treatment. I don't think that it is easy to disable though, and we do want it to be enabled in the rest of the markdown code.
Should Markdown be inheriting from HTML? My tendency is to say no. Markdown is not a subset or superset of HTML; it is something different. Yes, you can insert HTML directly (outside of a code block) when Markdown itself can't give you what you want, but those insertions are usually very short. I don't think TM's Markdown mode benefits from this inheritance.
I don't tend to use HTML in Markdown, but I sure would like to see it colored when I do use it. I guess it depends on how one uses Markdown. One simple solution to avoiding the indenting behavior is to change the scope of the "Miscellaneous" file in the HTML bundle from "text.html" to "text.html - text.html.markdown". That would tell it to not use whatever that file is offering in the markdown bundle. This should make things work in your local copy. (Don't forget, if you want changes to preferences items to take effect, you have to close the Bundle Editor window) The only "disadvantage" to this is that it makes something in the HTML bundle refer markdown. the HTML bundle doesn't "know" about markdown, and it shouldn't. But if you want a quick fix, that is the simplest way.
-- Dr. Drang
Haris
On Mar 1, 2006, at 1:21 AM, Charilaos Skiadas wrote:
I don't tend to use HTML in Markdown, but I sure would like to see it colored when I do use it. I guess it depends on how one uses Markdown.
I'm beginning to think that I don't want any syntax highlighting in Markdown. I suppose the ideal would be for code blocks to be highlighted according to the language in that block, but not having highlighting doesn't affect me much. Except when taking notes in a programming class, I don't write code directly in Markdown, I paste it into my Markdown documents from the original source files--which are, of course, properly highlighted for the language.
One simple solution to avoiding the indenting behavior is to change the scope of the "Miscellaneous" file in the HTML bundle from "text.html" to "text.html - text.html.markdown". That would tell it to not use whatever that file is offering in the markdown bundle. This should make things work in your local copy. (Don't forget, if you want changes to preferences items to take effect, you have to close the Bundle Editor window) The only "disadvantage" to this is that it makes something in the HTML bundle refer markdown. the HTML bundle doesn't "know" about markdown, and it shouldn't. But if you want a quick fix, that is the simplest way.
I've only been back to using TextMate for a couple of weeks now, and don't feel comfortable mucking around inside it yet. And I've spent too much time undoing "quick fixes" to want to jump in and change TM's behavior before I get a better understanding of how it works and how I work with it. So for now I'll just backspace to get rid of the extra indentation.
Thanks for the explanations.
-- Dr. Drang
On 1/3/2006, at 8:21, Charilaos Skiadas wrote:
I will agree with you that in markup.raw.block.markdown it perhaps should not get special treatment [...]
I added a Preferences item to the Markdown bundle which sets the increase/decrease indent patterns as they are set in the Source bundle, and scoped this to markup.raw.block.markdown -- so at least in raw text in Markdown, C++ template arguments are not mistaken for HTML tags.
Maybe though people who use the raw environment for HTML examples will dislike the lack of smart indent -- but then, they can just remove this new preferences item :)
Should Markdown be inheriting from HTML? My tendency is to say no. Markdown is not a subset or superset of HTML; it is something different. [...]
There are advantages of letting it inherit from HTML, and thanks to the granular scope system, it’s generally not a problem to override the default behavior given from the HTML inheritance.
On Mar 1, 2006, at 8:15 AM, Allan Odgaard wrote:
On 1/3/2006, at 8:21, Charilaos Skiadas wrote:
I will agree with you that in markup.raw.block.markdown it perhaps should not get special treatment [...]
I added a Preferences item to the Markdown bundle which sets the increase/decrease indent patterns as they are set in the Source bundle, and scoped this to markup.raw.block.markdown -- so at least in raw text in Markdown, C++ template arguments are not mistaken for HTML tags.
Unfortunately, I'm too new to TextMate to really understand this. But it sounds like the new Markdown bundle will not have the extra indentation by default. Am I right?
I also want to make sure I understand the bundle hierarchy before I install anything new. I've made my own additions to TM's Markdown support and I don't want them to get blown away.
As I understand it, the default bundles are in /Applications/TextMate/ Contents/SharedSupport/Bundles and any changes/additions I make to a bundle are in ~/Library/Application\ Support/TextMate/Bundles. The manual says that when checking out bundles from svn, I should put them in Library/Application\ Support/TextMate/Bundles. Does this mean that the priority for bundle behavior is this?
Highest: ~/Library/Application\ Support/TextMate/Bundles /Library/Application\ Support/TextMate/Bundles Lowest: /Applications/TextMate/Contents/SharedSupport/Bundles
-- Dr. Drang
On 1/3/2006, at 16:31, Dr. Drang wrote:
Unfortunately, I'm too new to TextMate to really understand this. But it sounds like the new Markdown bundle will not have the extra indentation by default. Am I right?
Yes, for raw environments.
As I understand it, the default bundles are in /Applications/ TextMate/Contents/SharedSupport/Bundles and any changes/additions I make to a bundle are in ~/Library/Application\ Support/TextMate/ Bundles. The manual says that when checking out bundles from svn, I should put them in Library/Application\ Support/TextMate/Bundles. Does this mean that the priority for bundle behavior is this?
Highest: ~/Library/Application\ Support/TextMate/Bundles /Library/Application\ Support/TextMate/Bundles Lowest: /Applications/TextMate/Contents/SharedSupport/Bundles
Yes -- and it merges bundles on a per-item basis. So add one item to the Markdown bundle, and only that item goes to ~/Library, and the rest is still from the default bundle.
Basically TM will never “blow away” any custom stuff when you upgrade. For that, you need to actively delete stuff in ~/Library.