[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/crux 6ae09d0 045/112: Add functions on duplicate current l
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/crux 6ae09d0 045/112: Add functions on duplicate current line or region (#31) |
Date: |
Wed, 11 Aug 2021 09:57:50 -0400 (EDT) |
branch: elpa/crux
commit 6ae09d05c7729a74b342017acbe54784abcee8f3
Author: wscisme <wscisme@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
Add functions on duplicate current line or region (#31)
---
README.md | 46 ++++++++++++++++++++++++----------------------
crux.el | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
index db4dcee..0d8b67e 100644
--- a/README.md
+++ b/README.md
@@ -40,28 +40,30 @@ crux doesn't setup any keybindings for its commands
out-of-the-box.
Here's the list of some suggested keybindings. Feel free to bind
individual commands to whatever keybindings you prefer.
-Command | Suggested Keybinding(s)
| Description
---------------------------------------------|---------------------------------|------------------------
-`crux-open-with` | <kbd>C-c o</kbd> | Open the
currently visited file with an external program.
-`crux-smart-open-line-above` | <kbd>C-S-RET</kbd> or
<kbd>Super-o</kbd> | Insert an empty line above the current line and indent it
properly.
-`crux-smart-open-line` | <kbd>S-RET</kbd> or
<kbd>M-o</kbd> | Insert an empty line and indent it properly (as in most IDEs).
-`crux-cleanup-buffer-or-region` | <kbd>C-c n</kbd> | Fix
indentation in buffer and strip whitespace.
-`crux-recentf-ido-find-file` | <kbd>C-c f</kbd> or
<kbd>Super-r</kbd> | Open recently visited file.
-`crux-view-url` | <kbd>C-c u</kbd> | Open a new
buffer containing the contents of URL.
-`crux-eval-and-replace` | <kbd>C-c e</kbd> | Eval a bit of
Emacs Lisp code and replace it with its result.
-`crux-transpose-windows` | <kbd>C-x 4 t</kbd> | Transpose
the buffers between two windows.
-`crux-delete-file-and-buffer` | <kbd>C-c D</kbd> | Delete
current file and buffer.
-`crux-rename-file-and-buffer` | <kbd>C-c r</kbd> | Rename the
current buffer and its visiting file if any.
-`crux-visit-term-buffer` | <kbd>C-c t</kbd> | Open a
terminal emulator (`ansi-term`).
-`crux-kill-other-buffers` | <kbd>C-c k</kbd> | Kill all open
buffers except the one you're currently in.
-`crux-indent-defun` | <kbd>C-M z</kbd> | Indent the
definition at point.
-`crux-indent-rigidly-and-copy-to-clipboard` | <kbd>C-c TAB</kbd> | Indent and
copy region to clipboard
-`crux-find-user-init-file` | <kbd>C-c I</kbd> | Open user's
init file.
-`crux-find-shell-init-file` | <kbd>C-c S</kbd> | Open shell's
init file.
-`crux-top-join-lines` | <kbd>Super-j</kbd> or
<kbd>C-^</kbd> | Join lines
-`crux-kill-whole-line` | <kbd>Super-k</kbd> | Kill whole
line
-`crux-kill-line-backwards` | <kbd>C-Backspace</kbd> | Kill
line backwards
-`crux-ispell-word-then-abbrev` | <kbd>C-c i</kbd> | Fix word
using `ispell` and then save to `abbrev`.
+Command | Suggested Keybinding(s)
| Description
+----------------------------------------------------|---------------------------------|------------------------
+`crux-open-with` | <kbd>C-c o</kbd> |
Open the currently visited file with an external program.
+`crux-smart-open-line-above` | <kbd>C-S-RET</kbd> or
<kbd>Super-o</kbd> | Insert an empty line above the current line and indent it
properly.
+`crux-smart-open-line` | <kbd>S-RET</kbd> or
<kbd>M-o</kbd> | Insert an empty line and indent it properly (as in most IDEs).
+`crux-cleanup-buffer-or-region` | <kbd>C-c n</kbd> | Fix
indentation in buffer and strip whitespace.
+`crux-recentf-ido-find-file` | <kbd>C-c f</kbd> or
<kbd>Super-r</kbd> | Open recently visited file.
+`crux-view-url` | <kbd>C-c u</kbd> | Open
a new buffer containing the contents of URL.
+`crux-eval-and-replace` | <kbd>C-c e</kbd> | Eval
a bit of Emacs Lisp code and replace it with its result.
+`crux-transpose-windows` | <kbd>C-x 4 t</kbd> |
Transpose the buffers between two windows.
+`crux-delete-file-and-buffer` | <kbd>C-c D</kbd> |
Delete current file and buffer.
+`crux-duplicate-current-line-or-region` | <kbd>C-c d</kbd> |
Duplicate the current line (or region).
+`crux-duplicate-and-comment-current-line-or-region` | <kbd>C-c M-d</kbd> |
Duplicate and comment the current line (or region).
+`crux-rename-file-and-buffer` | <kbd>C-c r</kbd> |
Rename the current buffer and its visiting file if any.
+`crux-visit-term-buffer` | <kbd>C-c t</kbd> | Open
a terminal emulator (`ansi-term`).
+`crux-kill-other-buffers` | <kbd>C-c k</kbd> | Kill
all open buffers except the one you're currently in.
+`crux-indent-defun` | <kbd>C-M z</kbd> |
Indent the definition at point.
+`crux-indent-rigidly-and-copy-to-clipboard` | <kbd>C-c TAB</kbd> |
Indent and copy region to clipboard
+`crux-find-user-init-file` | <kbd>C-c I</kbd> | Open
user's init file.
+`crux-find-shell-init-file` | <kbd>C-c S</kbd> | Open
shell's init file.
+`crux-top-join-lines` | <kbd>Super-j</kbd> or
<kbd>C-^</kbd> | Join lines
+`crux-kill-whole-line` | <kbd>Super-k</kbd> |
Kill whole line
+`crux-kill-line-backwards` | <kbd>C-Backspace</kbd> |
Kill line backwards
+`crux-ispell-word-then-abbrev` | <kbd>C-c i</kbd> | Fix
word using `ispell` and then save to `abbrev`.
Here's how you'd bind some of the commands to keycombos:
diff --git a/crux.el b/crux.el
index 1d68fac..dfff419 100644
--- a/crux.el
+++ b/crux.el
@@ -226,6 +226,40 @@ point reaches the beginning or end of the buffer, stop
there."
(setq end (line-end-position))
(cons beg end)))
+(defun crux-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")
+ (pcase-let* ((origin (point))
+ (`(,beg . ,end) (crux-get-positions-of-line-or-region))
+ (region (buffer-substring-no-properties beg end)))
+ (-dotimes arg
+ (lambda (n)
+ (goto-char end)
+ (newline)
+ (insert region)
+ (setq end (point))))
+ (goto-char (+ origin (* (length region) arg) arg))))
+
+(defun crux-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")
+ (pcase-let* ((origin (point))
+ (`(,beg . ,end) (crux-get-positions-of-line-or-region))
+ (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 crux-rename-file-and-buffer ()
"Rename current buffer and if the buffer is visiting a file, rename it too."
(interactive)
- [nongnu] elpa/crux fde9d4b 044/112: Fix malformed header line, (continued)
- [nongnu] elpa/crux fde9d4b 044/112: Fix malformed header line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5b3c815 047/112: Release 0.3, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3e03d72 049/112: Don't use dash.el function (#34), ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux b60d9f4 051/112: Fix a compilation warning, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 54cc9b8 056/112: Fix typo in crux-top-join-line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 11096b9 058/112: Fix typo in keybindings (#47), ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux cedec52 063/112: Mark crux-recentf-ido-find-file as obsolete, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 66954bf 022/112: Mention crux-indent-defun, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3042f6f 029/112: Add some contribution guidelines, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 225b5e3 042/112: Merge pull request #29 from Wilfred/rename_file_and_buffer_tweaks, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 6ae09d0 045/112: Add functions on duplicate current line or region (#31),
ELPA Syncer <=
- [nongnu] elpa/crux 4302357 052/112: Make crux-visit-term-buffer ask to restart dead process (#36), ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 2e16b82 087/112: Rework `move-to-mode-line-start` to add extensibility (#71), ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux bb5a133 090/112: Simplify a bit of code, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 1fa7162 091/112: Optionally move visually in `move-to-mode-line-start', ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux dcd693c 093/112: Rename move-to-mode-line-start to crux-move-to-mode-line-start, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e805ab7 057/112: Use synchronous process for crux-open-with, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 4f5c8fe 059/112: [Fix #46] Address two issues with crux-move-beginning-line (#48), ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 49dc7d7 067/112: Remove unused prefix argument from crux-smart-kill-line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 903db7b 080/112: Add history on crux and links to emacsredux blog posts, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux ba4a1f3 098/112: Restructure the README a bit, ELPA Syncer, 2021/08/11