aboutsummaryrefslogtreecommitdiff
path: root/helpful.el
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2019-03-16 16:56:36 +0000
committerWilfred Hughes <me@wilfred.me.uk>2019-03-16 16:56:36 +0000
commit0a83a7b028881a7a463ba5dfc7646ca98afc48c7 (patch)
tree1ff13a3d3ee7b9255da8cbfa3040f6e9b327d722 /helpful.el
parentade085ac805845f70d5b46acca552071f42782cb (diff)
Ensure backslashes in string literals are escaped
Fixes #197
Diffstat (limited to 'helpful.el')
-rw-r--r--helpful.el18
1 files changed, 11 insertions, 7 deletions
diff --git a/helpful.el b/helpful.el
index ef5b66d..4aac2aa 100644
--- a/helpful.el
+++ b/helpful.el
@@ -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 "\\="))