write a xah-replace-invisible-char-in-dir similar to xah-replace-invisible-char
(defunxah-replace-invisible-char-in-dir (XdirXregex)
"Replace invisible chars in all files in a dir.
Similar to `xah-replace-invisible-char'
todo.
• by default, shouldn't remove many of the invisible chars. e.g. RIGHT-TO-LEFT MARK. it can damage the text. so, use with care or change the replace list
• if the file is not changed, close it
• add a option to save backup
• use with-temp-file instead find-file because the latter is super slow, it invoke syntax coloring and lots hooks. however, you lose the syntax coloring
Created: 2025-02-04
Version: 2025-02-04"
(interactive)
(let (xfilelist)
(setqxfilelist (directory-files-recursivelyXdirXregexnil (lambda (x) (not (string-match-p"/\\."x)))))
(mapc
(lambda (x)
(let ((case-replacenil)
(case-fold-searchnil)
(xregex
(regexp-opt
(mapcar (lambda (x) (char-to-string (carx))) xah-replace-invisible-char-list)))
xresult
)
(find-filex)
(goto-char (point-min))
(while (re-search-forwardxregexnilt)
(let (xcharIdxname)
(setqxcharId (string-to-char (match-string 0)))
(setqxname (get-char-code-propertyxcharId 'name))
(replace-match"")
(push (vectorxnamexcharId (orbuffer-file-name (buffer-name)) (point)) xresult)
(overlay-put (make-overlay (point) (progn (forward-word) (point))) 'face 'font-lock-warning-face)))))
xfilelist)))
;; (xah-replace-invisible-char-in-dir "c:/Users/xah/.emacs.d/temp/" "txt$")