Giter VIP home page Giter VIP logo

launch-editor's Introduction

launch-editor

Open file with line numbers in editor from Node.js.

The main functionality is extracted from react-dev-utils with slight modifications so that it can be used as a standalone package. The original source code is licensed under MIT.

Also added column number support.

Why

There are also a few other existing packages with the same purpose:

However, both expects env variables like EDITOR to be set in order to open files. This package infers the editor to open by checking current running processes before falling back to env variables.

On the other hand,react-dev-utils includes many other utilities and dependencies and is thus not suitable for standalone usage.

Usage

const launch = require('launch-editor')

launch(
  // filename:line:column
  // both line and column are optional
  'foo.js:12:34',
  // try specific editor bin first (optional)
  'code',
  // callback if failed to launch (optional)
  (fileName, errorMsg) => {
    // log error if any
  }
)

Middleware

An express/connect/webpack-dev-server compatible middleware is also available:

const launchMiddleware = require('launch-editor-middleware')

app.use('/__open-in-editor', launchMiddleware())

The middleware factory function accepts the following arguments (all optional, the callback can be in any position as long as it's the last argument):

  1. A specific editor bin to try first. Defaults to inferring from running processes, then fallback to env variables like EDITOR and VISUAL.
  2. The root directory of source files, in case the file path is relative. Defaults to process.cwd().
  3. a callback when it fails to launch the editor.

To launch files, send requests to the server like the following:

/__open-in-editor?file=src/main.js:13:24

Supported editors

Value Editor Linux Windows OSX
appcode AppCode
atom Atom
atom-beta Atom Beta
brackets Brackets
clion Clion
code Visual Studio Code
code-insiders Visual Studio Code Insiders
emacs Emacs
idea IDEA
notepad++ Notepad++
pycharm PyCharm
phpstorm PhpStorm
rubymine RubyMine
sublime Sublime Text
vim Vim
visualstudio Visual Studio
webstorm WebStorm

launch-editor's People

Contributors

anteriovieira avatar pi0 avatar yyx990803 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.