Function: query-replace-read-transpose-from-to

query-replace-read-transpose-from-to is an interactive and byte-compiled function defined in replace.el.gz.

Signature

(query-replace-read-transpose-from-to)

Documentation

Transpose the FROM and TO arguments of a query-replace operation.

If there is an active region in the minibuffer, transpose only those parts of FROM and TO that intersect with the active region, or complete TO or FROM if the active region only intersects with FROM or TO, respectively. For example, if '[...]' denotes the active region, this function would transpose '\<[foo]\> -> bar' to '\<bar\> -> foo'.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/replace.el.gz
(defun query-replace-read-transpose-from-to ()
  "Transpose the FROM and TO arguments of a `query-replace' operation.
If there is an active region in the minibuffer, transpose only those
parts of FROM and TO that intersect with the active region, or complete
TO or FROM if the active region only intersects with FROM or TO,
respectively.
For example, if '[...]' denotes the active region, this function would
transpose '\\=\\<[foo]\\> -> bar' to '\\=\\<bar\\> -> foo'."
  (interactive)
  (let* ((from-beg (minibuffer-prompt-end))
         (from-end (next-single-property-change from-beg 'separator))
         (to-beg   (and from-end
                        (next-single-property-change from-end 'separator)))
         (to-end   (point-max))
         (beg      (use-region-beginning))
         (end      (use-region-end)))
    (cond
     ((or (not from-end) (not to-beg))
      (user-error "No query-replace separator to transpose around"))
     ((or (not beg) (not end))
      (transpose-regions from-beg from-end to-beg to-end))
     (t
      ;; Calculate intersection of FROM and TO with active region.
      (when (< from-beg beg from-end) (setq from-beg beg))
      (when (< from-beg end from-end) (setq from-end end))
      (when (< to-beg beg to-end)     (setq to-beg beg))
      (when (< to-beg end to-end)     (setq to-end end))
      (transpose-regions from-beg from-end to-beg to-end)))))