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
|
;; Duplicate Line
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defun duplicate-line()
|
;; From: http://tuxicity.se/emacs/elisp/2010/03/11/duplicate-current-line-or-region-in-emacs.html
|
||||||
(interactive)
|
(defun duplicate-current-line-or-region (arg)
|
||||||
(move-beginning-of-line 1)
|
"Duplicates the current line or region ARG times.
|
||||||
(kill-line)
|
If there's no region, the current line will be duplicated. However, if
|
||||||
(yank)
|
there's a region, all lines that region covers will be duplicated."
|
||||||
(newline)
|
(interactive "p")
|
||||||
(yank))
|
(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))
|
(global-set-key (kbd "M-n") 'textmate-column-down))
|
||||||
|
|
||||||
;; Duplicate line (via helpers.el)
|
;; 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
|
;; Align to equal signs
|
||||||
(global-set-key (kbd "C-x a =") 'align-to-equals)
|
(global-set-key (kbd "C-x a =") 'align-to-equals)
|
||||||
|
|||||||
Reference in New Issue
Block a user