-
-
Save sebasmonia/d0d0286dbf7537cc6a849d6604ccdec6 to your computer and use it in GitHub Desktop.
Toggle between backslashes and forward slashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun toggle-backslash-dwim (&optional start end) | |
"Toggle slashes-backslashes for the active region. | |
If there's no active region START and END, it operates on the | |
current line." | |
(interactive "r") | |
(save-excursion | |
(unless (use-region-p) | |
(cl-destructuring-bind (a . b) | |
(bounds-of-thing-at-point 'line) | |
(setf start a | |
end b))) | |
(with-restriction start end | |
(goto-char start) | |
(if (save-excursion (search-forward "/" nil t)) | |
(while (search-forward "/" nil t) (replace-match "\\\\" 'literal)) | |
(while (search-forward "\\" nil t) (replace-match "/")))))) | |
(global-set-key (kbd "C-c C-/") #'toggle-backslash-dwim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment