mirror of
https://github.com/jimeh/.emacs.d.git
synced 2026-02-19 13:46:41 +00:00
stole a better duplicate-line function from the internet
This commit is contained in:
27
helpers.el
27
helpers.el
@@ -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)))))
|
||||
|
||||
|
||||
;;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user