Quantcast
Channel: Query-replace stops after first item in while - Emacs Stack Exchange
Viewing all articles
Browse latest Browse all 3

Query-replace stops after first item in while

$
0
0

Following this StackOverflow question, I coded this function to clean up text pasted from other sources, such as Google Docs:

(defun sanitize-md ()"Replace characters."  (interactive "*")  (save-excursion    (let ((replacement-list '(                              ("\\" . "/")                              ("fi" . "fi")                              ("“" . "\"")                              ("”" . "\"")                              )))      (while (let* ((pair (pop replacement-list))                    (to-find (car pair))                    (to-replace (cdr pair)))               (message "%s %s" to-find to-replace)               (query-replace to-find to-replace nil (point-min) (point-max))               )        replacement-list)      )))

My problem is the curly double quote , which I have in a document. When I run this function, I get this in the *Messages* buffer:

\ /Mark setReplaced 0 occurrences

If I remove the line on query-replace, then the *Messages* buffer shows all four pairs. And if I put the double-quote pair as the first element of the list, then it gets replaced.

Why does query-replace stop at the first element of the dolist, and how can I code the replacement of all pairs?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images