Emacs: Escape Quotes Command
This page shows a emacs command to escape/unescape quotes.
For example,
"xyz"
becomes
\"xyz\"
This is very useful when coding lisp to process other languages.
For example, when you have this x = "…"
, and you want (search-forward "x = \"…\"")
Here's the code.
(defun xah-escape-quotes (@begin @end) "Replace 「\"」 by 「\\\"」 in current line or text selection. See also: `xah-unescape-quotes' URL `http://ergoemacs.org/emacs/elisp_escape_quotes.html' Version 2017-01-11" (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)) (while (search-forward "\"" nil t) (replace-match "\\\"" "FIXEDCASE" "LITERAL")))))
(defun xah-unescape-quotes (@begin @end) "Replace 「\\\"」 by 「\"」 in current line or text selection. See also: `xah-escape-quotes' URL `http://ergoemacs.org/emacs/elisp_escape_quotes.html' Version 2017-01-11" (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)) (while (search-forward "\\\"" nil t) (replace-match "\"" "FIXEDCASE" "LITERAL")))))
You can assign keys to them. [see Emacs: How to Define Keys]
Emacs Text Transform Under Cursor
- Toggle Letter Case
- Title Case
- Upcase Sentences
- Cycle Space Hyphen Underscore
- Escape Quotes
- Quote Lines
- Spaces to New Lines
- Change Brackets/Quotes
- Remove Accent Marks
- Convert Straight/Curly Quotes
- Convert English/Chinese Punctuations
- Color Conversion (RGB, HSL, HSV)
- Decimal to Hexadecimal
- Replace Greek Letter Names to Unicode
- Twitterfy Text
- Toggle line wrap
- Clean White Space
If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard:
Best Keyboards for Emacs