prettier / prettier-emacs

Minor mode to format JS code on file save

Home Page:http://jlongster.com/A-Prettier-Formatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Customize path?

JuanCaicedo opened this issue · comments

Hi there! Would it be possible to support customizing the path to prettier?

I ask because I tend to locally install dev dependencies instead of globally. I get this at my emacs prompt

$ which prettier
# ./node_modules/.bin/prettier

However if I execute prettier-js I get

helm-M-x: Searching for program: No such file or directory, prettier

If it would be possible to support this, I'm willing to help 😃

I believe you may be able to do this already via the prettier-js-command defcustom 😄

Yes that worked well! I haven't been able to find a way to configure it globally, but for now I added a .dir-locals.el for the projects that use prettier

((nil
  (prettier-js-command
   .
   "/Users/JuanCaicedo/code/some-project/node_modules/\.bin/prettier")))

Although actually I get a command saying that it's not a safe variable. Maybe it should be marked as safe in the defcustom?

Is it possible for this to lean on https://github.com/codesuki/add-node-modules-path -- it seems undesirable when working in teams b/c the path is hard-coded.

I didn't know about that one @rymndhng, seems like the way to solve this. I'm going to start using it too, thanks!

@JuanCaicedo I have 0 knowledge of that part of emacs, but I tried customizing the variable via custom.el and it doesn't say it's unsafe for me.

If you have experience with defining customs, a PR would be appreciated!

Actually it does work out of the box! I am able to get this working by adding both hooks in my init.el, i.e for typescript:

(eval-after-load 'typescript-mode
    '(progn
       (add-hook 'typescript-mode-hook #'add-node-modules-path)
       (add-hook 'typescript-mode-hook #'prettier-js-mode)))

@rcoedo What do you think about adding that this to the README as a tip.

@rymndhng I think it can be very useful. Also, I'm adding this to my config right now 😄

Thanks!

FYI: I had the same issue and fixed by updating my emacs exec-path.

(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
    (setq exec-path (append exec-path '("/usr/local/bin")))