{"id":1836,"date":"2013-04-08T05:52:00","date_gmt":"2013-04-08T09:52:00","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=1836"},"modified":"2013-04-08T13:49:18","modified_gmt":"2013-04-08T17:49:18","slug":"emacsgolf-3","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=1836","title":{"rendered":"EmacsGolf 3"},"content":{"rendered":"<p>It&#8217;s been a while since we&#8217;ve had a EmacsGolf challenge but I just ran across this <a href=\"http:\/\/www.camsaul.com\/2013\/03\/let-regexes-write-your-code-for-you\/\">post from Cameron Saul<\/a> with the perfect problem for us. Here&#8217;s the problem: Saul is writing some Java code that looks like this<\/p>\n<pre class=\"src src-java\"><span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewRoute<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewRoute);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewDirection<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewDirection);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewStartStop<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewStartStop);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewStartDist<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewStartDist);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewStartPrediction<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewStartPrediction);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewEndStop<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewEndStop);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewEndDist<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewEndDist);\r\n<span style=\"color: #228b22;\">TextView<\/span> <span style=\"color: #a0522d;\">textViewEndPrediction<\/span> = (<span style=\"color: #228b22;\">TextView<\/span>)convertView.findViewById(R.id.textViewEndPrediction);<\/pre>\n<p>Notice that each line is the same except for a single symbol that is repeated twice. Saul says he wouldn&#8217;t have to write all this boilerplate if he were writing in a language that didn&#8217;t hate fun. My first thought was, \u201cor if you had a decent editor.\u201d So our job is to show Saul how to leverage Emacs to make this a trivial problem. You&#8217;ll appreciate the challenge more when you see his solution.<\/p>\n<p><b>Update<\/b>: Fuco points out that I didn&#8217;t specify a starting buffer. Let&#8217;s assume that the buffer is empty to begin with.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been a while since we&#8217;ve had a EmacsGolf challenge but I just ran across this post from Cameron Saul with the perfect problem for us. Here&#8217;s the problem: Saul is writing some Java code that looks like this TextView &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=1836\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-1836","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1836"}],"version-history":[{"count":5,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1836\/revisions"}],"predecessor-version":[{"id":1860,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1836\/revisions\/1860"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}