Comments (6)
My final package looks as such
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
;; load packages
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(add-to-list 'load-path "~/.emacs.d/lisp/")
;; prettier config
(require 'prettier-js)
(setq prettier-js-args '(
"--trailing-comma" "all"
"--bracket-spacing" "false"
))
;; add hooks
(add-hook 'js2-mode-hook 'prettier-js-mode)
;; custom shit
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages (quote (js2-mode))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
from prettier-emacs.
No worries, I got it working fine @rcoedo just was posting my example above to show how it was working.
I will check out the resources you sent too 👍 thanks!
from prettier-emacs.
Replace
(add-hook 'js2-mode-hook 'prettier-js-mode)
with
(add-hook 'js2-jsx-mode-hook 'prettier-js-mode)
Emacs has two different ways of changing its behavior: major modes and minor modes. There can only be one major mode active in one buffer, but there can be many minor modes.
With (add-to-list 'auto-mode-alist '("\\.jsx?\\'" . js2-jsx-mode))
you are telling emacs to load the major mode js2-jsx-mode
, which is one of the many major modes used to edit javascript and jsx, whenever you open a buffer with a .js
or .jsx
file associated to it.
With (add-hook 'js2-jsx-mode-hook 'prettier-js-mode)
you are saying: ok, I want to hook the minor mode prettier-js-mode
, which is used to reformat your code on save, so it is loaded every time I load js2-jsx-mode
.
In your code you were hooking prettier-js-mode
to the major mode js2-mode
instead, which is another major mode used to edit javascript files, so it wasn't being loaded.
For more info I recommend you this book. Emacs is a quite complex text editor (or IDE?) but once you figure it out, it really makes sense.
I hope this clear things out a bit.
Cheers! 🍻 😄
from prettier-emacs.
Thanks for the succinct explanation!
It still does not be seeming to work unfortunately. I am pretty sure I do not even have any of the packages correctly installed. I am looking into this now and will keep here updated :) and check out the book!
from prettier-emacs.
@rcoedo It was because I had not properly installed the js2 package!
I do not need the jsx mode hook either because I am just using .js files for my react-native views 👍 thanks a bunch for the help 🙇
from prettier-emacs.
Sorry for the late response, I've been on vacation 😄
If you are having problems organising your packages take a look at cask as a package manager and req-package as a package loader.
If you need an example, here is my configuration using both tools 👍
from prettier-emacs.
Related Issues (20)
- How validate and format json HOT 1
- "No such file or directory" "prettier" Error HOT 1
- Using eslint_d to do the same as this package
- [question] "prettier-js is an available obsolete package."
- Disable formatting on save HOT 3
- prettier empties file HOT 1
- Could not apply prettier HOT 1
- diff error on OpenBSD
- prettier-js-mode reformats file even when file is in .prettierignore HOT 3
- "prettier errors: env: node: No such file or directory" HOT 6
- Highlighting "flickering" while applying formatting HOT 2
- Searching for program: No such file or directory, prettier HOT 2
- [warn] Ignored unknown option --stdin HOT 1
- Convenient way to disable per file HOT 1
- No files matching the pattern were found: "false". HOT 2
- Cannot find prettier anywhere HOT 2
- Prettier not formatting typescript file HOT 1
- do not respect .prettierignore
- Not working with prettier 3.0.1 HOT 2
- Handle cloned buffers and give error message when not visiting a file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-emacs.