stole a better duplicate-line function from the internet

This commit is contained in:
2012-02-11 20:50:20 +00:00
parent a379d2d9f0
commit ea6cd9d5d0
2 changed files with 21 additions and 8 deletions

View File

@@ -29,13 +29,26 @@
;; Duplicate Line
;;
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(newline)
(yank))
;; From: http://tuxicity.se/emacs/elisp/2010/03/11/duplicate-current-line-or-region-in-emacs.html
(defun duplicate-current-line-or-region (arg)
"Duplicates the current line or region ARG times.
If there's no region, the current line will be duplicated. However, if
there's a region, all lines that region covers will be duplicated."
(interactive "p")
(let (beg end (origin (point)))
(if (and mark-active (> (point) (mark)))
(exchange-point-and-mark))
(setq beg (line-beginning-position))
(if mark-active
(exchange-point-and-mark))
(setq end (line-end-position))
(let ((region (buffer-substring-no-properties beg end)))
(dotimes (i arg)
(goto-char end)
(newline)
(insert region)
(setq end (point)))
(goto-char (+ origin (* (length region) arg) arg)))))
;;

View File

@@ -62,7 +62,7 @@
(global-set-key (kbd "M-n") 'textmate-column-down))
;; Duplicate line (via helpers.el)
(global-set-key (kbd "C-x C-d") 'duplicate-line)
(global-set-key (kbd "C-x C-d") 'duplicate-current-line-or-region)
;; Align to equal signs
(global-set-key (kbd "C-x a =") 'align-to-equals)