Created
October 25, 2023 13:08
-
-
Save dov/a02254789ef1d73f05d916f7a2608753 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-line () | |
"Toggle all forward slashes to backslashes for the current line." | |
(interactive) | |
(save-excursion | |
(if (use-region-p) | |
(setq myBoundaries (cons (region-beginning) (region-end))) | |
(setq myBoundaries (bounds-of-thing-at-point 'line))) | |
(save-restriction | |
(goto-char (car myBoundaries)) | |
(narrow-to-region (car myBoundaries) (cdr myBoundaries)) | |
(if (search-forward "/" nil t) | |
(progn | |
(goto-char (car myBoundaries)) | |
(while (search-forward "/" nil t) (replace-match "\\\\" 'literal))) | |
(progn | |
(goto-char (car myBoundaries)) | |
(while (search-forward "\\" nil t) (replace-match "/"))) | |
) | |
)) | |
(if (use-region-p) | |
(progn | |
(set-mark (car myBoundaries)) | |
(goto-char (cdr myBoundaries))))) | |
(global-set-key [(control x) (control ?\\)] 'toggle-backslash-line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment