R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
128 stars 15 forks source link

New feature: split file paths into its components #110

Closed PMassicotte closed 2 months ago

PMassicotte commented 2 months ago

This PR adds two new keybindings:

  1. <localleader>sp: Split a file path and wrap it around the paste() function.
  2. <localleader>sh: Split a file path and wrap it around the here() function.

This allows to breaks long lines to nicely format code.

Peek 2024-04-05 08-47

After, one can use the preferred formatter to wrap lines.

wurli commented 2 months ago

😮 I like this! Worth considering other features in this area, e.g. {codegrip}-style reshaping?

One comment, should Windows path separators \\ also be used to split paths? Both / and \\ as file separators are valid if using R on Windows so this is pretty rare, but does happen.

PMassicotte commented 2 months ago

😮 I like this! Worth considering other features in this area, e.g. {codegrip}-style reshaping?

One comment, should Windows path separators \\ also be used to split paths? Both / and \\ as file separators are valid if using R on Windows so this is pretty rare, but does happen.

I will check for windows support, I really hate seeing \\ :) But you are right. As for node formatting, I use https://github.com/Wansmer/treesj which works very nicely. Could be an option here, but would introduce 1 dependency.

jalvesaq commented 2 months ago

Good job, @PMassicotte! I see no problem in depending on treejs, but its README says that it already has a preset for R. Did you improve the preset?

PMassicotte commented 2 months ago

treejs does not split path, it simply reflows the code over multiple lines (i,e spread parameters vertically). At the moment, this PR do not need treejs, it will on only split the path. into components.

jalvesaq commented 2 months ago

Looking at the split path:

PMassicotte commented 2 months ago
  • You use treesitter... People who don't have a tree-sitter parser for R will miss interesting R.nvim features. Should we make the availability of a tree-sitter parser for R a required dependency?

I think that would be nice. We have few functionalities that now relies on it.

New commit coming for your proposed changes.

jalvesaq commented 2 months ago

Is it ready to be merged now?

PMassicotte commented 2 months ago

Yes all good I think!

jalvesaq commented 2 months ago

Thank you!