Advertisement
Guest User

Untitled

a guest
Jan 17th, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.30 KB | None | 0 0
  1. # Wrapping in TextMate:
  2.  
  3. It would be nice if we could get indented soft wrap in TextMate. To that end I'm making this list of all the different types of wrapping we may want to support, and some explanations of what type of flexibility is needed.
  4.  
  5. ## Markdown:
  6.  
  7. There are several valid ways to compose various markdown elements such as quoted text and lists, and we want to support them to the extent possible:
  8.  
  9. ### Lists:
  10.  
  11. If this is a regular paragraph,
  12.  
  13. * This is a list with a really long
  14. line in it. we want the line with
  15. the `*` to have a hanging indent.
  16.  
  17. * This is item 2 in the list
  18.  
  19. * this is a sublist with a long
  20. line itself. it should be
  21. wrapped as well
  22. * the sublist's second item
  23. * in markdown 2 i think we
  24. want to disallow these
  25. two-space indents for
  26. sublists
  27.  
  28. * back to the main list
  29.  
  30. ----
  31.  
  32. Here is another list:
  33.  
  34. * the items are indented
  35. * like so
  36.  
  37. We can put a sublist inside
  38. this list with ease:
  39.  
  40. * and the sub-items
  41. are also indented
  42. * like so
  43.  
  44. And then go back to the item
  45. in the main list, in an easy
  46. readable fashion
  47.  
  48. * this makes the whole list
  49. indented from regular text
  50.  
  51. Regular text just stays flush to the left
  52.  
  53. * The only downside with such indentation
  54. * is that sublists seem rather deeply
  55. indented
  56. * when there's no regular body text
  57. in the original list
  58. * Like in this example
  59.  
  60. This is my preferred way of indenting
  61. nested lists, nonetheless
  62.  
  63. ----
  64.  
  65. Numbered lists are harder, because
  66. there are many ways to write them:
  67.  
  68. 1. We can write the numbers all the way
  69. to the left edge and not indent
  70. 2. Like this
  71.  
  72. ----
  73.  
  74. 1. Writing the numbered list just like
  75. this (or similar).
  76. 2. If we continue this list, it
  77. will look okay
  78. 15. But if our numbers grow, suddenly
  79. so does our indent… not so hot.
  80.  
  81. To this end we might want a list like:
  82.  
  83. 1. here's another list, this time with
  84. the text starting on a tab stop.
  85. 2. this one makes sure that things
  86. look good.
  87. 12. and we can even get the numbers
  88. (up through 99 at least) to be
  89. right-aligned
  90. 13. though currently a bug in
  91. Markdown's implementation prevents
  92. this from working as it should.
  93. Markdown 2.0 should fix this, and
  94. it would be slick if TM even
  95. wrote the lists like this by
  96. default when typing along.
  97.  
  98. Of course, if we're going to indent lists
  99. and quotes by two spaces, then we could
  100. also do this with numbered lists:
  101.  
  102. 1. This list ends up not keeping
  103. the paragraph exactly aligned
  104. with the first line
  105. 2. However it avoids the whole
  106. right-aligned dilemma
  107. 14. And for big numbers
  108. the list just gets a bit more
  109. out of alignment.
  110.  
  111. ### Quoted text
  112.  
  113. For quoted text, things are if anything even worse.
  114.  
  115. Here's a paragraph
  116. > In email, quoted text generally
  117. > starts with a `>` mark
  118. >> A sub-quote starts with two
  119. >> `>` marks instead
  120. >>> And we can keep increasing
  121. >>> the quote level as we like
  122.  
  123. Now, sometimes people put spaces
  124. between qoute marks:
  125.  
  126. > This is a quoted bit piece
  127. > of text.
  128. > > This is a sub-quote
  129. > > > etc. etc.
  130. > And back to the first quote
  131.  
  132. But in markdown, we can also indent
  133. before a quote mark, so that the
  134. quoted text is indented as it
  135. would be when the document is
  136. typeset:
  137.  
  138. > so this text is quoted, and
  139. > we can see visually that
  140. > it's indented from surrounding
  141. > text
  142. >
  143. > > we can make doubly quoted
  144. > > text indented even more
  145. > > using 4 spaces between.
  146. > >
  147. > > > If these are typeset
  148. > > > with little quote bars
  149. > > > down the left, they
  150. > > > now bear a strong
  151. > > > resemblance now to their
  152. > > > final form.
  153. >
  154. > And it's easy to get back to an
  155. > earlier quotation level.
  156. >
  157. > * For reference, here's a list
  158. > inside some quoted text.
  159. > * With two items in it
  160. >
  161. > And back to the original quotation
  162. >
  163. > > > > > > One big
  164. > > > > > > downside with
  165. > > > > > > this method
  166. > > > > > > is it doesn't
  167. > > > > > > work well with
  168. > > > > > > deeply nested
  169. > > > > > > quotations.
  170.  
  171. Unfortunately, this style takes up lots of extra space (especially with deep nesting, as in emails), even if it's more readable.
  172.  
  173. *Aside:* For the purposes of Markdown 2.0, I'm not sure how this should be done. I suppose it can have a rule something like, if there are 4 spaces after the last `>`, then we get pre-formatted text, or similar. I don't think it's as big a problem with lists (to require 4 spaces or a tab for each additional level) as it is with quotes, because lists aren't commonly nested very deeply, whereas with email quotations, nesting can be very deep indeed.
  174.  
  175. ----
  176.  
  177. We want textmate to do hanging indents on these, and possibly even do nifty stuff like putting in "ghost" `>` characters for us. So the wrapping might look like:
  178.  
  179. This is a paragraph
  180.  
  181. > And this is a quote with a long
  182. line in it, which wraps.
  183.  
  184. Or might look like this:
  185.  
  186. This is a paragraph
  187.  
  188. > This is a quote with a long line
  189. > but a ghost `>` character keeps it
  190. > looking like it's hard wrapped.
  191.  
  192. ### Pre-formatted text:
  193.  
  194. We probably don't want some lines to wrap at all. In the case of markdown, this includes lines of Pre-formatted text, such as:
  195.  
  196. The following code block should not wrap at all:
  197.  
  198. def spam(eggs, ham): return (lambda x, y: (eggs*x + ham*y)**(1/2) - 1)
  199.  
  200. Whew, that was a long line
  201.  
  202. This will allow for the exact quoting of code, without getting weird wrapping effects.
  203.  
  204. ### Long urls in references:
  205.  
  206. We don't want long urls in reference style links to wrap, in Markdown. For instance, in my key binding article, I have the following at the bottom:
  207.  
  208. [appledev-plist]: http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/PropertyLists.html#//apple_ref/doc/uid/10000048
  209. [appledev-keybindings]: http://developer.apple.com/documentation/Cocoa/Conceptual/InputManager/Concepts/KeyBindings.html#//apple_ref/doc/uid/20001037-DontLinkElementID_2050128a
  210. [appledev-text-system-defaults]: http://developer.apple.com/documentation/Cocoa/Conceptual/BasicEventHandling/Tasks/TextDefaultsAndBindings.html
  211. [appledev-nsres]: http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSResponder.html
  212. [appledev-nstext]: http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSText.html
  213. [appledev-text-input]: http://developer.apple.com/documentation/Cocoa/Conceptual/InputManager/index.html
  214. [apple-ucode]: http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT
  215.  
  216. It's annoying for this to wrap.
  217.  
  218. ## HTML
  219.  
  220. In html, xml (like svg), etc. it would be slick if soft wrap really worked well.
  221.  
  222. ### Within opening/closing
  223.  
  224. For instance, in the following svg version of the UK flag, some lines are way too long. It would be nice if these wrapped, in an "intelligent" fashion: not wrapping some scopes at all, and wrapping others at logical places.
  225.  
  226. <?xml version="1.0" standalone="yes"?>
  227. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  228. <svg id="Flag of the United Kingdom" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1200" height="600" viewBox="0 0 1200 600">
  229. <defs>
  230. <g id="diagonal">
  231. <rect fill="white" width="68" height="6" y="-3" />
  232. <rect fill="#CF142B" width="34" height="2" />
  233. <rect fill="#CF142B" width="34" height="2" x="34" y="-2" />
  234. </g>
  235. </defs>
  236. <g id="Flag of the United Kingdom" transform="scale(20,20)">
  237. <rect id="blue background" fill="#00247D" width="60" height="30" />
  238. <g id="saltires">
  239. <use id="NW-SE" xlink:href="#diagonal" transform="rotate(26.56505117707799001891544321551918983459472656)" />
  240. <use id="NE-SW" xlink:href="#diagonal" transform="translate(0,30) rotate(-26.56505117707799001891544321551918983459472656)" />
  241. </g>
  242. <g id="white cross" fill="white">
  243. <rect width="10" height="30" x="25" />
  244. <rect width="60" height="10" y="10" />
  245. </g>
  246. <g id="red cross" fill="#CF142B">
  247. <rect width="6" height="30" x="27" />
  248. <rect width="60" height="6" y="12" />
  249. </g>
  250. </g>
  251. </svg>
  252.  
  253. In this case, we probably want the doctype to wrap, as well as the `svg` tag, and the `use` tags. An ideal wrapping is probably something like:
  254.  
  255. 1 <?xml version="1.0" standalone="yes"?>
  256. 2 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  257. • "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  258. 3 <svg id="Flag of the United Kingdom" version="1.1"
  259. • xmlns="http://www.w3.org/2000/svg"
  260. • xmlns:xlink="http://www.w3.org/1999/xlink"
  261. • width="1200" height="600" viewBox="0 0 1200 600">
  262. 4 <defs>
  263. 5 <g id="diagonal">
  264. 6 <rect fill="white" width="68" height="6" y="-3" />
  265. 7 <rect fill="#CF142B" width="34" height="2" />
  266. 8 <rect fill="#CF142B" width="34" height="2" x="34" y="-2" />
  267. 9 </g>
  268. 10 </defs>
  269. 11 <g id="Flag of the United Kingdom" transform="scale(20,20)">
  270. 12 <rect id="blue background" fill="#00247D" width="60"
  271. • height="30" />
  272. 13 <g id="saltires">
  273. 14 <use id="NW-SE" xlink:href="#diagonal"
  274. • transform="rotate(26.56505117707799001891544321551918983459472656)" />
  275. 15 <use id="NE-SW" xlink:href="#diagonal"
  276. • transform="translate(0,30) rotate(-26.56505117707799001891544321551918983459472656)" />
  277. 16 </g>
  278. 17 <g id="white cross" fill="white">
  279. 18 <rect width="10" height="30" x="25" />
  280. 19 <rect width="60" height="10" y="10" />
  281. 20 </g>
  282. 21 <g id="red cross" fill="#CF142B">
  283. 22 <rect width="6" height="30" x="27" />
  284. 23 <rect width="60" height="6" y="12" />
  285. 24 </g>
  286. 25 </g>
  287. 26 </svg>
  288.  
  289. Where for instance we don't get wrapping in the middle of an attribute (like halfway through one of those very long numbers, for instance)
  290.  
  291. ### Inside tags
  292.  
  293. In html, or xml plists, &c., the tags themselves aren't generally so absurdly long, but their content might be. There are a couple of ways that the actual file could be stored, listed below:
  294.  
  295. <ul>
  296. <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>
  297. <li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</li>
  298. </ul>
  299.  
  300. ----
  301.  
  302. <ul>
  303. <li>
  304. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  305. </li>
  306. <li>
  307. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  308. </li>
  309. </ul>
  310.  
  311. The second of these is quite straight-forward. We simply want to wrap to the exact level to which the beginning of the line is wrapped, like so:
  312.  
  313. <ul>
  314. <li>
  315. Lorem ipsum dolor sit amet, consectetur
  316. adipisicing elit, sed do eiusmod tempor
  317. incididunt ut labore et dolore magna aliqua.
  318. Ut enim ad minim veniam, quis nostrud
  319. exercitation ullamco laboris nisi ut aliquip
  320. ex ea commodo consequat.
  321. </li>
  322. <li>
  323. Duis aute irure dolor in reprehenderit in
  324. voluptate velit esse cillum dolore eu fugiat
  325. nulla pariatur. Excepteur sint occaecat
  326. cupidatat non proident, sunt in culpa qui
  327. officia deserunt mollit anim id est laborum.
  328. </li>
  329. </ul>
  330.  
  331. It is the first scenario which offers a couple of solutions. The simplest is to simply wrap every line after the first to the same indentation level. This is the approach which BBEdit adopts in their most recent version:
  332.  
  333. <ul>
  334. <li>Lorem ipsum dolor sit amet, consectetur
  335. adipisicing elit, sed do eiusmod tempor
  336. incididunt ut labore et dolore magna aliqua.
  337. Ut enim ad minim veniam, quis nostrud
  338. exercitation ullamco laboris nisi ut aliquip
  339. ex ea commodo consequat.</li>
  340. <li>Duis aute irure dolor in reprehenderit in
  341. voluptate velit esse cillum dolore eu fugiat
  342. nulla pariatur. Excepteur sint occaecat
  343. cupidatat non proident, sunt in culpa qui
  344. officia deserunt mollit anim id est
  345. laborum.</li>
  346. </ul>
  347.  
  348. This doesn't seem satisfactory. A separate method would be to allow scope and/or a regular expression on the line to set the number of tab stops to indent. We may want the text in this case to be wrapped to one (or maybe two) tab stops beyond the original:
  349.  
  350. <ul>
  351. <li>Lorem ipsum dolor sit amet, consectetur
  352. adipisicing elit, sed do eiusmod tempor
  353. incididunt ut labore et dolore magna aliqua.
  354. Ut enim ad minim veniam, quis nostrud
  355. exercitation ullamco laboris nisi ut aliquip
  356. ex ea commodo consequat.</li>
  357. <li>Duis aute irure dolor in reprehenderit in
  358. voluptate velit esse cillum dolore eu fugiat
  359. nulla pariatur. Excepteur sint occaecat
  360. cupidatat non proident, sunt in culpa qui
  361. officia deserunt mollit anim id est
  362. laborum.</li>
  363. </ul>
  364.  
  365. A more complicated method would allow the text to be indented so that it aligns with the end of the opening tag:
  366.  
  367. <ul>
  368. <li>Lorem ipsum dolor sit amet, consectetur
  369. adipisicing elit, sed do eiusmod tempor
  370. incididunt ut labore et dolore magna
  371. aliqua. Ut enim ad minim veniam, quis
  372. nostrud exercitation ullamco laboris nisi
  373. ut aliquip ex ea commodo consequat.</li>
  374. <li>Duis aute irure dolor in reprehenderit
  375. in voluptate velit esse cillum dolore eu
  376. fugiat nulla pariatur. Excepteur sint
  377. occaecat cupidatat non proident, sunt in
  378. culpa qui officia deserunt mollit anim
  379. id est laborum.</li>
  380. </ul>
  381.  
  382. Or perhaps even with the first character of the tag content--something like:
  383.  
  384.  
  385. <ul>
  386. <li> Lorem ipsum dolor sit amet, consectetur
  387. adipisicing elit, sed do eiusmod tempor
  388. incididunt ut labore et dolore magna
  389. aliqua. Ut enim ad minim veniam, quis
  390. nostrud exercitation ullamco laboris nisi
  391. ut aliquip ex ea commodo consequat.</li>
  392. <li> Duis aute irure dolor in reprehenderit
  393. in voluptate velit esse cillum dolore eu
  394. fugiat nulla pariatur. Excepteur sint
  395. occaecat cupidatat non proident, sunt in
  396. culpa qui officia deserunt mollit anim
  397. id est laborum.</li>
  398. </ul>
  399.  
  400. The problem that I can envision with a scheme like this is that it could get rather ugly if the tags have lots of attributes:
  401.  
  402.  
  403. <ul>
  404. <li id="foobaria" class="wow"> Lorem ipsum
  405. dolor sit amet,
  406. consectetur
  407. adipisicing elit,
  408. sed do eiusmod
  409. tempor incididunt
  410. ut labore et
  411. dolore magna
  412. aliqua. Ut enim
  413. ad minim veniam,
  414. quis nostrud
  415. exercitation
  416. ullamco laboris
  417. nisi ut aliquip
  418. ex ea commodo
  419. consequat.</li>
  420. <li id="baz"> Duis aute irure dolor in
  421. reprehenderit in voluptate velit
  422. esse cillum dolore eu fugiat nulla
  423. pariatur. Excepteur sint occaecat
  424. cupidatat non proident, sunt in
  425. culpa qui officia deserunt mollit
  426. anim id est laborum.</li>
  427. </ul>
  428.  
  429. Which is, quite frankly, ridiculous. So maybe people would in this type of scheme need the ability to set a maximum level to which the wrap would happen (of course this maximum would need to be settable on a case-by-case basis).
  430.  
  431. But the problem is not only with really exended lines. It's also annoying that in the above, the two paragraphs don't line up. I much prefer the one tab method in this case:
  432.  
  433. <ul>
  434. <li id="foobaria" class="wow"> Lorem ipsum dolor
  435. sit amet, consectetur adipisicing elit, sed do
  436. eiusmod tempor incididunt ut labore et dolore
  437. magna aliqua. Ut enim ad minim veniam, quis
  438. nostrud exercitation ullamco laboris nisi ut
  439. aliquip ex ea commodo consequat.</li>
  440. <li id="baz"> Duis aute irure dolor in
  441. reprehenderit in voluptate velit esse cillum
  442. dolore eu fugiat nulla pariatur. Excepteur sint
  443. occaecat cupidatat non proident, sunt in culpa
  444. qui officia deserunt mollit anim id est
  445. laborum.</li>
  446. </ul>
  447.  
  448. The above is pretty readable, IMO, especially with some proper syntax highlighting to separate content from tags.
  449.  
  450. ----
  451.  
  452. With a customizable enough system, we could maybe even make the code look like it was hard wrapped. It could wrap something like:
  453.  
  454. 1 <ul>
  455. 2 <li id="foobaria" class="wow">
  456. • Lorem ipsum dolor sit amet, consectetur
  457. • adipisicing elit, sed do eiusmod tempor
  458. • incididunt ut labore et dolore magna
  459. • aliqua. Ut enim ad minim veniam, quis
  460. • nostrud exercitation ullamco laboris
  461. • nisi ut aliquip ex ea commodo consequat.
  462. • </li>
  463. 3 <li id="baz">
  464. • Duis aute irure dolor in reprehenderit
  465. • in voluptate velit esse cillum dolore
  466. • eu fugiat nulla pariatur. Excepteur
  467. • sint occaecat cupidatat non proident,
  468. • sunt in culpa qui officia deserunt
  469. • mollit anim id est laborum.
  470. • </li>
  471. 4 </ul>
  472.  
  473. The above would be pretty neat, but might get users confused about whether their text was hard or soft wrapped, and it might be disconcerting to be typing along on a line, and with the addition of one letter, have the whole thing get reformatted drastically:
  474.  
  475. 1 <ul>
  476. 2 <li class="wow"> Lorem ipsum dolor s|</li>
  477. 3 </ul>
  478.  
  479. becoming
  480.  
  481. 1 <ul>
  482. 2 <li class="wow">
  483. • Lorem ipsum dolor sit|
  484. • </li>
  485. 3 </ul>
  486.  
  487. where `|` represents the insertion point. This might also be a potential performance drag. The following would be more in line with (especially unfamiliar) user expectations:
  488.  
  489. 1 <ul>
  490. 2 <li class="wow"> Lorem ipsum dolor
  491. • sit|</li>
  492. 3 </ul>
  493.  
  494.  
  495. ----
  496.  
  497. Of course, this whole thing somewhat comes down to personal preference, which maybe is an argument for flexibility (however, most new users won't be able to figure out a very complicated scheme for setting these indentation levels, so KISS is also an important principle here).
  498.  
  499. ## Source code
  500.  
  501. In source code, I have no idea how various things should be indented. In general, I just hard wrap everything, as python is pretty amenable to 80 character line limits when coding, and I don't write much code in extremely verbose languages like Objective C. The only place where I can really see myself liking any kind of soft wrap in code is inside comments and strings.
  502.  
  503.  
  504. ## Option: Let's Go More Basic
  505.  
  506. Having Textmate deduce what sort of wrapping to do contextual is good, but sometimes it's nice to have some simpler options. Consequently, I'd suggest the following, at minimum, to just be Preferences/View Menu options:
  507.  
  508. (Taken from http://ticket.macromates.com/show?ticket_id=4EFB31A8)
  509. 1. No-Indent Wrap: Where soft-wrapped subsequent lines start at column 0.
  510. 2. Same Indent Wrap: Where soft-wrapped subsequent lines start at the same indent as the original line.
  511. 3. Plus-One Indent Wrap: Where soft-wrapped subsequent lines start at the same indent as the original line plus one additional indent.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement