summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarthik Chikmagalur <karthikchikmagalur@gmail.com>2023-06-04 22:00:25 -0700
committerMagnar Sveen <magnars@gmail.com>2024-01-04 18:21:33 +0100
commite1b099a62ff3c718d1bd8a100f516b3dff035dd2 (patch)
treeea874f63f62249761b50bc4a7ce2e4ac5a488dee
parent9e3f86c02c5e2ab6f0d95da8a34045b54f6166d1 (diff)
expand-region-core: Fix excursions when expensive
expand-region-core.el (er--expand-region-1, er--save-excursion): When `er-save-excursion` is expensive, such as when using Org-mode's `org-save-outline-visibility`, calling it repeatedly for each function in `er/try-expand-list' is prohibitive. Fix by only calling it once around the expansion trials, and using `save-mark-and-excursion` around each expansion function.
-rw-r--r--expand-region-core.el26
1 files changed, 13 insertions, 13 deletions
diff --git a/expand-region-core.el b/expand-region-core.el
index c239fd1..1f60dbe 100644
--- a/expand-region-core.el
+++ b/expand-region-core.el
@@ -72,8 +72,7 @@
`(save-excursion ,@body))))
(defmacro er--save-excursion (&rest body)
- `(let ((action (lambda ()
- (save-mark-and-excursion ,@body))))
+ `(let ((action (lambda () ,@body)))
(if er/save-mode-excursion
(funcall er/save-mode-excursion action)
(funcall action))))
@@ -109,17 +108,18 @@ moving point or mark as little as possible."
(skip-chars-forward er--space-str)
(setq start (point)))
- (while try-list
- (er--save-excursion
- (ignore-errors
- (funcall (car try-list))
- (when (and (region-active-p)
- (er--this-expansion-is-better start end best-start best-end))
- (setq best-start (point))
- (setq best-end (mark))
- (when (and er--show-expansion-message (not (minibufferp)))
- (message "%S" (car try-list))))))
- (setq try-list (cdr try-list)))
+ (er--save-excursion
+ (while try-list
+ (ignore-errors
+ (save-mark-and-excursion
+ (funcall (car try-list))
+ (when (and (region-active-p)
+ (er--this-expansion-is-better start end best-start best-end))
+ (setq best-start (point))
+ (setq best-end (mark))
+ (when (and er--show-expansion-message (not (minibufferp)))
+ (message "%S" (car try-list))))))
+ (setq try-list (cdr try-list))))
(setq deactivate-mark nil)
;; if smart cursor enabled, decide to put it at start or end of region: