This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/contrib/lang/javascript
Andrew Oppenlander e303fce60b Add Javacript layer
- move JavaScript/js2-mode into a contrib layer
- add js2-refactor
- change keybindings to be more spacemacsy
- add a function to define a command prefix for a specific mode
2014-12-07 23:55:32 -05:00
..
packages.el Add Javacript layer 2014-12-07 23:55:32 -05:00
README.md Add Javacript layer 2014-12-07 23:55:32 -05:00

JavaScript contribution layer for Spacemacs

Features

  • Smart Code Folding
  • Refactoring
  • Auto-completion
  • Documentation Lookup

Install

To use this contribution add it to your ~/.spacemacs

(defvar dotspacemacs-configuration-layers '(js2-mode)
  "List of contribution to load."
)

You will also need to install tern to use the auto-completion and documentation features:

$ npm install -g tern

Key Bindings

js2-mode

Improved JavaScript editing mode for GNU Emacs.

Key Binding   |                 Description

------------------|------------------------------------------------------------ m w | toggle js2-mode warnings and errors m z c | hide element m z o | show element m z r | show all element m z e | toggle hide/show element m z F | toggle hide functions m z C | toggle hide comments

js2-refactor

Refactoring is done using js2-refactor.
Bindings should match the plain emacs assignments.

Key Binding   |                 Description

------------------|------------------------------------------------------------ x m j | move line down, while keeping commas correctly placed x m k | move line up, while keeping commas correctly placed m k | deletes to the end of the line, but does not cross semantic boundaries m r 3 i | converts ternary operator to if-statement m r a g | creates a /* global */ annotation if it is missing, and adds var to point to it m r a o | replaces arguments to a function call with an object literal of named arguments m r b a | moves the last child out of current function, if-statement, for-loop or while-loop m r c a | converts a multiline array to one line m r c o | converts a multiline object literal to one line m r c u | converts a multiline function to one line (expecting semicolons as statement delimiters) m r e a | converts a one line array to multiline m r e f | extracts the marked expressions into a new named function m r e m | extracts the marked expressions out into a new method in an object literal m r e o | converts a one line object literal to multiline m r e u | converts a one line function to multiline (expecting semicolons as statement delimiters) m r e v | takes a marked expression and replaces it with a var m r i g | creates a shortcut for a marked global by injecting it in the wrapping immediately invoked function expression m r i p | changes the marked expression to a parameter in a local function m r i v | replaces all instances of a variable with its initial value m r l p | changes a parameter to a local var in a local function m r l t | adds a console.log statement for what is at point (or region) m r r v | renames the variable on point and all occurrences in its lexical scope m r s l | moves the next statement into current function, if-statement, for-loop, while-loop m r s s | splits a String m r s v | splits a var with multiple vars declared into several var statements m r t f | toggle between function declaration and function expression m r u w | replaces the parent statement with the selected region m r v t | changes local var a to be this.a instead m r w i | wraps the entire buffer in an immediately invoked function expression m r w l | wraps the region in a for-loop

tern

Tern is used as an auto-completion backend and for documentation features.

Key Binding   |                 Description

------------------|------------------------------------------------------------ m . | jump to the definition of the thing under the cursor m , | brings you back to last place you were when you pressed M-.. m f | jump to definition for the given name m c | rename variable under the cursor using tern m t | find the type of the thing under the cursor m g | find docs of the thing under the cursor. Press again to open the associated URL (if any)