l-zeuch / yagpdb.vim

(N)Vim plugin for YAGPDB Custom Commands.
GNU General Public License v2.0
7 stars 2 forks source link

Proposal: Minify Code #43

Open l-zeuch opened 2 years ago

l-zeuch commented 2 years ago

Description

In a similar fashion to jo3-l/cc-minifier, add a command (and/or binding) to generate a minified version of the current buffer contents.

Solution

To begin with, I'm not entirely sure if this feature is even possible in pure Vim script, or if we have to resort to the Lua API, and thus make this a Neovim-only feature. I'll do some research in those regards and see if I can come up with results that bring this forward.

However, before I further go into the discussion of a potential solution, we first have to consider the dreaded feature creep — is such a feature really necessary and needed? To me it sure seems convenient to just enter a command and have a minimal version of my code.

Finally, we have to consider multiple things:

Regarding my first point, this definitely needs some discussion. Perhaps we can take inspiration at jo3-l/cc-minifier? With respect to the second point however, we'll have to decide a way.

Comments feel rather clunky and unnecessarily complicated to me — their format and what argument does what would have to be documented well.

If we can pass arguments to our command, then I suggest we go with that, in a very similar fashion to command line programs that already do text manipulation. We would then also be able to bundle multiple effects into one single argument, say --aggressive.

The format, whether we use the flag syntax or pass arguments surely is up to debate. Personally, I like the flags style more, they feel to me more appropriate.

Code of Conduct

LRitzdorf commented 2 years ago

This does indeed seem useful. Although it might constitute just a bit of feature creep, I think it makes sense, along with #40 (as both implement enhanced functionality that wouldn't otherwise be available).

As for the issues you mentioned, I also like the flags approach. Since most options would likely be binary, flags do seem to be the most logical option.

Joe's code could definitely be useful as a basis for this, but (obviously) it's JS, so we'd have to port it to something more suitable for Vim. To that end, I like Python more than Lua here, since that will ensure we aren't limited to Neovim.

Lastly, in addition to the transforms in Joe's existing code, we might want to add one-lining (perhaps as part of an extra-aggressive mode?), since newlines in the CC itself count as two characters each.

l-zeuch commented 2 years ago

Personally I prefer this feature over #40 — adding features to a programming interface is not the task of a simple plugin, in my eyes.

[...] but (obviously) it's JS, so we'd have to port it to something more suitable for Vim. To that end, I like Python more than Lua here, since that will ensure we aren't limited to Neovim.

I honestly don't know if that would make any difference. When you try to run :checkhealth in your Neovim, you'll see a multitude of language providers, namely: Ruby via neovim-ruby-host gem; Node.js via neovim npm/yarn package; Perl via Neovim::Ext; Python3 via pynvim. Lua just so happens to be inbuilt and shipped everywhere, these modules and packages are obviously all optional.

However, if there is a way — any way — to also interface Vim with this backend, we'll use that way and thus that language.

`:checkhealth` image ![image](https://user-images.githubusercontent.com/71897876/170947308-ac823137-6791-46c6-9b42-c79ac5a5b756.png)

Lastly, in addition to the transforms in Joe's existing code, we might want to add one-lining (perhaps as part of an extra-aggressive mode?), since newlines in the CC itself count as two characters each.

Definitely needed, the character count being off on the web interface has been fixed recently as well.

LRitzdorf commented 2 years ago

Hm, good point about language support. But also, I think Python is something of a standard for more advanced Vim plugins (even for vanilla Vim), so it might be more reasonable to expect users to have Python already installed and set up.