Ember-mode speeds up navigation in EmberJS projects.
ember-mode can be used to either generate, destroy, or navigate between files.
Let's assume you have the following files in your emberjs folder structure:
- app router.coffee - models - friend.coffee - plugin.coffee - controllers - plugins.coffee - routes - friends.coffee - plugins.coffee - friends - show.coffee
Say you are visiting the
models/friend.coffee file with
ember-mode enabled. Pressing
C-c . f r will move to
If, from there on, you enter
C-c . f c ember-mode will try to open
controllers/friends.coffee. As that doesn't exist, it'll try all of the following:
- controllers/friends.js - controllers/friend.coffee - controllers/friend.js
As none of these exist, it lists all controllers and lets you select one of them.
Say we are visiting
routes/plugins.coffee and would like to generate a
Peer model. Pressing
C-c . g m will ask for the name of the class to generate (with a default of
plugins) and the options to be passed to the generator. The default is hinted based on the current file.
Similarly, if we are visiting
routes/plugins.coffee and want to generate a controller, pressing
C-c . g c will ask for the name of the controller to generate (with a default of
plugins) and the options to be passed to the generator. In essence, pressing enter twice will generate
Say we are visiting
models/friend.coffee and want to generate the
friend route. Pressing
C-u C-c . g r will use the ember generators to generate the route and open it (without posing any questions).
Note that pressing
C-c . f r would have navigated to
routes/friends.coffee and wouldn't have found the newly generated route before.
PRO TIP: If you are using coffeescript, enable
cd path/to/your/ember-cli-project npm install ember-cli-coffeescript --save-dev
building, serving, testing
ember build and
ember test can be run with
C-c . r b and
C-c . r t
C-c . r s will either run
ember serve, or bring up
the serve buffer if already running. These commands use compilation
mode to link errors to files with line and column numbers. If the
ember serve runs in is buried, it will also notify of
build status via minibuffer messages.
working with PODs
Ember-mode is shipped with basic support for the POD structure. Navigation support and generators operate the same, but keep the POD structure in mind.
Ember-mode will pick up
"usePods": true when set in
.ember-cli. If this is set, navigation occurs assuming a POD structure. See the installation section for more information on overriding the detection of a POD enabled project.
ember-mode also supports managing bare-bones imports. If you need to import computed from the ember package, you can just write
computed and execute the
C-c . i e to import computed from the correct package. This works for other imports too.
If you have code which uses the old style
Ember.computed. It can help you upgrade an import statement from it's
Ember.something form to its new form. Move your cursor on
Ember.computed and execute
C-c . i u.
If you wish to use a different prefix other than
C-c ., you may
customize the variable
clone this folder in your emacs.d folder:
mkdir -p ~/.emacs.d/ cd ~/.emacs.d git clone https://github.com/madnificent/ember-mode.git
add the folder to your load path in your
~/.emacsfile if it isn't there already and require ember-mode.
(add-to-list 'load-path "~/.emacs.d/ember-mode/") (require 'ember-mode)
reload the settings, go to an ember project, enable ember-mode and try out your new keybindings!
to enable ember-mode in specific projects, create a
.dir-locals.elfile in your ember project with the following:
((nil . ((mode . ember))))
In order to override pod structure detection, you can use the ember-use-pods variable:
((nil . ((mode . ember) (ember-use-pods . t))))
(add-hook 'js-mode-hook (lambda () (ember-mode t))) (add-hook 'web-mode-hook (lambda () (ember-mode t)))