Giter Club home page Giter Club logo

kakoune-jsx-selections's Introduction

Kakoune JSX Selections

A Kakoune plugin providing custom selections for JSX code.

NOTE: Currently, this plugin should be considered alpha and is subject to breaking changes.

Background

When using Kakoune to work on a ReactJS-based project, I've found manipulating the React elements / DOM tags embedded in JSX files to be one of the biggest pain-points. This plugin initially aimed to improve that experience specifically, but because it is based on a proper AST parser it made sense to support other syntactic objects as well.

Scope

This plugin is focused solely on providing useful selections for JavaScript/JSX code (and should work for TypeScript as well). Because Kakoune uses the subject-verb model, the provided selections can naturally be followed up with any desired actions.

Including only selections also makes the plugin quite safe and robust. If a selection fails or is incorrect due to a bug, no code was changed, and the user can manually correct the selection and continue working without disruption.

Dependencies

This plugin requires the following applications to be installed on your system.

  • node
  • npm

Installing & Configuring

Using plug.kak

  1. Add this to your kakrc:
plug 'jordan-yee/kakoune-jsx-selections' do %{
    npm install
    npm link
} config %{
    declare-user-mode jsx-selections
    map global jsx-selections c ': jsx-select-current-element<ret>' -docstring 'select the element at the cursor'
    map global jsx-selections n ': jsx-select-next-element<ret>' -docstring 'select next element after the cursor'
    map global jsx-selections f ': jsx-select-current-function<ret>' -docstring 'select the function at the cursor'
    map global jsx-selections j ': jsx-select-next-function<ret>' -docstring 'select next function after the cursor'

    map global user x ': enter-user-mode jsx-selections<ret>' -docstring 'jsx-selections mode'
    map global user X ': enter-user-mode -lock jsx-selections<ret>' -docstring 'jsx-selections mode'
}
  1. Restart Kakoune then run the install command:
:plug-install

Uninstalling

The included NodeJS program is installed using npm link, which creates a global symbolic link, which enables the command to be run from anywhere.

To uninstall this, run npm rm --global kakoune-jsx-selections.

Commands

Here is a reference of the provided commands:

Command Description
jsx-select-current-element select the element at the cursor
jsx-select-next-element select next element after the cursor
jsx-select-current-function select the function at the cursor
jsx-select-next-function select next function after the cursor

Developer Notes

This plugin is based on the Acorn JavaScript parser, which is used to parse a JavaScript or JSX file into an AST that in turn can be used to reliably find the structures we want to select.

TODOs

Here is a brain dump of updates I have in mind.

Features:

  • select-previous-* commands
  • select-parent-element
  • select-first-child-element
  • select-*-expression commands
  • auto-generate selection commands from all AST node types

Design Improvements:

  • provide command that automatically applies suggested mappings
  • improve ergonomics of suggested mappings

Technical Improvements:

  • Use buffer contents to determine selections rather than file contents
  • wrap all provided commands in a module
  • only define commands for JavaScript filetype
  • investigate trade-offs between npm link vs published npm package strategies
  • review plugin standards and update or refactor as needed
  • implement versioning w/ changelog

kakoune-jsx-selections's People

Contributors

jordan-yee avatar

Watchers

 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.