branch: elpa/helm
commit e39db6bbf26d6a4b4b4d14140d98b4a254c7e153
Merge: f5159e17b8 de07b116fe
Author: Thierry Volpiatto <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #2535 from renatofdds/master
Fix helm-occur when previous mark is outside active region
---
helm-occur.el | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/helm-occur.el b/helm-occur.el
index 14a831b645..ad269ded43 100644
--- a/helm-occur.el
+++ b/helm-occur.el
@@ -211,11 +211,15 @@ engine beeing completely different and also much faster."
;; When user mark defun with `mark-defun' with intention of
;; using helm-occur on this region, it is relevant to use the
;; thing-at-point located at previous position which have been
- ;; pushed to `mark-ring'.
- (setq def (save-excursion
- (goto-char (setq pos (car mark-ring)))
- (helm-aif (thing-at-point 'symbol) (regexp-quote it))))
- (narrow-to-region (region-beginning) (region-end)))
+ ;; pushed to `mark-ring', if it's within the active region.
+ (let ((beg (region-beginning))
+ (end (region-end))
+ (prev-pos (car mark-ring)))
+ (when (and prev-pos (>= prev-pos beg) (< prev-pos end))
+ (setq def (save-excursion
+ (goto-char (setq pos prev-pos))
+ (helm-aif (thing-at-point 'symbol) (regexp-quote
it)))))
+ (narrow-to-region beg end)))
(unwind-protect
(helm :sources 'helm-source-occur
:buffer "*helm occur*"