Code Monkey home page Code Monkey logo

Comments (6)

awitherow avatar awitherow commented on May 17, 2024 1

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.

awitherow avatar awitherow commented on May 17, 2024 1

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.

rcoedo avatar rcoedo commented on May 17, 2024

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.

awitherow avatar awitherow commented on May 17, 2024

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.

awitherow avatar awitherow commented on May 17, 2024

@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.

rcoedo avatar rcoedo commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.