{"id":1517,"date":"2012-12-13T08:44:07","date_gmt":"2012-12-13T13:44:07","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=1517"},"modified":"2012-12-13T08:45:26","modified_gmt":"2012-12-13T13:45:26","slug":"a-nice-emacs-trick","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=1517","title":{"rendered":"A Nice Emacs Trick"},"content":{"rendered":"<p>In the <a href=\"http:\/\/irreal.org\/blog\/?p=1489#comment-64079\">comments<\/a> to my <a href=\"http:\/\/irreal.org\/blog\/?p=1489#comments\">Another VimGolf in Emacs Challenge<\/a> post, Aaron Culich points out something that I didn&#8217;t know. It is possible to enter <code>query-replace<\/code> or <code>query-replace-regexp<\/code> directly from <code>isearch<\/code>. When you do this, <code>query-replace<\/code> and <code>query-replace-regexp<\/code> will use the search string for the FROM string and only ask you for the TO string. You invoke the query-replace functions from <code>isearch<\/code> by typing \u3010<kbd>Meta<\/kbd>+<kbd>%<\/kbd>\u3011 or \u3010<kbd>Ctrl<\/kbd>+<kbd>Meta<\/kbd>+<kbd>%<\/kbd>\u3011 before quitting <code>isearch<\/code>.<\/p>\n<p>Why would you want to do this? Here&#8217;s an example. Suppose you have code like<\/p>\n<pre class=\"src src-emacs-lisp\">(<span style=\"color: #a020f0;\">defun<\/span> <span style=\"color: #0000ff;\">anothercase<\/span> ()\r\n  ...)\r\n...\r\n(anothercase)\r\n...\r\n(anothercase)\r\n...\r\netc<\/pre>\n<p>and that your cursor is at the <code>defun<\/code>. You decide you want to change the name of the <code>anothercase<\/code> function to <code>make-new-instance<\/code>. If you type \u3010<kbd>Ctrl<\/kbd>+<kbd>s<\/kbd> <kbd>a<\/kbd> <kbd>Ctrl<\/kbd>+<kbd>w<\/kbd>\u3011 the search string will be <code>anothercase<\/code> and you can type \u3010<kbd>Meta<\/kbd>+<kbd>%<\/kbd>\u3011 to start query replace with the FROM string already set.<\/p>\n<p>A final note. You don&#8217;t have to do anything to enable this functionality. In particular, it is <i>not<\/i> controlled by the <code>query-replace-interactive<\/code> variable. That, if non-nil, <i>always<\/i> uses the last <code>isearch<\/code> string as the FROM string for the query-replace functions, which is probably not what you want.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the comments to my Another VimGolf in Emacs Challenge post, Aaron Culich points out something that I didn&#8217;t know. It is possible to enter query-replace or query-replace-regexp directly from isearch. When you do this, query-replace and query-replace-regexp will use &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=1517\">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-1517","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\/1517","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=1517"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1517\/revisions"}],"predecessor-version":[{"id":1518,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1517\/revisions\/1518"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}