From: Mattias EngdegÄrd Date: Sat, 24 Aug 2024 13:00:32 +0000 (+0200) Subject: Faster region-beginning and region-end for rectangle selections X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=457c61eb435e5698d1bdf9963d0f445f63d976c4;p=emacs.git 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. (cherry picked from commit 3a8222e700304e4dff84fcdfa8ff2a4e48646c82) --- 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'." ((not rectangle-mark-mode) (funcall orig)) (t - (apply #'min (mapcar #'car (region-bounds)))))) + (save-excursion + (let* ((pt (point)) + (mk (mark)) + (start (min pt mk)) + (end (max pt mk)) + (cols (rectangle--pos-cols start end)) + (startcol (car cols)) + (endcol (cdr cols))) + (goto-char start) + (move-to-column (min startcol endcol)) + (point)))))) (defun rectangle--region-end (orig) "Like `region-end' but supports rectangular regions." @@ -774,7 +784,17 @@ Ignores `line-move-visual'." ((not rectangle-mark-mode) (funcall orig)) (t - (apply #'max (mapcar #'cdr (region-bounds)))))) + (save-excursion + (let* ((pt (point)) + (mk (mark)) + (start (min pt mk)) + (end (max pt mk)) + (cols (rectangle--pos-cols start end)) + (startcol (car cols)) + (endcol (cdr cols))) + (goto-char end) + (move-to-column (max startcol endcol)) + (point)))))) (defun rectangle--extract-region (orig &optional delete) (cond