GithubHelp home page GithubHelp logo

tern's Introduction

Tern

This is Tern. Tern is a stand-alone, editor-independent JavaScript analyzer that can be used to improve the JavaScript integration of existing editors. It currently comes only with an online demo, but I am hard at work on Emacs and Vim plug-ins.

Thanks to a group of generous crowd funders, Tern is open-source software, under an MIT license.

(Disclaimer: This is a work in progress. The interface will change, and it has bugs. But it just might occasionally work.)

Setting up the Emacs mode

  1. Make sure you are using Emacs 24 or later. The Tern mode requires lexical scoping.

  2. Clone this repository somewhere. Do npm install to get the dependencies.

  3. Make Emacs aware of emacs/tern.el. For example by adding this to your .emacs file:

    (add-to-list 'load-path "/path/to/tern/emacs/")
    (autoload 'tern-mode "tern.el" nil t)
    
  4. Optionally set tern-mode to be automatically enabled for your JavaScript mode of choice. Here's the snippet for js-mode:

    (add-hook 'js-mode-hook (lambda () (tern-mode t)))
    

Buffers in tern-mode add a completion-at-point function that activates Tern's completion. So, unless you rebound the command, M-tab will trigger completion.

When the point is in an argument list, Tern will show argument names and types at the bottom of the screen.

The following keys are bound:

  • M-. to jump to the definition of the thing under the cursor.
  • M-, brings you back to last place you were when you pressed M-..
  • C-c C-r to rename the variable under the cursor.

Setting up the Vim plugin

  1. Clone this repository somewhere. Do npm install to get the dependencies.

  2. Make sure your Vim has Python support.

  3. Source the vim/tern.vim script in your .vimrc. Don't copy it anywhere, leave it in the Tern checkout so that it can find the Tern server code.

    so /path/to/tern/vim/tern.vim
    

When editing a JavaScript (.js) file, your omni-complete will be hooked into Tern. Use C-x C-o in insert mode to activate it.

Configuring Tern

The Tern server used by the Emacs and Vim plugins will look for a .tern-project file in the current directory or any of its parents, to determine the scope of the project. If it doesn't find one, it'll assume the local directory is the scope, and use its default settings.

A .tern-project file is a JSON file in a format like this:

{
  "libs": [
    "browser",
    "jquery"
  ],
  "loadEagerly": [
    "importantfile.js"
  ],
  "plugins": {
    "requirejs: {
      "baseURL": "./",
      "paths": {}
    }
  }
}

The libs property refers to the JSON type descriptions that should be loaded into the environment for this project. See the defs/ directory for examples. The strings given here will be suffixed with .json, and searched for first in the project's own dir, and then in the defs/ directory of the Tern distribution.

By default, local files are loaded into the Tern server when they are opened by the editor. loadEagerly allows you to force some files to always be loaded.

Finally, plugins is an object used to load and configure Tern plugins. The names of the properties refer to files (suffixed with .js) or directories, either in the project dir or under plugin/ in the Tern directory. Their values are configuration objects that will be passed to the plugins. You can leave them at {} when you don't need to pass any options.

tern's People

Contributors

eztierney avatar marijnh avatar nico avatar seidtgeist avatar sergioramos avatar

Watchers

 avatar  avatar

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.