Last active
June 8, 2016 08:15
-
-
Save unjello/866f2702d024c6bdb5364c16c3435e47 to your computer and use it in GitHub Desktop.
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 unj-c-stringify (αbegin αend) | |
"Surround current line or each line in region with quotes and escape ones inside | |
based on Xah Lee http://ergoemacs.org/emacs/elisp_escape_quotes.html | |
v2016-06-08" | |
(interactive | |
(if (use-region-p) | |
(list (region-beginning) (region-end)) | |
(list (line-beginning-position) (line-end-position)))) | |
(save-excursion | |
(save-restriction | |
(narrow-to-region αbegin αend) | |
(goto-char (point-min)) | |
(save-excursion | |
(while (search-forward "\"" nil t) | |
(replace-match "\\\"" 'FIXEDCASE 'LITERAL))) | |
(save-excursion (replace-regexp "^" "\"")) | |
(save-excursion (replace-regexp "$" "\\\\n\""))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment