{"id":1050,"date":"2013-02-08T11:17:01","date_gmt":"2013-02-08T16:17:01","guid":{"rendered":"http:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/?p=1050"},"modified":"2022-07-01T09:03:59","modified_gmt":"2022-07-01T13:03:59","slug":"linebreak-fixing-in-emacs","status":"publish","type":"post","link":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/2013\/02\/linebreak-fixing-in-emacs\/","title":{"rendered":"Linebreak &#8220;Fixing&#8221; in Emacs"},"content":{"rendered":"<p><a href=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2013\/02\/Screenshot-02082013-111528-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-thumbnail wp-image-1052\" alt=\"Screenshot - 02082013 - 11:15:28 AM\" src=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-content\/uploads\/2013\/02\/Screenshot-02082013-111528-AM-150x150.png\" width=\"150\" height=\"150\" \/><\/a>Back in the stone ages, everybody knew that whitespace was unimportant and people should be free to format text, code, whatever, any damn way they please. \u00a0<strong>NO LONGER!<\/strong> \u00a0In our brave new world all those line breaks, indents, tabbing, and so on are all critical and we must all do them the same way! \u00a0Or else!<\/p>\n<p>The latest offender is <a href=\"http:\/\/gitlab.org\/\">GitLab<\/a>&#8216;s slightly modified <a href=\"http:\/\/daringfireball.net\/projects\/markdown\/syntax\">Markdown<\/a>, which treats linebreaks in text blocks as actual linebreaks and inserts hard breaks in the output HTML. Somewhat disappointing for an otherwise largely stellar package&#8230;<\/p>\n<p>In any event, that means you need to be careful about how you format your <code>README.md<\/code> and such if you want it to print reasonably in GitLab&#8217;s web view. For all those Emacs devotees used to religiously <code>META-Q<\/code>&#8216;ing text paragraphs to be terminal formatted&#8212;as any sane person would!&#8212;you wind up with a ton of short lines in the display.<\/p>\n<p>This is a little helper I wrote and include in my <code>.emacs<\/code> to deal with this and similar problems:<\/p>\n<pre>(defun fix-lines ()\r\n  (interactive \"*\")\r\n  (save-excursion\r\n    (save-restriction\r\n      (if (region-active-p)\r\n          (progn  (setq start (region-beginning) end (region-end))\r\n                  (narrow-to-region start end)\r\n                  (goto-char (point-min))))\r\n         (while (re-search-forward \"\\\\([^\\n]\\\\)\\n\\\\([^\\n]\\\\)\" nil t)\r\n              (replace-match \"\\\\1 \\\\2\" nil nil)))))\r\n\r\n(global-set-key \"\\C-xf\" 'fix-lines)<\/pre>\n<p><code>CTRL-xf<\/code> will now get rid of all those newly <em>eviiil<\/em> linebreaks. If a region is active only that text will be affected, otherwise the text from the current point on is modified. Hooray!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in the stone ages, everybody knew that whitespace was unimportant and people should be free to format text, code, whatever, any damn way they please. \u00a0NO LONGER! \u00a0In our brave new world all those line breaks, indents, tabbing, and so on are all critical and we must all do them the same way! \u00a0Or &hellip; <a href=\"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/2013\/02\/linebreak-fixing-in-emacs\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1052,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[147,257,151,148],"class_list":["post-1050","post","type-post","status-publish","format-standard","hentry","category-code","tag-emacs","tag-featured","tag-lisp","tag-markdown"],"_links":{"self":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts\/1050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/comments?post=1050"}],"version-history":[{"count":2,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts\/1050\/revisions"}],"predecessor-version":[{"id":1053,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/posts\/1050\/revisions\/1053"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/media\/1052"}],"wp:attachment":[{"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/media?parent=1050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/categories?post=1050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocketshipgames.com\/blogs\/tjkopena\/wp-json\/wp\/v2\/tags?post=1050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}