tag:blogger.com,1999:blog-3992530807750384868.post7902853816255222152..comments2022-03-28T08:42:20.497+03:00Comments on emacs-fu: copying lines without selecting themUnknownnoreply@blogger.comBlogger15125tag:blogger.com,1999:blog-3992530807750384868.post-56618343585648791782014-10-15T01:15:20.057+03:002014-10-15T01:15:20.057+03:00here is mine version.
(defun copy-line ()
&quo...here is mine version. <br /><br />(defun copy-line ()<br /> "Save the whole line under the cursor as if killed, but don't kill it."<br /> (interactive "*")<br /> (copy-region-as-kill (line-beginning-position) (line-end-position)))Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-21048816240795988402010-06-20T05:11:55.746+03:002010-06-20T05:11:55.746+03:00Very nice tricks. But I prefer to copy the entire ...Very nice tricks. But I prefer to copy the entire line <i>without</i> the end of line. To do so, I just changed "(line-beginning-position 2)" to "(line-end-position)".Sébastienhttps://www.blogger.com/profile/11402067037245380225noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-50601272809213117542009-11-27T21:39:52.057+02:002009-11-27T21:39:52.057+02:00I got some code originally from emacs-wiki that di...I got some code originally from emacs-wiki that didn't work, so I modified it and this works for me:<br /><br />(defun slick-copy ()<br /> (interactive)<br /> "Copy from point to the end of the current line if region is inactive. Otherwise it behaves just like kill-ring-save"<br /> (if (eq mark-active t)<br /> (progn (mark) (kill-ring-save (region-beginning) (region-end)) (message "slick-copy-region"))<br /> (progn (kill-ring-save (point) (line-end-position)) (message "slick-copy-line"))))<br />;(progn (kill-ring-save (line-beginning-position) (line-end-position)) (message "slick-copy-line"))<br />;place the above line into slick copy if you would rather grab the entire line you're on<br />(global-set-key "\M-w" 'slick-copy)ryanm2215https://www.blogger.com/profile/12213776380670717090noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-5068856830378900322009-11-15T06:47:41.101+02:002009-11-15T06:47:41.101+02:00Select and delete a line: C-a C-SPC C-n C-k. Up u...Select and delete a line: C-a C-SPC C-n C-k. Up until emacs23, 'C-n' always worked on logical lines, independently of line wrapping. By default, this is no longer true which, although I suppose is occasionally useful, will make this sequence fail in the presence of wrapped lines. However, my suggestion would be to turn off this feature, at least in programming modes.<br /><br />Similarly, to delete the prefix of a line: C-SPC C-a C-k<br /><br />To delete the end of a line: C-SPC C-e C-k.<br /><br />I guess I've used these so long that I don't view them as intrusive in any way. Indeed, the sequence above for deleting the prefix of a line is probably quicker to type than M-0 C-k.<br /><br />Until recently, emacs had no notion of an active region or transient marks, and I tend to think disabling transient mark mode leads to a more fluid style, once you get used to it.Unknownhttps://www.blogger.com/profile/10644646023400970640noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-32380112422028770442009-11-13T19:10:59.509+02:002009-11-13T19:10:59.509+02:00ok.. I know now what was I doing wrong, sorry.
No...ok.. I know now what was I doing wrong, sorry.<br /><br />Now I added the "next-line" before the list creation and changed line-beggining-position accordinglybut it seems it doesn't have the behavior that killing multiple lines have. It overwrites the killed line instead of appending to it.Ferknoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-37266470859156208982009-11-13T17:42:57.628+02:002009-11-13T17:42:57.628+02:00thanks! that's great.
But how do I make it so...thanks! that's great.<br /><br />But how do I make it so that when I press the M-w it goes to the next line (so that I can copy multiple lines)?<br /><br />I tried adding (next-line) to the if, but it says "wrong number of arguments",why is that? :S<br /><br /><br />call-interactively: Wrong number of arguments: #[(beg end) "Ã Ä <br />\" )" [ad-return-value beg end nil ad-Orig-kill-ring-save] 4 2088129 (byte-code " Ferknoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-87126073075913921672009-11-13T16:51:33.390+02:002009-11-13T16:51:33.390+02:00defadvice rocks. I just noticed it this week, whil...defadvice rocks. I just noticed it this week, while searching for a way to allow perldb mode to interpret environment variables in the command line you give it when starting. I wound up with this:<br /><br />(defadvice start-process (around start-process-subst-vars)<br /> "Substitute env vars in `start-process`."<br /> (let ((arglist (ad-get-args 2))<br /> new-arglist<br /> )<br /> (setq new-arglist<br /> (mapcar 'substitute-in-file-name arglist))<br /> (ad-set-args 2 new-arglist)<br /> )<br /> ad-do-it)<br />(ad-activate 'start-process)aaphttps://www.blogger.com/profile/01316081883197172654noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-71050212841511586842009-11-13T16:33:16.307+02:002009-11-13T16:33:16.307+02:00You can also use C-S-Backspace to kill the entire ...You can also use C-S-Backspace to kill the entire line, it's bound to kill-whole-line in Emacs 23, and I think in 22 as well.<br /><br />But that's a bit more cumbersome than C-w if you use transient mark mode anyway.Unknownhttps://www.blogger.com/profile/09540286867149999590noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-89217158470726003062009-11-13T14:41:56.112+02:002009-11-13T14:41:56.112+02:00Funny to find this post now... I just made somethi...Funny to find this post now... I just made something similar today.<br /><br />Enjoy!<br /><br /><br />(defun smart-copy ()<br /> "Copy word at point, or line if called twice, or region if transient-mark active."<br /> (interactive)<br /> (if (eq last-command 'smart-copy)<br /> (progn (kill-ring-save (line-beginning-position) (line-end-position))<br /> (message "Line pushed to kill ring"))<br /> (save-excursion<br /> (if (not mark-active)<br /> (progn<br /> (mark-word)<br /> (backward-word)<br /> (message "Word pushed to kill ring")))<br /> (kill-ring-save (region-beginning) (region-end)))))Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-8138685179859567912009-11-13T13:18:36.774+02:002009-11-13T13:18:36.774+02:00useless for those which don't use transient-ma...useless for those which don't use transient-mark-mode. Also, it seems that you should be using `use-region-p' for you test. From the Elisp manual:<br /><br /><br /> -- Variable: mark-active<br /> The mark is active when this variable is non-`nil'. This variable is always buffer-local in each buffer. Do _not_ use the value of this variable to decide whether a command that normally operates on text near point should operate on the region instead. Use the function `use-region-p' for that (*note The Region::).Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-65668372980191847942009-11-13T01:39:20.683+02:002009-11-13T01:39:20.683+02:00perfect solution! i've seen many attempts at ...perfect solution! i've seen many attempts at this before. i never implemented any of them because i didn't know what to bind the kill line and copy line commands to. i wanted to bind to one key-stroke like C-k, but ran out of things to bind to...and nothing intuitive came to mind. this is AWESOME as it saves me from binding to new keys. kudos!vinhdizzohttps://www.blogger.com/profile/01446145211934423625noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-42411468676120944462009-11-13T01:32:52.568+02:002009-11-13T01:32:52.568+02:00Wow, that is so obvious and yet so useful! Thanks!...Wow, that is so obvious and yet so useful! Thanks!Draxilhttps://www.blogger.com/profile/17135312635347373235noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-64615425043072477252009-11-13T00:42:45.020+02:002009-11-13T00:42:45.020+02:00Oh, thanks! Again :)
I even managed to bind M-0 C...Oh, thanks! Again :)<br /><br />I even managed to bind M-0 C-k to M-k without too much effort (I'm still a newbie in this world):<br /><br />(global-set-key (kbd "M-k") (lambda () (interactive) (kill-line 0)))Oscarhttps://www.blogger.com/profile/16349261750902063941noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-50984365895039355362009-11-13T00:20:44.946+02:002009-11-13T00:20:44.946+02:00@Oscar: see the docs for 'kill-line'.
&q...@Oscar: see the docs for 'kill-line'.<br /> "With zero argument, kills the text before point on the current line."<br /><br />So<br /> M-0 C-k <br />will delete from point to beginning.djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-42583545990330991092009-11-13T00:09:04.827+02:002009-11-13T00:09:04.827+02:00Nice! I've actually been looking for this, but...Nice! I've actually been looking for this, but the solutions I've encountered earlier haven't worked as I'd hoped. Thanks! (:<br /><br />Now, one of the few things left to fix is the opposite to C-k, that is, delete everything from this point to the beginning of the line. The quest goes on...Oscarhttps://www.blogger.com/profile/16349261750902063941noreply@blogger.com