Make javascript layer adhere to REPL conventions and fix typescript doc
This commit is contained in:
parent
eee7d20bfe
commit
9ebf17af49
|
@ -20,6 +20,8 @@
|
|||
- [[#configuration][Configuration]]
|
||||
- [[#indentation][Indentation]]
|
||||
- [[#repl][REPL]]
|
||||
- [[#browser-based-repl][Browser based REPL]]
|
||||
- [[#server-based-repl][Server based REPL]]
|
||||
- [[#node][Node]]
|
||||
- [[#node-modules][Node Modules]]
|
||||
- [[#node-externs][Node Externs]]
|
||||
|
@ -29,9 +31,9 @@
|
|||
- [[#importing-import-js][Importing (import-js)]]
|
||||
- [[#refactoring-js2-refactor][Refactoring (js2-refactor)]]
|
||||
- [[#documentation-js-doc][Documentation (js-doc)]]
|
||||
- [[#repl-skewer-mode][REPL (skewer-mode)]]
|
||||
- [[#browser-based-repl-skewer-mode][Browser based REPL (skewer-mode)]]
|
||||
- [[#server-based-repl-nodejs-repl][Server based REPL (nodejs-repl)]]
|
||||
- [[#debugger-dap-mode][debugger (dap mode)]]
|
||||
- [[#nodejs-repl-nodejs-repl][NodeJS REPL (nodejs-repl)]]
|
||||
|
||||
* Description
|
||||
This layer adds support for the JavaScript language using [[https://github.com/mooz/js2-mode][js2-mode]].
|
||||
|
@ -41,8 +43,8 @@ This layer adds support for the JavaScript language using [[https://github.com/m
|
|||
- Smart code folding
|
||||
- Refactoring: done using [[https://github.com/magnars/js2-refactor.el][js2-refactor]].
|
||||
- Auto-completion and documentation
|
||||
- REPL available via [[https://github.com/skeeto/skewer-mode][skewer-mode]] and [[https://github.com/pandeiro/livid-mode][livid-mode]]
|
||||
- NodeJS REPL with [[https://github.com/abicky/nodejs-repl.el][nodejs-repl]]
|
||||
- Browser based REPL available via [[https://github.com/skeeto/skewer-mode][skewer-mode]] and [[https://github.com/pandeiro/livid-mode][livid-mode]]
|
||||
- Server based REPL with [[https://github.com/abicky/nodejs-repl.el][nodejs-repl]]
|
||||
- Formatting with [[https://github.com/yasuyk/web-beautify][web-beautify]]
|
||||
|
||||
* Install
|
||||
|
@ -183,12 +185,28 @@ or when adding the =javascript= configuration layer:
|
|||
#+END_SRC
|
||||
|
||||
** REPL
|
||||
To use the available JS repl, you need a running httpd server and a page loaded
|
||||
*** Browser based REPL
|
||||
To use the browser based REPL set the =javascript-repl= variable as shown below:
|
||||
#+BEGIN_SRC elisp
|
||||
(setq-default dotspacemacs-configuration-layers
|
||||
'((javascript :variables javascript-repl `skewer)))
|
||||
#+END_SRC
|
||||
|
||||
In addition you need a running httpd server and a page loaded
|
||||
with skewer. If a blank page serves your needs, just use the run-skewer command
|
||||
in your javascript buffer. If you want to inject it in your own page, follow
|
||||
[[https://github.com/skeeto/skewer-mode#skewering-with-cors][these instructions]] (install the Greasemonkey script and then click the triangle
|
||||
in the top-right corner - if it turns green, you're good to go).
|
||||
|
||||
*** Server based REPL
|
||||
To use the server based REPL set the =javascript-repl= variable as shown below:
|
||||
#+BEGIN_SRC elisp
|
||||
(setq-default dotspacemacs-configuration-layers
|
||||
'((javascript :variables javascript-repl `nodejs)))
|
||||
#+END_SRC
|
||||
|
||||
In addition install nodejs and make sure that =node= is in the path.
|
||||
|
||||
** Node
|
||||
*** Node Modules
|
||||
If you would like =node_modules/.bin= to be automatically added to the buffer
|
||||
|
@ -284,7 +302,7 @@ You can check more [[https://github.com/mooz/js-doc/][here]]
|
|||
| ~SPC m r d t~ | insert tag to comment |
|
||||
| ~SPC m r d h~ | show list of available jsdoc tags |
|
||||
|
||||
** REPL (skewer-mode)
|
||||
** Browser based REPL (skewer-mode)
|
||||
|
||||
| Key binding | Description |
|
||||
|-------------+------------------------------------------------------------------|
|
||||
|
@ -303,6 +321,21 @@ You can check more [[https://github.com/mooz/js-doc/][here]]
|
|||
| ~SPC m s R~ | send current region to the skewer REPL and switch to it in insert state |
|
||||
| ~SPC m s s~ | switch to REPL |
|
||||
|
||||
** Server based REPL (nodejs-repl)
|
||||
|
||||
| Key binding | Description |
|
||||
|-------------+--------------------------------------------------------------------|
|
||||
| ~SPC m s i~ | Switch to NodeJS REPL if one has been started, otherwise start one |
|
||||
| ~SPC m s e~ | Send last expression to NodeJS REPL |
|
||||
| ~SPC m s E~ | Send last expression to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s b~ | Send current buffer to NodeJS REPL |
|
||||
| ~SPC m s B~ | Send current buffer to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s l~ | Send current line to NodeJS REPL |
|
||||
| ~SPC m s L~ | Send current line to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s r~ | Send active region to NodeJS REPL |
|
||||
| ~SPC m s R~ | Send active region to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s s~ | switch to REPL |
|
||||
|
||||
** debugger (dap mode)
|
||||
|
||||
| Key binding | Description |
|
||||
|
@ -349,17 +382,3 @@ You can check more [[https://github.com/mooz/js-doc/][here]]
|
|||
| ~SPC m d w o~ | goto output buffer if present |
|
||||
| ~SPC m d w s~ | list sessions |
|
||||
| ~SPC m d w b~ | list breakpoints |
|
||||
|
||||
** NodeJS REPL (nodejs-repl)
|
||||
|
||||
| Key binding | Description |
|
||||
|-------------+--------------------------------------------------------------------|
|
||||
| ~SPC m s n i~ | Switch to NodeJS REPL if one has been started, otherwise start one |
|
||||
| ~SPC m s n e~ | Send last expression to NodeJS REPL |
|
||||
| ~SPC m s n E~ | Send last expression to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s n b~ | Send current buffer to NodeJS REPL |
|
||||
| ~SPC m s n B~ | Send current buffer to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s n l~ | Send current line to NodeJS REPL |
|
||||
| ~SPC m s n L~ | Send current line to NodeJS REPL and switch to REPL |
|
||||
| ~SPC m s n r~ | Send active region to NodeJS REPL |
|
||||
| ~SPC m s n R~ | Send active region to NodeJS REPL and switch to REPL |
|
||||
|
|
|
@ -24,3 +24,6 @@
|
|||
|
||||
(defvar javascript-fmt-on-save nil
|
||||
"Run formatter on buffer save.")
|
||||
|
||||
(defvar javascript-repl 'skewer
|
||||
"Repl to be configured by the layer, `skewer' for browser based javascript, `nodejs' for server based development.")
|
||||
|
|
|
@ -25,12 +25,12 @@
|
|||
js2-mode
|
||||
js2-refactor
|
||||
livid-mode
|
||||
nodejs-repl
|
||||
org
|
||||
prettier-js
|
||||
skewer-mode
|
||||
tern
|
||||
web-beautify
|
||||
nodejs-repl
|
||||
))
|
||||
|
||||
(defun javascript/post-init-add-node-modules-path ()
|
||||
|
@ -158,6 +158,7 @@
|
|||
"xmk" 'js2r-move-line-up))))
|
||||
|
||||
(defun javascript/init-livid-mode ()
|
||||
(when (eq javascript-repl 'skewer)
|
||||
(use-package livid-mode
|
||||
:defer t
|
||||
:init
|
||||
|
@ -167,7 +168,7 @@
|
|||
:mode livid-mode
|
||||
:documentation "Live evaluation of JS buffer change."
|
||||
:evil-leader-for-mode (js2-mode . "Tl"))
|
||||
(spacemacs|diminish livid-mode " 🅻" " [l]"))))
|
||||
(spacemacs|diminish livid-mode " 🅻" " [l]")))))
|
||||
|
||||
(defun javascript/pre-init-prettier-js ()
|
||||
(when (eq javascript-fmt-tool 'prettier)
|
||||
|
@ -178,6 +179,7 @@
|
|||
(add-to-list 'spacemacs--import-js-modes (cons 'js2-mode 'js2-mode-hook))))
|
||||
|
||||
(defun javascript/init-skewer-mode ()
|
||||
(when (eq javascript-repl 'skewer)
|
||||
(use-package skewer-mode
|
||||
:defer t
|
||||
:init
|
||||
|
@ -202,9 +204,10 @@
|
|||
"sF" 'spacemacs/skewer-eval-defun-and-focus
|
||||
"sr" 'spacemacs/skewer-eval-region
|
||||
"sR" 'spacemacs/skewer-eval-region-and-focus
|
||||
"ss" 'skewer-repl))))
|
||||
"ss" 'skewer-repl)))))
|
||||
|
||||
(defun javascript/init-nodejs-repl ()
|
||||
(when (eq javascript-repl 'nodejs)
|
||||
(use-package nodejs-repl
|
||||
:defer nil
|
||||
:init
|
||||
|
@ -213,34 +216,40 @@
|
|||
"nodejs-repl")
|
||||
:config
|
||||
(progn
|
||||
(spacemacs/declare-prefix-for-mode 'js2-mode "msn" "nodejs-repl")
|
||||
(spacemacs/declare-prefix-for-mode 'js2-mode "ms" "nodejs-repl")
|
||||
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
|
||||
"sni" 'nodejs-repl-switch-to-repl
|
||||
"sne" 'nodejs-repl-send-last-expression
|
||||
"snE" (lambda ()
|
||||
"'" 'nodejs-repl
|
||||
"ss" 'nodejs-repl
|
||||
"si" 'nodejs-repl-switch-to-repl
|
||||
"se" 'nodejs-repl-send-last-expression
|
||||
"sE" (lambda ()
|
||||
(interactive)
|
||||
(nodejs-repl-send-last-expression)
|
||||
(nodejs-repl-switch-to-repl))
|
||||
"snb" 'nodejs-repl-send-buffer
|
||||
"snB" (lambda ()
|
||||
"sb" 'nodejs-repl-send-buffer
|
||||
"sB" (lambda ()
|
||||
(interactive)
|
||||
(nodejs-repl-send-buffer)
|
||||
(nodejs-repl-switch-to-repl))
|
||||
"snl" 'nodejs-repl-send-line
|
||||
"snL" (lambda ()
|
||||
"sl" 'nodejs-repl-send-line
|
||||
"sL" (lambda ()
|
||||
(interactive)
|
||||
(nodejs-repl-send-line)
|
||||
(nodejs-repl-switch-to-repl))
|
||||
"snr" 'nodejs-repl-send-region
|
||||
"snR" (lambda ()
|
||||
(nodejs-repl-send-region)
|
||||
"sr" 'nodejs-repl-send-region
|
||||
"sR" (lambda (start end)
|
||||
(interactive "r")
|
||||
(nodejs-repl-send-region start end)
|
||||
(nodejs-repl-switch-to-repl)))
|
||||
(spacemacs/declare-prefix-for-mode 'js2-mode
|
||||
"msnE" "nodejs-send-last-expression-and-focus")
|
||||
"msE" "nodejs-send-last-expression-and-focus")
|
||||
(spacemacs/declare-prefix-for-mode 'js2-mode
|
||||
"msnB" "nodejs-send-buffer-and-focus")
|
||||
"msB" "nodejs-send-buffer-and-focus")
|
||||
(spacemacs/declare-prefix-for-mode 'js2-mode
|
||||
"msnL" "nodejs-send-line-and-focus")
|
||||
"msL" "nodejs-send-line-and-focus")
|
||||
(spacemacs/declare-prefix-for-mode 'js2-mode
|
||||
"msnR" "nodejs-send-region-and-focus")
|
||||
)))
|
||||
"msR" "nodejs-send-region-and-focus")
|
||||
))))
|
||||
|
||||
(defun javascript/post-init-tern ()
|
||||
(add-to-list 'tern--key-bindings-modes 'js2-mode))
|
||||
|
|
|
@ -89,7 +89,7 @@ We need to use the project-local eslint installation in order to pick up plugins
|
|||
and presets installed locally.
|
||||
|
||||
Ensure that the project directory =node_modules/.bin= is added to the buffer
|
||||
local =exec_path= (see the Javascript layer [[file:~/.emacs.d/layers/+lang/javascript/README.org][README]] documentation for more
|
||||
local =exec_path= (see the Javascript layer [[file:../../+lang/javascript/README.org][README]] documentation for more
|
||||
details).
|
||||
|
||||
If you want to use typescript-formatter for formatting run:
|
||||
|
|
Loading…
Reference in a new issue