|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
;; This file:
;; http://anggtwu.net/elisp/query-replace-list-1.el.html
;; http://anggtwu.net/elisp/query-replace-list-1.el
;; (find-angg "elisp/query-replace-list-1.el")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;;
;; `query-replace-list', version 1.
;; Based on this question:
;; https://lists.gnu.org/archive/html/help-gnu-emacs/2023-12/msg00064.html
;; Superseded by:
;; (find-eev "eev-qrl.el")
;;
;; (eval-buffer)
;; (load (buffer-file-name))
;; (defun e () (interactive) (find-angg "elisp/query-replace-list-1.el"))
;;
;; High-level tests:
;; (find-elinks-elisp '((qrl "from1" "to1" "from2" "to2") "from2from1"))
;; (find-elinks-elisp '((qrl "a" "bb" "b" "aa") "abcde"))
;; (find-elinks-elisp '((qrl) "{\"foo\"}"))
;; Low-level tests:
;; (ee-qrl-as)
;; (ee-qrl-regexp)
;; (ee-qrl-r0 "{")
;; (ee-qrl-r1 "foo\\&bar")
;; (ee-qrl-r2 "\\")
(defvar ee-qrl-plist0
'("\"" "\\\""
"\\" "\\\\"
"{" "{<}"
"}" "{>}"))
(defvar ee-qrl-plist ee-qrl-plist0)
(defun ee-qrl-as () (cl-loop for (a b) on ee-qrl-plist by 'cddr collect a))
(defun ee-qrl-regexp () (mapconcat 'regexp-quote (ee-qrl-as) "\\|"))
(defun ee-qrl-r0 (s) (plist-get ee-qrl-plist (ee-no-properties s) 'equal))
(defun ee-qrl-r1 (s) (replace-regexp-in-string "\\\\" "\\\\\\\\" s))
(defun ee-qrl-r2 (s) (ee-qrl-r1 (ee-qrl-r0 s)))
(defun ee-qrl-r3 (a b) (ee-qrl-r2 (match-string 0)))
(defun ee-qrl0 (&rest plist)
(interactive)
(let ((ee-qrl-plist (or plist ee-qrl-plist)))
(query-replace-regexp (ee-qrl-regexp) (list 'ee-qrl-r3 nil))
"Done"))
(defun ee-qrl-narrow (&rest plist)
(interactive)
(save-excursion
(save-restriction
(narrow-to-region (point) (mark))
(goto-char (point-min))
(apply 'ee-qrl0 plist))))
(defun ee-qrl (&rest plist)
(interactive)
(if (region-active-p)
(apply 'ee-qrl-narrow plist)
(apply 'ee-qrl0 plist)))
(defalias 'qrl0 'ee-qrl0)
(defalias 'qrl 'ee-qrl)
;; Local Variables:
;; coding: utf-8-unix
;; End: