From 5e879f9b5cb5785fe266435b45333fd002d2dc05 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 17:36:47 +0200 Subject: [PATCH 1/3] Guard against empty search pattern in 'mc/mark-all-in-region', otherwise it will enter an infinite loop --- mc-mark-more.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index 7e240a1..22110c6 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -270,7 +270,8 @@ With zero ARG, skip the last one and mark next." (case-fold-search nil)) (mc/remove-fake-cursors) (goto-char beg) - (while (search-forward search end t) + (while (and (not (string= search "")) + (search-forward search end t)) (push-mark (match-beginning 0)) (mc/create-fake-cursor-at-point)) (let ((first (mc/furthest-cursor-before-point))) From 8dfe725c4f9684e295b96f2820372766317d53fe Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 23:53:59 +0200 Subject: [PATCH 2/3] Abort immediately when empty search pattern is passed to 'mc/mark-all-in-region' --- mc-mark-more.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index 22110c6..e84d614 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -263,15 +263,16 @@ With zero ARG, skip the last one and mark next." (mc/mark-all-like-this))) ;;;###autoload -(defun mc/mark-all-in-region (beg end) +(defun* mc/mark-all-in-region (beg end) "Find and mark all the parts in the region matching the given search" (interactive "r") (let ((search (read-from-minibuffer "Mark all in region: ")) (case-fold-search nil)) + (when (string= search "") + (return-from mc/mark-all-in-region nil)) (mc/remove-fake-cursors) (goto-char beg) - (while (and (not (string= search "")) - (search-forward search end t)) + (while (search-forward search end t) (push-mark (match-beginning 0)) (mc/create-fake-cursor-at-point)) (let ((first (mc/furthest-cursor-before-point))) From a86daa79ce7fada8e56f20c96c2128ff6ee1d464 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Fri, 6 Sep 2013 09:33:37 +0200 Subject: [PATCH 3/3] Guard with 'if' rather than defun*/return-from --- mc-mark-more.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index e84d614..627b401 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -263,25 +263,26 @@ With zero ARG, skip the last one and mark next." (mc/mark-all-like-this))) ;;;###autoload -(defun* mc/mark-all-in-region (beg end) +(defun mc/mark-all-in-region (beg end) "Find and mark all the parts in the region matching the given search" (interactive "r") (let ((search (read-from-minibuffer "Mark all in region: ")) (case-fold-search nil)) - (when (string= search "") - (return-from mc/mark-all-in-region nil)) - (mc/remove-fake-cursors) - (goto-char beg) - (while (search-forward search end t) - (push-mark (match-beginning 0)) - (mc/create-fake-cursor-at-point)) - (let ((first (mc/furthest-cursor-before-point))) - (if (not first) - (error "Search failed for %S" search) - (mc/pop-state-from-overlay first)))) - (if (> (mc/num-cursors) 1) - (multiple-cursors-mode 1) - (multiple-cursors-mode 0))) + (if (string= search "") + (message "Mark aborted") + (progn + (mc/remove-fake-cursors) + (goto-char beg) + (while (search-forward search end t) + (push-mark (match-beginning 0)) + (mc/create-fake-cursor-at-point)) + (let ((first (mc/furthest-cursor-before-point))) + (if (not first) + (error "Search failed for %S" search) + (mc/pop-state-from-overlay first))) + (if (> (mc/num-cursors) 1) + (multiple-cursors-mode 1) + (multiple-cursors-mode 0)))))) (when (not (fboundp 'set-temporary-overlay-map)) ;; Backport this function from newer emacs versions