Xah Talk Show 2021-07-14 emacs lisp, slash backslash, what should be the filepath separator
(defun xah-slash-to-backslash (&optional pos1 pos2)
"Replace slash by backslash on current line or region.
Version 2021-07-14"
(interactive)
(let (p1 p2)
(if pos1
(setq p1 pos1 p2 pos2)
(if (region-active-p)
(setq p1 (region-beginning) p2 (region-end))
(setq p1 (line-beginning-position) p2 (line-end-position))))
(save-restriction
(narrow-to-region p1 p2)
(let ((case-fold-search nil))
(goto-char (point-min))
(while (search-forward "/" nil t)
(replace-match "\\\\"))))))
(defun xah-slash-to-double-backslash (&optional pos1 pos2)
"Replace slash by double backslash on current line or region.
Version 2021-07-14"
(interactive)
(let (p1 p2)
(if pos1
(setq p1 pos1 p2 pos2)
(if (region-active-p)
(setq p1 (region-beginning) p2 (region-end))
(setq p1 (line-beginning-position) p2 (line-end-position))))
(save-restriction
(narrow-to-region p1 p2)
(let ((case-fold-search nil))
(goto-char (point-min))
(while (search-forward "/" nil t)
(replace-match "\\\\\\\\"))))))
(defun xah-double-backslash-to-slash (&optional pos1 pos2)
"Replace double backslash by slash on current line or region.
Version 2021-07-14"
(interactive)
(let (p1 p2)
(if pos1
(setq p1 pos1 p2 pos2)
(if (region-active-p)
(setq p1 (region-beginning) p2 (region-end))
(setq p1 (line-beginning-position) p2 (line-end-position))))
(save-restriction
(narrow-to-region p1 p2)
(let ((case-fold-search nil))
(goto-char (point-min))
(while (search-forward "\\\\" nil t)
(replace-match "/"))))))
xah_talk_show_2021-07-14.txt