diff --git a/jsfmt.el b/jsfmt.el index 57fdffe..4b0534c 100644 --- a/jsfmt.el +++ b/jsfmt.el @@ -113,25 +113,26 @@ buffer." ;; We're using errbuf for the mixed stdout and stderr output. This ;; is not an issue because jsfmt --write does not produce any stdout ;; output in case of success. - (if save + (let (success) + (if save + (if ast + (setq success (zerop (call-process jsfmt-command nil errbuf nil "--save-ast" "--write" tmpfile))) + (setq success (zerop (call-process jsfmt-command nil errbuf nil "--write" tmpfile)))) (if ast - (setq success (zerop (call-process jsfmt-command nil errbuf nil "--save-ast" "--write" tmpfile))) - (setq success (zerop (call-process jsfmt-command nil errbuf nil "--write" tmpfile)))) - (if ast - (setq success (zerop (call-process jsfmt-command nil errbuf nil "--ast" "--write" tmpfile))) + (setq success (zerop (call-process jsfmt-command nil errbuf nil "--ast" "--write" tmpfile))) + (setq success nil)) (setq success nil)) - (setq success nil)) - - (if 'success - (if (zerop (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-" tmpfile)) - (progn - (kill-buffer errbuf) - (message "Buffer is already jsfmted")) - (js--apply-rcs-patch patchbuf) - (kill-buffer errbuf) - (message "Applied jsfmt")) - (message "Could not apply jsfmt. Check errors for details") - (jsfmt--process-errors (buffer-file-name) tmpfile errbuf)) + + (if success + (if (zerop (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-" tmpfile)) + (progn + (kill-buffer errbuf) + (message "Buffer is already jsfmted")) + (js--apply-rcs-patch patchbuf) + (kill-buffer errbuf) + (message "Applied jsfmt")) + (message "Could not apply jsfmt. Check errors for details") + (jsfmt--process-errors (buffer-file-name) tmpfile errbuf))) (kill-buffer patchbuf) (delete-file tmpfile)))