Xah Lee, 2010-05-21
Last month, i wrote Emacs: Shortcut to Delete Whole Line, because i find that deleting whole line is much frequently needed. But also, i didn't mention that i often find the need to copy the current line too. Usually, this meas moving the cursor to beginning of line, mark, move to end of line, then copy. This is 4 operations. The following code will make it just a single operation:
(defadvice kill-ring-save (before slick-copy activate compile) "When called interactively with no active region, copy the current line." (interactive (if mark-active (list (region-beginning) (region-end)) (progn (message "Current line is copied.") (list (line-beginning-position) (line-beginning-position 2)) ) ) )) (defadvice kill-region (before slick-copy activate compile) "When called interactively with no active region, cut the current line." (interactive (if mark-active (list (region-beginning) (region-end)) (progn (list (line-beginning-position) (line-beginning-position 2)) ) ) ))
With the above code, when you do not have a text selection, copy will just copy the current line. Similar for cut. Super!
Thanks to Joseph O'Donnell for mentioning this. The code is originally from emacswiki.org SlickCopy. Apparently, this behavior is default in VisualStudio, TextMate, SlickEdit.