Add function so/query-swap-strings
This commit is contained in:
parent
b94281446b
commit
d5421a1fdb
@ -15,3 +15,28 @@
|
||||
(list (if current-prefix-arg 'unfill) t)))
|
||||
(let ((fill-column (if unfill (point-max) fill-column)))
|
||||
(fill-paragraph nil region)))
|
||||
|
||||
;; Copied from http://emacs.stackexchange.com/a/27170/507
|
||||
(defun so/query-swap-strings (from-string
|
||||
to-string
|
||||
&optional delimited start end)
|
||||
"Swap occurrences of FROM-STRING and TO-STRING."
|
||||
(interactive
|
||||
(let ((common
|
||||
(query-replace-read-args
|
||||
(concat "Query swap"
|
||||
(if current-prefix-arg
|
||||
(if (eq current-prefix-arg '-) " backward" " word")
|
||||
"")
|
||||
(if (use-region-p) " in region" ""))
|
||||
nil)))
|
||||
(list (nth 0 common) (nth 1 common) (nth 2 common)
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end)))))
|
||||
(perform-replace
|
||||
(concat "\\(" (regexp-quote from-string) "\\)\\|" (regexp-quote to-string))
|
||||
`(replace-eval-replacement replace-quote
|
||||
(if (match-string 1)
|
||||
,to-string
|
||||
,from-string))
|
||||
t t delimited nil nil start end))
|
||||
|
Loading…
Reference in New Issue
Block a user