From: Christian Heller Date: Mon, 11 Feb 2019 02:10:07 +0000 (+0100) Subject: Emulate Vim's Y more fully. X-Git-Url: https://plomlompom.com/repos/reset_cookie?a=commitdiff_plain;h=6ea767416e40c7590cccf7b865e098f3fb553daa;p=plomvi.el Emulate Vim's Y more fully. --- diff --git a/plomvi.el b/plomvi.el index 577e674..34524fd 100644 --- a/plomvi.el +++ b/plomvi.el @@ -170,14 +170,31 @@ Note that this ignores killed rectangles." (interactive) (search-backward isearch-string)) - -(defun plomvi-copy-line() - "Copy current line into kill buffer." +(defun plomvi-Y() + "Copy rectangle, or full line, or region in full lines." (interactive) - (let ((keep_pos (point))) ; We sort of cheat: We kill the line, then we - (kill-whole-line) ; paste it back, and return point to its - (plomvi-paste-backward) ; original position. - (goto-char keep_pos))) ; + (cond + ((and (boundp 'rectangle-mark-mode) (eq t rectangle-mark-mode)) + (copy-rectangle-as-kill (region-beginning) (region-end))) + ((use-region-p) + (let* ((start-start-pos (region-beginning)) + (start-end-pos (region-end)) + (region-start (progn + (goto-char start-start-pos) + (beginning-of-line) + (point))) + (region-end (progn + (goto-char start-end-pos) + (end-of-line) + (+ 1 (point))))) + (copy-region-as-kill region-start region-end) + (goto-char region-start))) + (t + (let ((keep-pos (point)) + (region-start (progn (beginning-of-line) (point))) + (region-end (progn (end-of-line) (+ 1 (point))))) + (copy-region-as-kill region-start region-end) + (goto-char keep-pos))))) (defun plomvi-copy-region() "Copy marked region." @@ -259,7 +276,7 @@ text editing.") (define-key plomvi-mode-editable-map (kbd "I") 'string-insert-rectangle) (define-key plomvi-mode-editable-map (kbd "p") 'plomvi-paste-forward) (define-key plomvi-mode-editable-map (kbd "P") 'plomvi-paste-backward) -(define-key plomvi-mode-editable-map (kbd "Y") 'plomvi-copy-line) +(define-key plomvi-mode-editable-map (kbd "Y") 'plomvi-Y) (define-key plomvi-mode-editable-map (kbd "y") 'plomvi-copy-region) (define-key plomvi-mode-editable-map (kbd "D") 'plomvi-region-kill) (define-prefix-command 'plomvi-d-map)