Add prelude-duplicate-and-comment-current-line-or-region (fixes #348)
This commit is contained in:
parent
d47293858c
commit
88248111d1
3 changed files with 26 additions and 0 deletions
|
@ -227,6 +227,7 @@ Keybinding | Description
|
||||||
<kbd>C-c e</kbd> | Eval a bit of Emacs Lisp code and replace it with its result.
|
<kbd>C-c e</kbd> | Eval a bit of Emacs Lisp code and replace it with its result.
|
||||||
<kbd>C-c s</kbd> | Swap two active windows.
|
<kbd>C-c s</kbd> | Swap two active windows.
|
||||||
<kbd>C-c d</kbd> | Duplicate the current line (or region).
|
<kbd>C-c d</kbd> | Duplicate the current line (or region).
|
||||||
|
<kbd>C-c M-d</kbd> | Duplicate and comment the current line (or region).
|
||||||
<kbd>C-c r</kbd> | Rename the currently visited file and buffer.
|
<kbd>C-c r</kbd> | Rename the currently visited file and buffer.
|
||||||
<kbd>C-c t</kbd> | Open a terminal emulator (`ansi-term`).
|
<kbd>C-c t</kbd> | Open a terminal emulator (`ansi-term`).
|
||||||
<kbd>C-c k</kbd> | Kill all open buffers except the one you're currently in.
|
<kbd>C-c k</kbd> | Kill all open buffers except the one you're currently in.
|
||||||
|
|
|
@ -222,6 +222,30 @@ there's a region, all lines that region covers will be duplicated."
|
||||||
(setq end (point))))
|
(setq end (point))))
|
||||||
(goto-char (+ origin (* (length region) arg) arg)))))
|
(goto-char (+ origin (* (length region) arg) arg)))))
|
||||||
|
|
||||||
|
;; TODO: Remove code duplication by extracting something more generic
|
||||||
|
(defun prelude-duplicate-and-comment-current-line-or-region (arg)
|
||||||
|
"Duplicates and comments 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)))
|
||||||
|
(comment-or-uncomment-region beg end)
|
||||||
|
(setq end (line-end-position))
|
||||||
|
(-dotimes arg
|
||||||
|
(lambda (n)
|
||||||
|
(goto-char end)
|
||||||
|
(newline)
|
||||||
|
(insert region)
|
||||||
|
(setq end (point))))
|
||||||
|
(goto-char (+ origin (* (length region) arg) arg)))))
|
||||||
|
|
||||||
(defun prelude-rename-file-and-buffer ()
|
(defun prelude-rename-file-and-buffer ()
|
||||||
"Renames current buffer and file it is visiting."
|
"Renames current buffer and file it is visiting."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
(define-key map (kbd "C-c s") 'prelude-swap-windows)
|
(define-key map (kbd "C-c s") 'prelude-swap-windows)
|
||||||
(define-key map (kbd "C-c D") 'prelude-delete-file-and-buffer)
|
(define-key map (kbd "C-c D") 'prelude-delete-file-and-buffer)
|
||||||
(define-key map (kbd "C-c d") 'prelude-duplicate-current-line-or-region)
|
(define-key map (kbd "C-c d") 'prelude-duplicate-current-line-or-region)
|
||||||
|
(define-key map (kbd "C-c M-d") 'prelude-duplicate-and-comment-current-line-or-region)
|
||||||
(define-key map (kbd "C-c r") 'prelude-rename-file-and-buffer)
|
(define-key map (kbd "C-c r") 'prelude-rename-file-and-buffer)
|
||||||
(define-key map (kbd "C-c t") 'prelude-visit-term-buffer)
|
(define-key map (kbd "C-c t") 'prelude-visit-term-buffer)
|
||||||
(define-key map (kbd "C-c k") 'prelude-kill-other-buffers)
|
(define-key map (kbd "C-c k") 'prelude-kill-other-buffers)
|
||||||
|
|
Loading…
Reference in a new issue