File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -832,5 +832,31 @@ If START and END are provided, they are set as point and mark."
832832 (should (equal b (current-buffer )))
833833 (should (string= (buffer-string ) json-string)))))
834834
835+ (ert-deftest jsonian-edit-string-hook ()
836+ " Test `jsonian-edit-string' moves to a new buffer and then returns correctly."
837+ (with-temp-buffer
838+ (let* ((json-string " {\" key\" : \" some complex value\\ nwith new lines\" }" )
839+ (b (current-buffer ))
840+ (edit-buffer nil )
841+ (hook-fn (lambda ()
842+ (should (string= " some complex value\n with new lines" (buffer-string )))
843+ (should (not (equal (current-buffer ) b)))
844+ (setq edit-buffer (current-buffer ))
845+ (text-mode ))))
846+ (add-hook 'jsonian-edit-string-hook hook-fn)
847+ (jsonian-mode)
848+ (insert json-string)
849+ (goto-char 10 ) ; ; Move the point into the "complex" string
850+ (jsonian-edit-string)
851+ (should (eq major-mode 'text-mode ))
852+ (should (equal (current-buffer ) edit-buffer))
853+ (delete-region (point-min ) (point-max ))
854+ (insert " some new value" )
855+ (jsonian-edit-mode-return)
856+ (should (equal b (current-buffer )))
857+ (should (string= (buffer-string ) " {\" key\" : \" some new value\" }" ))
858+ (should (eq major-mode 'jsonian-mode ))
859+ (remove-hook 'jsonian-edit-string-hook hook-fn))))
860+
835861(provide 'jsonian-tests )
836862; ;; jsonian-tests.el ends here
Original file line number Diff line number Diff line change @@ -1084,6 +1084,11 @@ POS must be a valid node location."
10841084(defvar-local jsonian-edit-return-var nil
10851085 " Information necessary to jump back from `jsonian--edit-mode' ." )
10861086
1087+ (defvar jsonian-edit-string-hook nil
1088+ " A normal hook run when `jsonian-edit-string' is called.
1089+
1090+ It is run in the context of the edit buffer." )
1091+
10871092(defun jsonian-edit-string ()
10881093 " Edit the string at point in another buffer."
10891094 (interactive )
@@ -1100,6 +1105,7 @@ POS must be a valid node location."
11001105 (insert text)
11011106 (jsonian--unintern-special-chars (current-buffer ))
11021107 (goto-char (point-min ))
1108+ (run-hooks 'jsonian-edit-string-hook )
11031109 (setq-local jsonian-edit-return-var (make-jsonian--edit-return
11041110 :match match
11051111 :back-buffer cbuffer
You can’t perform that action at this time.
0 commit comments