{"id":44,"date":"2009-01-16T10:55:59","date_gmt":"2009-01-16T09:55:59","guid":{"rendered":"http:\/\/www.schuerig.de\/michael\/blog\/?p=44"},"modified":"2021-11-24T09:20:32","modified_gmt":"2021-11-24T08:20:32","slug":"line-movement-for-emacs","status":"publish","type":"post","link":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/2009\/01\/16\/line-movement-for-emacs\/","title":{"rendered":"Line movement for Emacs"},"content":{"rendered":"<p>Recently, I&#8217;ve been mingling with two old acquaintances (if not downright friends): <tt>C<\/tt> and <tt>Emacs<\/tt>. Through my interaction with other text editors I&#8217;ve come to know functions to move the current line, i.e. the one containing the cursor, up or down. That&#8217;s something I wanted to have in <tt>Emacs<\/tt> too. And so I wrote my first ever <tt>Emacs Lisp<\/tt> functions with some help from <a href=\"http:\/\/groups.google.com\/group\/comp.emacs\/browse_thread\/thread\/9a0b9b2ab342762d#\"><tt>comp.emacs<\/tt><\/a>.<\/p>\n<p>Stick these definitions in <tt>~\/.emacs<\/tt> and evaluate them or restart <tt>Emacs<\/tt>.<\/p>\n<p><code><\/p>\n<pre>\r\n(defun move-line-down ()\r\n  (interactive)\r\n  (let ((col (current-column)))\r\n    (save-excursion\r\n      (next-line)\r\n      (transpose-lines 1))\r\n    (next-line)\r\n    (move-to-column col)))\r\n\r\n(defun move-line-up ()\r\n  (interactive)\r\n  (let ((col (current-column)))\r\n    (save-excursion\r\n      (next-line)\r\n      (transpose-lines -1))\r\n    (move-to-column col)))\r\n\r\n(global-set-key [\\M-down] 'move-line-down)\r\n(global-set-key [\\M-up] 'move-line-up)\r\n<\/pre>\n<p><\/code><\/p>\n<p>Now you have Meta-Down and Meta-Up (i.e., probably Alt-Down and Alt-Up) bound to moving the current line around.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I&#8217;ve been mingling with two old acquaintances (if not downright friends): C and Emacs. Through my interaction with other text editors I&#8217;ve come to know functions to move the current line, i.e. the one containing the cursor, up or &hellip; <a href=\"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/2009\/01\/16\/line-movement-for-emacs\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[17],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-emacs","tag-emacs-lisp"],"_links":{"self":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":3,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/44\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}