Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add npm-mode key bindings to TypeScript layer #16378

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.develop
Original file line number Diff line number Diff line change
Expand Up @@ -3816,6 +3816,16 @@ files (thanks to Daniel Nicolai)
=typescript/jump-to-type-def= (thanks to Roy Choo)
- ~SPC m r i~ to organize imports (thanks to Stéphane Bisinger)
- ~SPC m r f~ to rename file (thanks to Stéphane Bisinger)
- Added =npm-mode= key bindings:
- ~SPC m n i~ to run the =npm install= command in the project root
- ~SPC m n r~ to show a list of available npm scripts, and execute the selected one
- ~SPC m n c~ to run the =npm clean= command in the project root
- ~SPC m n s~ to prompt for the name of an npm package, install it and save to =dependencies=
- ~SPC m n d~ to prompt for the name of an npm package, install it and save to =devDependencies=
- ~SPC m n n~ to initialize new project
- ~SPC m n u~ to remove project dependency
- ~SPC m n l~ to list installed project dependencies
- ~SPC m n p~ to visit project =package.json= file
- Changed the default linter from tslint to eslint
- Call tsfmt with extension of current buffer for TSX formatting
(thanks to Victor Andrée)
Expand Down
15 changes: 15 additions & 0 deletions layers/+lang/typescript/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [[#key-bindings][Key bindings]]
- [[#typescript-major-mode][Typescript Major Mode]]
- [[#reference-major-mode][Reference Major Mode]]
- [[#running-npm-npm-mode][Running NPM (npm-mode)]]

* Description
This layer adds support for TypeScript and TSX editing.
Expand Down Expand Up @@ -195,3 +196,17 @@ then set the variable =typescript-lsp-linter= to =nil=.
| ~C-j~ | find previous reference |
| ~C-k~ | find next reference |
| ~C-l~ | goto reference |

** Running NPM (npm-mode)

| Key binding | Description |
|-------------+---------------------------------------------------------------------------------|
| ~SPC m n i~ | Run the =npm install= command in the project root |
| ~SPC m n r~ | Show a list of available npm scripts, and execute the selected one |
| ~SPC m n c~ | Run the =npm clean= command in the project root |
| ~SPC m n s~ | Prompt for the name of an npm package, install it and save to =dependencies= |
| ~SPC m n d~ | Prompt for the name of an npm package, install it and save to =devDependencies= |
| ~SPC m n n~ | Initialize new project |
| ~SPC m n u~ | Remove project dependency |
| ~SPC m n l~ | List installed project dependencies |
| ~SPC m n p~ | Visit project =package.json= file |
25 changes: 25 additions & 0 deletions layers/+lang/typescript/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
eldoc
emmet-mode
flycheck
npm-mode
smartparens
typescript-mode
import-js
Expand Down Expand Up @@ -90,6 +91,30 @@
'(typescript-mode-local-vars-hook typescript-tsx-mode-local-vars-hook)
t))

(defun typescript/post-init-npm-mode ()
(add-hook 'typescript-mode-hook #'npm-mode)
(spacemacs/declare-prefix-for-mode 'typescript-mode "mn" "npm")
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode
"ni" 'npm-mode-npm-install
"nr" 'npm-mode-npm-run
"ns" 'npm-mode-npm-install-save
"nd" 'npm-mode-npm-install-save-dev
"nn" 'npm-mode-npm-init
"nu" 'npm-mode-npm-uninstall
"nl" 'npm-mode-npm-list
"np" 'npm-mode-visit-project-file)
(add-hook 'typescript-tsx-mode-hook #'npm-mode)
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mn" "npm")
(spacemacs/set-leader-keys-for-major-mode 'typescript-tsx-mode
"ni" 'npm-mode-npm-install
"nr" 'npm-mode-npm-run
"ns" 'npm-mode-npm-install-save
"nd" 'npm-mode-npm-install-save-dev
"nn" 'npm-mode-npm-init
"nu" 'npm-mode-npm-uninstall
"nl" 'npm-mode-npm-list
"np" 'npm-mode-visit-project-file))

(defun typescript/post-init-smartparens ()
(spacemacs/add-to-hooks #'spacemacs//activate-smartparens '(typescript-mode-hook
typescript-tsx-mode-hook)))
Expand Down