mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 09:14:18 +00:00
Use use-region-beginning/end in replacement commands (bug#45607)
* lisp/isearch.el (isearch-query-replace): Use use-region-beginning and use-region-end. * lisp/textmodes/paragraphs.el (repunctuate-sentences): * lisp/replace.el (query-replace, query-replace-regexp) (map-query-replace-regexp, replace-string, replace-regexp): Add 'interactive-args' to 'declare' and use use-region-beginning, use-region-end, use-region-noncontiguous-p. * lisp/simple.el (use-region-noncontiguous-p): New function. (region-noncontiguous-p): Return more meaningful value.
This commit is contained in:
parent
ad6878005d
commit
40cdbf6dc1
4 changed files with 38 additions and 22 deletions
|
|
@ -2389,8 +2389,7 @@ type \\[help-command] at that time."
|
|||
(if (use-region-p) " in region" ""))
|
||||
isearch-regexp)
|
||||
t isearch-regexp (or delimited isearch-regexp-function) nil nil
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end))
|
||||
(use-region-beginning) (use-region-end)
|
||||
backward))
|
||||
(and isearch-recursive-edit (exit-recursive-edit)))
|
||||
|
||||
|
|
|
|||
|
|
@ -448,6 +448,10 @@ Arguments FROM-STRING, TO-STRING, DELIMITED, START, END, BACKWARD, and
|
|||
REGION-NONCONTIGUOUS-P are passed to `perform-replace' (which see).
|
||||
|
||||
To customize possible responses, change the bindings in `query-replace-map'."
|
||||
(declare (interactive-args
|
||||
(start (use-region-beginning))
|
||||
(end (use-region-end))
|
||||
(region-noncontiguous-p (use-region-noncontiguous-p))))
|
||||
(interactive
|
||||
(let ((common
|
||||
(query-replace-read-args
|
||||
|
|
@ -461,10 +465,9 @@ To customize possible responses, change the bindings in `query-replace-map'."
|
|||
;; These are done separately here
|
||||
;; so that command-history will record these expressions
|
||||
;; rather than the values they had this time.
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end))
|
||||
(use-region-beginning) (use-region-end)
|
||||
(nth 3 common)
|
||||
(if (use-region-p) (region-noncontiguous-p)))))
|
||||
(use-region-noncontiguous-p))))
|
||||
(perform-replace from-string to-string t nil delimited nil nil start end backward region-noncontiguous-p))
|
||||
|
||||
(define-key esc-map "%" 'query-replace)
|
||||
|
|
@ -541,6 +544,10 @@ Use \\[repeat-complex-command] after this command for details.
|
|||
|
||||
Arguments REGEXP, TO-STRING, DELIMITED, START, END, BACKWARD, and
|
||||
REGION-NONCONTIGUOUS-P are passed to `perform-replace' (which see)."
|
||||
(declare (interactive-args
|
||||
(start (use-region-beginning))
|
||||
(end (use-region-end))
|
||||
(region-noncontiguous-p (use-region-noncontiguous-p))))
|
||||
(interactive
|
||||
(let ((common
|
||||
(query-replace-read-args
|
||||
|
|
@ -555,10 +562,9 @@ REGION-NONCONTIGUOUS-P are passed to `perform-replace' (which see)."
|
|||
;; These are done separately here
|
||||
;; so that command-history will record these expressions
|
||||
;; rather than the values they had this time.
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end))
|
||||
(use-region-beginning) (use-region-end)
|
||||
(nth 3 common)
|
||||
(if (use-region-p) (region-noncontiguous-p)))))
|
||||
(use-region-noncontiguous-p))))
|
||||
(perform-replace regexp to-string t t delimited nil nil start end backward region-noncontiguous-p))
|
||||
|
||||
(define-key esc-map [?\C-%] 'query-replace-regexp)
|
||||
|
|
@ -592,6 +598,10 @@ Fourth and fifth arg START and END specify the region to operate on.
|
|||
|
||||
Arguments REGEXP, START, END, and REGION-NONCONTIGUOUS-P are passed to
|
||||
`perform-replace' (which see)."
|
||||
(declare (interactive-args
|
||||
(start (use-region-beginning))
|
||||
(end (use-region-end))
|
||||
(region-noncontiguous-p (use-region-noncontiguous-p))))
|
||||
(interactive
|
||||
(let* ((from (read-regexp "Map query replace (regexp): " nil
|
||||
query-replace-from-history-variable))
|
||||
|
|
@ -603,9 +613,8 @@ Arguments REGEXP, START, END, and REGION-NONCONTIGUOUS-P are passed to
|
|||
(list from to
|
||||
(and current-prefix-arg
|
||||
(prefix-numeric-value current-prefix-arg))
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end))
|
||||
(if (use-region-p) (region-noncontiguous-p)))))
|
||||
(use-region-beginning) (use-region-end)
|
||||
(use-region-noncontiguous-p))))
|
||||
(let (replacements)
|
||||
(if (listp to-strings)
|
||||
(setq replacements to-strings)
|
||||
|
|
@ -665,9 +674,10 @@ which will run faster and will not set the mark or print anything.
|
|||
and TO-STRING is also null.)"
|
||||
(declare (interactive-only
|
||||
"use `search-forward' and `replace-match' instead.")
|
||||
(interactive-args
|
||||
(interactive-args
|
||||
(start (use-region-beginning))
|
||||
(end (use-region-end))))
|
||||
(end (use-region-end))
|
||||
(region-noncontiguous-p (use-region-noncontiguous-p))))
|
||||
(interactive
|
||||
(let ((common
|
||||
(query-replace-read-args
|
||||
|
|
@ -681,7 +691,7 @@ and TO-STRING is also null.)"
|
|||
(list (nth 0 common) (nth 1 common) (nth 2 common)
|
||||
(use-region-beginning) (use-region-end)
|
||||
(nth 3 common)
|
||||
(if (use-region-p) (region-noncontiguous-p)))))
|
||||
(use-region-noncontiguous-p))))
|
||||
(perform-replace from-string to-string nil nil delimited nil nil start end backward region-noncontiguous-p))
|
||||
|
||||
(defun replace-regexp (regexp to-string &optional delimited start end backward region-noncontiguous-p)
|
||||
|
|
@ -746,7 +756,11 @@ What you probably want is a loop like this:
|
|||
(replace-match TO-STRING nil nil))
|
||||
which will run faster and will not set the mark or print anything."
|
||||
(declare (interactive-only
|
||||
"use `re-search-forward' and `replace-match' instead."))
|
||||
"use `re-search-forward' and `replace-match' instead.")
|
||||
(interactive-args
|
||||
(start (use-region-beginning))
|
||||
(end (use-region-end))
|
||||
(region-noncontiguous-p (use-region-noncontiguous-p))))
|
||||
(interactive
|
||||
(let ((common
|
||||
(query-replace-read-args
|
||||
|
|
@ -758,10 +772,9 @@ which will run faster and will not set the mark or print anything."
|
|||
(if (use-region-p) " in region" ""))
|
||||
t)))
|
||||
(list (nth 0 common) (nth 1 common) (nth 2 common)
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end))
|
||||
(use-region-beginning) (use-region-end)
|
||||
(nth 3 common)
|
||||
(if (use-region-p) (region-noncontiguous-p)))))
|
||||
(use-region-noncontiguous-p))))
|
||||
(perform-replace regexp to-string nil t delimited nil nil start end backward region-noncontiguous-p))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6878,6 +6878,10 @@ point otherwise."
|
|||
"Return the end of the region if `use-region-p'."
|
||||
(and (use-region-p) (region-end)))
|
||||
|
||||
(defun use-region-noncontiguous-p ()
|
||||
"Return non-nil for a non-contiguous region if `use-region-p'."
|
||||
(and (use-region-p) (region-noncontiguous-p)))
|
||||
|
||||
(defun use-region-p ()
|
||||
"Return t if the region is active and it is appropriate to act on it.
|
||||
This is used by commands that act specially on the region under
|
||||
|
|
@ -6922,7 +6926,7 @@ see `region-noncontiguous-p' and `extract-rectangle-bounds'."
|
|||
"Return non-nil if the region contains several pieces.
|
||||
An example is a rectangular region handled as a list of
|
||||
separate contiguous regions for each line."
|
||||
(cdr (region-bounds)))
|
||||
(let ((bounds (region-bounds))) (and (cdr bounds) bounds)))
|
||||
|
||||
(defun redisplay--unhighlight-overlay-function (rol)
|
||||
"If ROL is an overlay, call `delete-overlay'."
|
||||
|
|
|
|||
|
|
@ -514,9 +514,9 @@ Second and third arg START and END specify the region to operate on.
|
|||
If optional argument NO-QUERY is non-nil, make changes without asking
|
||||
for confirmation. You can use `repunctuate-sentences-filter' to add
|
||||
filters to skip occurrences of spaces that don't need to be replaced."
|
||||
(interactive (list nil
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end))))
|
||||
(declare (interactive-args (start (use-region-beginning))
|
||||
(end (use-region-end))))
|
||||
(interactive (list nil (use-region-beginning) (use-region-end)))
|
||||
(let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +")
|
||||
(to-string "\\1\\2\\3 "))
|
||||
(if no-query
|
||||
|
|
|
|||
Loading…
Reference in a new issue