Coder Social home page Coder Social logo

codegrip's Introduction

codegrip

Codecov test coverage R-CMD-check

codegrip provides RStudio addins and Emacs commands for reshaping R code and navigating across syntactic constructs.

Reshaping

addin_reshape lets you cycle between different shapes of function calls. For instance, reshaping transforms code from wide to long shape and vice versa.

Note that for function definitions, addin_reshape cycles through two different long shapes. The traditional L form uses more horizontal space whereas the flat form uses less horizontal space and the arguments are always aligned at double indent:

Navigating

There are currently two motions implemented in codegrip: outwards and inwards.

  • addin_move_inside finds the first opening delimiter ((, [, or {) after your cursor and steps inside it.

  • addin_move_outside finds the first opening delimiter before your cursor and steps outside it.

These motions are handy for quick navigation across to quickly jump from a function argument to the corresponding function call. From there, you can reshape the whole call using addin_reshape.

Installation

The package is not yet on CRAN but you can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("lionel-/codegrip")

Setup

Suggested keybindings:

  • Alt + Tab: addin_reshape
  • Alt + 3: addin_move_outside
  • Alt + 4: addin_move_inside

Not yet implemented:

  • Alt + 1: addin_move_backwards
  • Alt + 2: addin_move_forwards

Using in Visual Studio Code

addin_reshape is available for keybinding in VS Code. See here for instructions on enabling general addin support.

Once addins are enabled, add the following to keybindings.json:

{
  "key": "Alt+tab",
  "command": "r.runCommand",
  "description": "Reshape expressions longer or wider",
  "when": "editorTextFocus",
  "args": "codegrip::addin_reshape()"
}

Roadmap

  • Forward and backward motions.

  • Adding arguments to a function call using forward backward motions.

  • Reshaping of repeated calls like foo(...)(...). This will help reshaping data.table pipelines, e.g. DT[...][...].

  • Reshaping of { expressions.

  • Reshaping of pipelines of binary operations, including pipes.

  • Columnar formatting of tibble::tribble() calls.

  • Selection of syntactic constructs, such as function arguments.

Limitations

codegrip currently uses the R parser to figure out the structure of your code. Because of this, it doesn't work with malformed or partially written code. Your whole file must be valid R code for codegrip commands to work.

codegrip's People

Contributors

lionel- avatar jimgar avatar jennybc 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.