Skip to main content
edited tags
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257
edited title
Link
emonigma
  • 2k
  • 14
  • 34

Query-replace stops after first item in dolistwhile

Format code
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47

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 set
Replaced 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?

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 set
Replaced 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?

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 set
Replaced 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?

Source Link
emonigma
  • 2k
  • 14
  • 34
Loading