diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2019-03-16 16:56:36 +0000 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2019-03-16 16:56:36 +0000 |
| commit | 0a83a7b028881a7a463ba5dfc7646ca98afc48c7 (patch) | |
| tree | 1ff13a3d3ee7b9255da8cbfa3040f6e9b327d722 /helpful.el | |
| parent | ade085ac805845f70d5b46acca552071f42782cb (diff) | |
Ensure backslashes in string literals are escaped
Fixes #197
Diffstat (limited to 'helpful.el')
| -rw-r--r-- | helpful.el | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -969,15 +969,19 @@ unescaping too." (while (not (eobp)) (cond ((looking-at - (rx "\"")) - (looking-at ;; Text of the form "foo" (rx "\"")) - ;; Don't do anything with literal strings. - ;; Step over opening doublequote. - (forward-char 1) - ;; Move past closing doublequote. - (search-forward "\"")) + ;; For literal strings, escape backslashes so our output + ;; shows copy-pasteable literals. + (let* ((start-pos (point)) + (end-pos (progn (forward-char) (search-forward "\"" nil t))) + contents) + (if end-pos + (progn + (setq contents (buffer-substring start-pos end-pos)) + (delete-region start-pos end-pos) + (insert (s-replace "\\" "\\\\" contents))) + (forward-char 1)))) ((looking-at ;; Text of the form \=X (rx "\\=")) |
