[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 07153e4 026/110: Add kill and save region functionality.
From: |
Oleh Krehel |
Subject: |
[elpa] master 07153e4 026/110: Add kill and save region functionality. |
Date: |
Sat, 11 May 2019 10:15:37 -0400 (EDT) |
branch: master
commit 07153e4fb74beb54126506cc0f55393623423dbb
Author: Xu Ma <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add kill and save region functionality.
Fixes #158
---
avy.el | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 114 insertions(+)
diff --git a/avy.el b/avy.el
index 87b298e..a91d270 100644
--- a/avy.el
+++ b/avy.el
@@ -83,6 +83,10 @@ in the avy overlays."
(const avy-copy-region)
(const avy-move-line)
(const avy-move-region)
+ (const avy-kill-whole-line)
+ (const avy-kill-region)
+ (const avy-kill-ring-save-whole-line)
+ (const avy-kill-ring-save-region)
(function :tag "Other command"))
:value-type (repeat :tag "Keys" character)))
@@ -113,6 +117,10 @@ If the commands isn't on the list, `avy-style' is used."
(const avy-copy-region)
(const avy-move-line)
(const avy-move-region)
+ (const avy-kill-whole-line)
+ (const avy-kill-region)
+ (const avy-kill-ring-save-whole-line)
+ (const avy-kill-ring-save-region)
(function :tag "Other command"))
:value-type (choice
(const :tag "Pre" pre)
@@ -1458,6 +1466,112 @@ The window scope is determined by `avy-all-windows' or
(insert text pad))))
;;;###autoload
+(defun avy-kill-region (arg)
+ "Select two lines and kill the region between them.
+
+The window scope is determined by `avy-all-windows' or
+`avy-all-windows-alt' when ARG is non-nil."
+ (interactive "P")
+ (let ((initial-window (selected-window)))
+ (avy-with avy-kill-region
+ (let* ((beg (save-selected-window
+ (list (avy--line arg) (selected-window))))
+ (end (list (avy--line arg) (selected-window))))
+ (cond
+ ((not (numberp (car beg)))
+ (user-error "Fail to select the beginning of region."))
+ ((not (numberp (car end)))
+ (user-error "Fail to select the end of region"))
+ ;; Restrict operation to same window. It's better if it can be
+ ;; different windows but same buffer; however, then the cloned
+ ;; buffers with different narrowed regions might cause problem.
+ ((not (equal (cdr beg) (cdr end)))
+ (user-error "Selected points are not in the same window"))
+ ((< (car beg) (car end))
+ (save-excursion
+ (kill-region
+ (car beg)
+ (progn (goto-char (car end)) (forward-visible-line 1) (point)))))
+ (t
+ (save-excursion
+ (kill-region
+ (progn (goto-char (car beg)) (forward-visible-line 1) (point))
+ (car end)))))))
+ (select-window initial-window)))
+
+;;;###autoload
+(defun avy-kill-ring-save-region (arg)
+ "Select two lines and save the region between them to the kill ring."
+ (interactive "P")
+ (let ((initial-window (selected-window)))
+ (avy-with avy-kill-ring-save-region
+ (let* ((beg (save-selected-window
+ (list (avy--line arg) (selected-window))))
+ (end (list (avy--line arg) (selected-window))))
+ (cond
+ ((not (numberp (car beg)))
+ (user-error "Fail to select the beginning of region."))
+ ((not (numberp (car end)))
+ (user-error "Fail to select the end of region"))
+ ((not (equal (cdr beg) (cdr end)))
+ (user-error "Selected points are not in the same window"))
+ ((< (car beg) (car end))
+ (save-excursion
+ (kill-ring-save
+ (car beg)
+ (progn (goto-char (car end)) (forward-visible-line 1) (point)))))
+ (t
+ (save-excursion
+ (kill-ring-save
+ (progn (goto-char (car beg)) (forward-visible-line 1) (point))
+ (car end)))))))
+ (select-window initial-window)))
+
+;;;###autoload
+(defun avy-kill-whole-line (arg)
+ "Select line and kill the whole selected line.
+
+With a numerical prefix ARG, kill ARG line(s) starting from the
+selected line. If ARG is negative, kill backward.
+
+If ARG is zero, kill the selected line but exclude the trailing
+newline.
+
+\\[universal-argument] 3 \\[avy-kil-whole-line] kill three lines
+starting from the selected line. \\[universal-argument] -3
+
+\\[avy-kill-whole-line] kill three lines backward including the
+selected line."
+ (interactive "P")
+ (let ((initial-window (selected-window)))
+ (avy-with avy-kill-whole-line
+ (let* ((start (avy--line)))
+ (if (not (numberp start))
+ (user-error "Fail to select the line to kill")
+ (save-excursion (goto-char start)
+ (kill-whole-line arg)))))
+ (select-window initial-window)))
+
+;;;###autoload
+(defun avy-kill-ring-save-whole-line (arg)
+ "Select line and Save the whole selected line as if killed, but don’t kill
it.
+
+This command is similar to `avy-kill-whole-line', except that it
+saves the line(s) as if killed, but does not kill it(them)."
+ (interactive "P")
+ (let ((initial-window (selected-window)))
+ (avy-with avy-kill-ring-save-whole-line
+ (let* ((start (avy--line)))
+ (if (not (numberp start))
+ (user-error "Fail to select the line to kill")
+ (save-excursion
+ (let ((kill-read-only-ok t)
+ (buffer-read-only t))
+ (goto-char start)
+ (kill-whole-line arg))))))
+ (select-window initial-window)))
+
+;;;###autoload
(defun avy-setup-default ()
"Setup the default shortcuts."
(eval-after-load "isearch"
- [elpa] master 8556274 045/110: avy.el (avy-org-goto-heading-timer): Simplify, (continued)
- [elpa] master 8556274 045/110: avy.el (avy-org-goto-heading-timer): Simplify, Oleh Krehel, 2019/05/11
- [elpa] master 83859c3 040/110: avy.el: Add new avy-style to use words as sequences, Oleh Krehel, 2019/05/11
- [elpa] master 240d717 041/110: Makefile: Add target checkdoc to check documentation guidelines of lisp files, Oleh Krehel, 2019/05/11
- [elpa] master 3980c03 035/110: avy.el (avy-move-region): Insert in original window, Oleh Krehel, 2019/05/11
- [elpa] master 54bce2c 036/110: avy.el (avy-move-region): Update, Oleh Krehel, 2019/05/11
- [elpa] master 49b070d 042/110: avy-test.el: Fix checkdoc warnings, Oleh Krehel, 2019/05/11
- [elpa] master 228ed97 039/110: avy.el (avy-action-teleport): Add and bind to "t", Oleh Krehel, 2019/05/11
- [elpa] master f2bedee 038/110: Allow "C-h" to delete for avy-goto-char-timer, Oleh Krehel, 2019/05/11
- [elpa] master d609eb9 033/110: Add avy-goto-word-0-below and avy-goto-word-0-above, Oleh Krehel, 2019/05/11
- [elpa] master b8d7163 032/110: avy.el (avy-action-goto): Add raise-frame, Oleh Krehel, 2019/05/11
- [elpa] master 07153e4 026/110: Add kill and save region functionality.,
Oleh Krehel <=
- [elpa] master dd112c8 027/110: avy.el (avy-goto-subword-1): Check char-after, Oleh Krehel, 2019/05/11
- [elpa] master 0c30cdb 034/110: avy.el (avy-action-yank): Add and bind to "y", Oleh Krehel, 2019/05/11
- [elpa] master c911850 031/110: avy.el (avy--overlay-at-full): Fix for visual-line-mode, Oleh Krehel, 2019/05/11
- [elpa] master 5515f28 021/110: Allow using symbols instead of words in word cmds, Oleh Krehel, 2019/05/11
- [elpa] master a911903 029/110: avy.el (avy-goto-word-1): Work for "^A"-"^Z", Oleh Krehel, 2019/05/11
- [elpa] master a5fb936 028/110: avy.el (avy-resume): Make it show up in M-x, Oleh Krehel, 2019/05/11
- [elpa] master 20ecb9b 024/110: Use flyspell if its minor mode is active, Oleh Krehel, 2019/05/11
- [elpa] master b522bfe 023/110: avy.el (avy-resume): Add, Oleh Krehel, 2019/05/11
- [elpa] master e460d7e 025/110: avy.el (flyspell-correct-word-before-point): Declare, Oleh Krehel, 2019/05/11
- [elpa] master 05a5003 022/110: avy.el: Fix linum-related compile warnings, Oleh Krehel, 2019/05/11