tag:blogger.com,1999:blog-3992530807750384868.post923434516280360941..comments2022-03-28T08:42:20.497+03:00Comments on emacs-fu: duplicating lines and commenting themUnknownnoreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3992530807750384868.post-78787521170599637702010-01-23T10:47:18.416+02:002010-01-23T10:47:18.416+02:00Thanks!
Would it be useful to have something simi...Thanks!<br /><br />Would it be useful to have something similar for regions?Anders Rønningenhttps://www.blogger.com/profile/10767259353995815066noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-321889743826445022010-01-22T23:14:12.331+02:002010-01-22T23:14:12.331+02:00A line can be killed by just C-S-backspace, which ...A line can be killed by just C-S-backspace, which calls kill-whole-line. It will kill the whole line independently of cursor position.<br /><br />However, as C-k, it doesn't work on the buffer's last line.Unknownhttps://www.blogger.com/profile/03146653060374564215noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-38288529251792873602010-01-22T19:21:35.992+02:002010-01-22T19:21:35.992+02:00I've been using a version of this for a while ...I've been using a version of this for a while now. I actually map mine to C-xC-d because I use it so much. After reading this post, I've added the comment option.<br /><br />This version will leave the cursor on the same column it was before (but on the new line). I prefer this behavior.<br /><br />Thank you Ola for the interactive hint.<br /><br />(defun duplicate-line (&optional comment line)<br /> "Duplicate the line containing the point. <br />\nIf COMMENT is non-nil, also comment out the original line. <br />If LINE is non-nil, duplicate that line instead."<br /> (interactive "P")<br /> (let ((col (current-column)))<br /> (save-excursion<br /> (when line<br /> (goto-line line))<br /> (let ((line (buffer-substring (point-at-bol) (point-at-eol))))<br /> (when comment<br /> (comment-region (point-at-bol) (point-at-eol)))<br /> (goto-char (point-at-eol))<br /> (if (eobp)<br /> (newline)<br /> (forward-line 1))<br /> (open-line 1)<br /> (insert line)))<br /> (forward-line 1)<br /> (move-to-column col)))Kyle Shermanhttps://www.blogger.com/profile/06549502492931509389noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-21902690027588078492010-01-22T14:52:57.431+02:002010-01-22T14:52:57.431+02:00Change the (interactive) call to (interactive &quo...Change the (interactive) call to (interactive "P") and C-u C-c y will duplicate with comment.Unknownhttps://www.blogger.com/profile/14294332406449952131noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-8841227133814493172010-01-22T06:12:32.536+02:002010-01-22T06:12:32.536+02:00I like the one without mark.
But can anyone just ...I like the one without mark.<br /><br />But can anyone just modify it as if marked, copy the marked part, if not, copy the whole line. <br /><br />(I am not good at lisp)Enchanterhttps://www.blogger.com/profile/11196557718482369610noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-48759085848833169102010-01-22T00:11:18.743+02:002010-01-22T00:11:18.743+02:00nice!nice!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-37469339721326761032010-01-21T23:48:45.909+02:002010-01-21T23:48:45.909+02:00Just another thought... I didn't want to have ...Just another thought... I didn't want to have to set the mark, so a small change:<br /><br />(defun djcb-duplicate-line (&optional commentfirst)<br /> "comment line at point; if COMMENTFIRST is non-nil, comment the original" <br /> (interactive)<br /> (beginning-of-line)<br /> (let<br /> ((beg (point)))<br /> (end-of-line)<br /> (let ((str (buffer-substring beg (point))))<br /> (when commentfirst<br /> (comment-region beg (point)))<br /> (insert-string<br /> (concat (if (= 0 (forward-line 1)) "" "\n") str "\n"))<br /> (forward-line -1))))<br /><br />Thanks.Squiddonoreply@blogger.com