Skip to content

Commit

Permalink
Inhibit fixing up after destringify
Browse files Browse the repository at this point in the history
  • Loading branch information
taku0 committed Jun 1, 2024
1 parent 44f7e93 commit ed299df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
16 changes: 11 additions & 5 deletions json-par-insert.el
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ START is the start position of the object."
((use-region-p)
(json-par-stringify-region (region-beginning) (region-end)))


;; Inside a string
((save-excursion (nth 3 (setq parser-state (syntax-ppss))))
(cond
Expand Down Expand Up @@ -620,7 +619,9 @@ If the region is active, unwrap all strings in it.
Otherwise, unwrap the nearest string.
Escaped characters in the strings are unescaped."
Escaped characters in the strings are unescaped.
Inhibit fixing up until next modification."
(interactive)
(let* ((parser-state (save-excursion (syntax-ppss)))
(current-atom (json-par--current-atom parser-state))
Expand Down Expand Up @@ -678,10 +679,12 @@ Escaped characters in the strings are unescaped."
(push #'json-par-destringify json-par--fixup-adviced-functions)

(defun json-par-destringify-region (start end)
"Unwrap strings in the region from START to END.
"Unwrap strings overlapping the region from START to END.
Escaped characters in the strings are unescaped.
Inhibit fixing up until next modification.
Return the end position."
(interactive "r")
(save-excursion
Expand Down Expand Up @@ -711,14 +714,17 @@ Return the end position."
(push #'json-par-destringify-region json-par--fixup-adviced-functions)

(defun json-par--destringify-after ()
"Unwrap a string just after the point."
"Unwrap a string just after the point.
Inhibit fixing up until next modification."
(let ((start (point-marker))
(end (save-excursion (json-par-forward-token) (point-marker))))
(goto-char end)
(delete-char -1)
(goto-char start)
(delete-char 1)
(goto-char (json-par-unescape-region-for-string start end))))
(goto-char (json-par-unescape-region-for-string start end))
(setq json-par--inhibit-fixup-tick (buffer-chars-modified-tick))))

(defun json-par--insert-key-or-value (value)
"Insert VALUE as a key or a value.
Expand Down
18 changes: 8 additions & 10 deletions test/json-files/editing/insert_double_quotes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1695,8 +1695,8 @@
// action: (json-par-insert-double-quotes t)
// expected-start
[
/*|*/"", \, /, , ,
, 😀
/*|*/""\/
😀
]
// expected-end
// test-end
Expand Down Expand Up @@ -1735,8 +1735,7 @@
// action: (json-par-insert-double-quotes t)
// expected-start
[
"\"abc\"",/*|*/
"abc"
"\"abc\""/*|*/"abc"
]
// expected-end
// test-end
Expand All @@ -1750,7 +1749,7 @@
// action: (json-par-insert-double-quotes t)
// expected-start
[
"abc", /*|*/
"abc" /*|*/
"\"abc\""
]
// expected-end
Expand All @@ -1765,7 +1764,7 @@
// action: (json-par-insert-double-quotes t)
// expected-start
[
"\"abc\"",
"\"abc\""
/*|*/ "abc"
]
// expected-end
Expand All @@ -1780,8 +1779,7 @@
// FIXME: should the point be adjusted?
// expected-start
[
"\"abc\"",
/*|*/ "abc"
"\"abc\"", /*|*/ "abc"
]
// expected-end
// test-end
Expand All @@ -1797,7 +1795,7 @@
// action: (json-par-insert-double-quotes t)
// expected-start
[
"\"abc\"",
"\"abc\""
/*|*/
"abc"
]
Expand All @@ -1814,7 +1812,7 @@
// action: (json-par-insert-double-quotes t)
// expected-start
[
"abc",
"abc"
/*|*/
1
]
Expand Down

0 comments on commit ed299df

Please sign in to comment.