diff options
| author | Mattias EngdegÄrd | 2024-08-24 15:00:32 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-08-25 13:47:40 +0200 |
| commit | 3a8222e700304e4dff84fcdfa8ff2a4e48646c82 (patch) | |
| tree | 431eebf67dbf160db6b209f23fba7e9c836f7120 | |
| parent | 7319f5e078b6c98379414a4601a269e6581ec206 (diff) | |
| download | emacs-3a8222e700304e4dff84fcdfa8ff2a4e48646c82.tar.gz emacs-3a8222e700304e4dff84fcdfa8ff2a4e48646c82.zip | |
Faster region-beginning and region-end for rectangle selections
* lisp/rect.el (rectangle--region-beginning, rectangle--region-end):
Make these run in O(1), not linear, time and space.
| -rw-r--r-- | lisp/rect.el | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lisp/rect.el b/lisp/rect.el index 0212dedcb48..93007824679 100644 --- a/lisp/rect.el +++ b/lisp/rect.el | |||
| @@ -766,7 +766,17 @@ Ignores `line-move-visual'." | |||
| 766 | ((not rectangle-mark-mode) | 766 | ((not rectangle-mark-mode) |
| 767 | (funcall orig)) | 767 | (funcall orig)) |
| 768 | (t | 768 | (t |
| 769 | (apply #'min (mapcar #'car (region-bounds)))))) | 769 | (save-excursion |
| 770 | (let* ((pt (point)) | ||
| 771 | (mk (mark)) | ||
| 772 | (start (min pt mk)) | ||
| 773 | (end (max pt mk)) | ||
| 774 | (cols (rectangle--pos-cols start end)) | ||
| 775 | (startcol (car cols)) | ||
| 776 | (endcol (cdr cols))) | ||
| 777 | (goto-char start) | ||
| 778 | (move-to-column (min startcol endcol)) | ||
| 779 | (point)))))) | ||
| 770 | 780 | ||
| 771 | (defun rectangle--region-end (orig) | 781 | (defun rectangle--region-end (orig) |
| 772 | "Like `region-end' but supports rectangular regions." | 782 | "Like `region-end' but supports rectangular regions." |
| @@ -774,7 +784,17 @@ Ignores `line-move-visual'." | |||
| 774 | ((not rectangle-mark-mode) | 784 | ((not rectangle-mark-mode) |
| 775 | (funcall orig)) | 785 | (funcall orig)) |
| 776 | (t | 786 | (t |
| 777 | (apply #'max (mapcar #'cdr (region-bounds)))))) | 787 | (save-excursion |
| 788 | (let* ((pt (point)) | ||
| 789 | (mk (mark)) | ||
| 790 | (start (min pt mk)) | ||
| 791 | (end (max pt mk)) | ||
| 792 | (cols (rectangle--pos-cols start end)) | ||
| 793 | (startcol (car cols)) | ||
| 794 | (endcol (cdr cols))) | ||
| 795 | (goto-char end) | ||
| 796 | (move-to-column (max startcol endcol)) | ||
| 797 | (point)))))) | ||
| 778 | 798 | ||
| 779 | (defun rectangle--extract-region (orig &optional delete) | 799 | (defun rectangle--extract-region (orig &optional delete) |
| 780 | (cond | 800 | (cond |