summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2018-02-06 23:20:10 +0200
committerJuri Linkov <juri@linkov.net>2018-02-06 23:20:10 +0200
commit31350817ae6eda2e071dbc28f1f1edc50e5f3b0c (patch)
tree60bc5152558543048b7dc6446ca27a13b7091926
parent5c414441ed73f1a302a2953dc493e83b98589262 (diff)
downloademacs-31350817ae6eda2e071dbc28f1f1edc50e5f3b0c.tar.gz
Support occur command operating on the region from Isearch.
* lisp/isearch.el (isearch-occur): Use region-bounds as region arg of occur. (isearch-query-replace): Use use-region-p. * lisp/replace.el (occur--region-start-line): Rename from occur--matches-threshold. (occur): Use complete lines when region is active for line-oriented occur. (occur-engine): Count lines either from occur--region-start-line or 1.
-rw-r--r--lisp/isearch.el9
-rw-r--r--lisp/replace.el14
2 files changed, 13 insertions, 10 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 9297c0f95ba..729f629423c 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1853,11 +1853,11 @@ replacements from Isearch is `M-s w ... M-%'."
(concat "Query replace"
(isearch--describe-regexp-mode (or delimited isearch-regexp-function) t)
(if backward " backward" "")
- (if (and transient-mark-mode mark-active) " in region" ""))
+ (if (use-region-p) " in region" ""))
isearch-regexp)
t isearch-regexp (or delimited isearch-regexp-function) nil nil
- (if (and transient-mark-mode mark-active) (region-beginning))
- (if (and transient-mark-mode mark-active) (region-end))
+ (if (use-region-p) (region-beginning))
+ (if (use-region-p) (region-end))
backward))
(and isearch-recursive-edit (exit-recursive-edit)))
@@ -1920,7 +1920,8 @@ characters in that string."
'isearch-regexp-function-descr
(isearch--describe-regexp-mode isearch-regexp-function))
regexp)
- nlines)))
+ nlines
+ (if (use-region-p) (region-bounds)))))
(declare-function hi-lock-read-face-name "hi-lock" ())
diff --git a/lisp/replace.el b/lisp/replace.el
index 0efd0820966..c6892328d71 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1387,7 +1387,7 @@ invoke `occur'."
;; Region limits when `occur' applies on a region.
(defvar occur--region-start nil)
(defvar occur--region-end nil)
-(defvar occur--matches-threshold nil)
+(defvar occur--region-start-line nil)
(defvar occur--orig-line nil)
(defvar occur--final-pos nil)
@@ -1441,13 +1441,15 @@ is not modified."
(or end (setq end (point-max))))
(let ((occur--region-start start)
(occur--region-end end)
- (occur--matches-threshold
+ (occur--region-start-line
(and in-region-p
(line-number-at-pos (min start end))))
(occur--orig-line
(line-number-at-pos (point))))
(save-excursion ; If no matches `occur-1' doesn't restore the point.
- (and in-region-p (narrow-to-region start end))
+ (and in-region-p (narrow-to-region
+ (save-excursion (goto-char start) (line-beginning-position))
+ (save-excursion (goto-char end) (line-end-position))))
(occur-1 regexp nlines (list (current-buffer)))
(and in-region-p (widen))))))
@@ -1621,7 +1623,7 @@ See also `multi-occur'."
(let ((lines 0) ;; count of matching lines
(matches 0) ;; count of matches
(curr-line ;; line count
- (or occur--matches-threshold 1))
+ (or occur--region-start-line 1))
(orig-line occur--orig-line)
(orig-line-shown-p)
(prev-line nil) ;; line number of prev match endpt
@@ -1754,7 +1756,7 @@ See also `multi-occur'."
(setq orig-line-shown-p t)
(save-excursion
(goto-char (point-min))
- (forward-line (1- orig-line))
+ (forward-line (- orig-line (or occur--region-start-line 1)))
(occur-engine-line (line-beginning-position)
(line-end-position) keep-props)))))
;; Actually insert the match display data
@@ -1792,7 +1794,7 @@ See also `multi-occur'."
(let ((orig-line-str
(save-excursion
(goto-char (point-min))
- (forward-line (1- orig-line))
+ (forward-line (- orig-line (or occur--region-start-line 1)))
(occur-engine-line (line-beginning-position)
(line-end-position) keep-props))))
(add-face-text-property