simple modifications to non-unitary defuns. kill-right-rectangle function does what you want. I am sure there is a much better way to do this. However, it works.
Two points relative to the following code.
- Since the idea is to bring the text to the end of the line, you donβt even need to specify the last column. just mark on the first line (in your example, specify "f") and go to the third line to call the "3" function. (we only need one column, so no need to move the cursor to the right)
- this does not work if the buffer is read-only. its just not implemented.
(defun end-column (POINT) "returns end column" (save-excursion (goto-char POINT) (move-end-of-line 1) (current-column))) (defun apply-on-right-rectangle (function start end &rest args) (let (startcol startpt endcol endpt final-point) (save-excursion (goto-char start) (setq startcol (current-column)) (beginning-of-line) (setq startpt (point)) (goto-char end) (setq endcol (current-column)) (forward-line 1) (setq endpt (point-marker)) ;; ensure the start column is the left one. (if (< endcol startcol) (let ((col startcol)) (setq startcol endcol endcol col))) ;; start looping over lines (goto-char startpt) (while (< (point) endpt) (setq endcol (end-column (point))) (apply function startcol endcol args) (setq final-point (point)) (forward-line 1))) final-point)) (defun delete-extract-right-rectangle (start end &optional fill) (let ((lines (list nil))) (apply-on-right-rectangle 'delete-extract-rectangle-line start end lines fill) (nreverse (cdr lines)))) (defun kill-right-rectangle (start end &optional fill) (interactive "r\nP") (condition-case nil (setq killed-rectangle (delete-extract-right-rectangle start end fill)) ((buffer-read-only text-read-only) (setq killed-rectangle (extract-rectangle start end)) (if kill-read-only-ok (progn (message "Read only text copied to kill ring") nil) (barf-if-buffer-read-only) (signal 'text-read-only (list (current-buffer)))))))
source share