More .emacs-fu
I promised somebody I know to start posting more .emacs-fu on in my blog. So here goes. First out is a function to duplicate whatever the line under the cursor is. If you are a programmer this is something that you probably do a lot. However C-a C-k C-y C-y or C-a M-spc C-e M-w gets old very fast. Instead, put the following function in your .emacs:
(defun duplicate() "Duplicate it the line we are on" (interactive) (let ( (beg (line-beginning-position)) (end (line-end-position))) (copy-region-as-kill beg end) (beginning-of-line) (forward-line 1) (yank) (newline) (forward-line -1)))
and bind it to any key-kombo you like (I used C-c C-j), and duplicating lines is suddenly just a key press away.
And while we are in the spirit. Another thing I often want to do is copy the whole line under the cursor so that I can paste it somewhere else in my document. Similarly add the following function to your .emacs:
(defun copy-line () "Copy current line in the kill ring" (interactive) (kill-ring-save (line-beginning-position) (line-beginning-position 2)) (message "Line copied"))
and bind it to any key-kombo you like (I used C-c C-y), and copying a line is suddenly just a key press away.
Enjoy!
- Previous: 21 August 2010 Migrating SMS from Nokia N80 to HTC Desire
- Next: 11 June 2010 Update on the fu
About me
-
- Professional
- Master thesis on security, privacy and availability in GSM-positioning systems at Simula Research Laboratory and University of Oslo - Department of Informatics. Currently working as a senior Java consultant and Liferay tech lead.
-
- Languages of choice
- C, python, perl and lisp
-
- Current interests
- GSM-networks and technology, Emacs, Stumpwm, org-mode, philosophy and ethics, microprocessors, Drupal, Latex and writing.