Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions jsonian-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -832,5 +832,31 @@ If START and END are provided, they are set as point and mark."
(should (equal b (current-buffer)))
(should (string= (buffer-string) json-string)))))

(ert-deftest jsonian-edit-string-hook ()
"Test `jsonian-edit-string' moves to a new buffer and then returns correctly."
(with-temp-buffer
(let* ((json-string "{\"key\": \"some complex value\\nwith new lines\"}")
(b (current-buffer))
(edit-buffer nil)
(hook-fn (lambda ()
(should (string= "some complex value\nwith new lines" (buffer-string)))
(should (not (equal (current-buffer) b)))
(setq edit-buffer (current-buffer))
(text-mode))))
(add-hook 'jsonian-edit-string-hook hook-fn)
(jsonian-mode)
(insert json-string)
(goto-char 10) ;; Move the point into the "complex" string
(jsonian-edit-string)
(should (eq major-mode 'text-mode))
(should (equal (current-buffer) edit-buffer))
(delete-region (point-min) (point-max))
(insert "some new value")
(jsonian-edit-mode-return)
(should (equal b (current-buffer)))
(should (string= (buffer-string) "{\"key\": \"some new value\"}"))
(should (eq major-mode 'jsonian-mode))
(remove-hook 'jsonian-edit-string-hook hook-fn))))

(provide 'jsonian-tests)
;;; jsonian-tests.el ends here
6 changes: 6 additions & 0 deletions jsonian.el
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@ POS must be a valid node location."
(defvar-local jsonian-edit-return-var nil
"Information necessary to jump back from `jsonian--edit-mode'.")

(defvar jsonian-edit-string-hook nil
"A normal hook run when `jsonian-edit-string' is called.

It is run in the context of the edit buffer.")

(defun jsonian-edit-string ()
"Edit the string at point in another buffer."
(interactive)
Expand All @@ -1100,6 +1105,7 @@ POS must be a valid node location."
(insert text)
(jsonian--unintern-special-chars (current-buffer))
(goto-char (point-min))
(run-hooks 'jsonian-edit-string-hook)
(setq-local jsonian-edit-return-var (make-jsonian--edit-return
:match match
:back-buffer cbuffer
Expand Down