web-beautify
web-beautify copied to clipboard
Buffer scrolls on long js files
I have setup web-beautify to run after js2-mode like so:
(eval-after-load 'js2-mode
'(add-hook 'js2-mode-hook
(lambda ()
(add-hook 'before-save-hook 'web-beautify-js-buffer t t))))
Everytime I save, this causes the buffer to scroll, after it's done the cursor is one line from the bottom of the window. This makes using web-beautify very frustrating to use. If it matters, I am using emacs prelude, but had disabled nearly everything debugging this problem.
I did not get this behavior with a similar setup before using emacs prelude. Perhaps there's something else going on in prelude?
I get the same issue here (also using Prelude, latest versions).
I suspect the issue is in the (goto-char p) call here, but I don't see how that could be done otherwise (the lines might have changed a lot due to the refactoring, so some movement is bound to happen...)
(defun web-beautify-format-buffer-1 (program extenstion)
"Internal function of `web-beautify-format-buffer'.
By PROGRAM, format current buffer with EXTENSTION."
(let* ((tmpfile (make-temp-file "web-beautify" nil
(format ".%s" extenstion)))
(outputbufname (format "*web-beautify-%s*" extenstion))
(outputbuf (get-buffer-create outputbufname))
(args (append web-beautify-args (list tmpfile))))
(unwind-protect
(progn
(with-current-buffer outputbuf (erase-buffer))
(write-region nil nil tmpfile)
(if (zerop (apply 'call-process program nil outputbuf nil args))
(let ((p (point)))
(save-excursion
(with-current-buffer (current-buffer)
(erase-buffer)
(insert-buffer-substring outputbuf)))
(goto-char p)
(message "Applied web-beautify")
(kill-buffer outputbuf))
(message (web-beautify-format-error-message outputbufname))
(display-buffer outputbuf)))
(progn
(delete-file tmpfile)))))
Did you manage to work around it ?
@drewwells @phtrivier Sorry for the very very delayed response. This issue is fixed by #9. Please try the latest version of web-beautify
.