Fork me on GitHub
#emacs
<
2019-01-23
>
theeternalpulse19:01:03

I made a function as such

(defun user-prettier-eslint ()
    "Format the current file with ESLint."
    (interactive)
    (let* ((binary (executable-find "prettier-eslint_d"))
           (command (format "cat %s | %s --stdin | tee %s" buffer-file-name binary buffer-file-name)))
      (progn
        ;;(save-buffer)
        (shell-command command "*test-buffer*" "*prettier-eslint-errors*")
        (revert-buffer t t t))))

  ;; ===prettier-eslint
  (add-hook 'js2-mode-hook (lambda () (add-hook 'after-save-hook 'user-prettier-eslint nil t)))
  (add-hook 'web-mode-hook (lambda () (add-hook 'after-save-hook 'user-prettier-eslint nil t)))
and noticed that sometimes after saving a blank file is fed into the command. I uncommented the (save-buffer) to resolve it, but it seems redundant. I'm not sure if the blank content is some thing I have to wait for emacs to finish saving but wondering what the issue is.

vemv19:01:14

could it be that your defun is being invoked N times per save? I think those hooks might pile up as you open more and more files

vemv19:01:26

also, the commented-out save-buffer would end up triggering your hook again, right? seems recursive

theeternalpulse19:01:32

I thought so, but it doens't seem to since the doc says

Add to the value of HOOK the function FUNCTION.
FUNCTION is not added if already present.
FUNCTION is added (if necessary) at the beginning of the hook list
unless the optional argument APPEND is non-nil, in which case
FUNCTION is added at the end.

👍 5
theeternalpulse20:01:12

going to restart to see if I can reproduce

theeternalpulse22:01:10

seems this is happening randomly with the command itself, some calls to cat somefile.js | prettier-eslint_d --stdin gives a blank result

vemv22:01:47

ah, nasty!

theeternalpulse22:01:02

seems to work when I use prettier-js and set the command to prettier-eslint_d.

theeternalpulse22:01:01

I filed an issue in the meantime, not sure if it's some weird piping issue or the command with that argument