rktjmp / paperplanes.nvim

Neovim :airplane: Pastebins
MIT License
90 stars 3 forks source link

Customize each :PP call #7

Closed RaafatTurki closed 2 years ago

RaafatTurki commented 2 years ago

Some providers like dpaste.org give the ability to chose syntax highlighting. In the case of dpaste you'd add -F "lexer=lua" to your curl command. I wanted :PP to automatically put the current filetype in there.

Maybe cmd() should take provider_options as an argument and set the dpaste provider to have a lexer provider option?

Keep in mind that I can't read fennel so if something like this was already implemented an example config would be very appreciated.

rktjmp commented 2 years ago

I actually did have that originally but dpaste would hard-fail if it didn't recognise the filetype:

https://github.com/rktjmp/paperplanes.nvim/blob/568611e220503dfa79dfafdb1fd6d051dc4ac8bf/fnl/paperplanes/providers/dpasteorg.fnl#L3-L6

dpaste should just be finding the correct lexer by extension. That did work when I first wrote the code but dpaste may have changed.

RaafatTurki commented 2 years ago

You could use this lua table I made, I got that list from the dpaste docs and formatted it into a lua table. And only provide curl with -F "lexer=..." if filetype is in that table.

The logic can be later improved to be smarter and knows when to use more complex lexers. For example if you were editing an html file in a django project it's probably a django template with many curly brackets:

-F "lexer=html" image

-F "lexer=html+django" image

rktjmp commented 2 years ago

Yep seems reasonable enough to include a lookup table for known types, not 100% sure how accurate the filetypes there map to what Neovim uses for filetypes though (i.e. "js+erb" might be "erb-js" in nvim, not sure).

I think :PP should take options too as I thought here https://github.com/rktjmp/paperplanes.nvim/issues/2#issuecomment-1001861724 and you're suggesting.

:PP lexer=python which could probably be merged into the provider options.

RaafatTurki commented 2 years ago

You don't have to be sure about its accuracy for now, if neovim can't find erb-js in the table it won't set a lexer.

I'd say leave :PP the way it is and instead provide a lua function that takes provider_opts as a table, something like require 'paperplanes'.PP(provider_opts)

rktjmp commented 2 years ago

Will be fixed in #9, both lexer detection and you can now call any of the API functions with an optional provider name and provider options table.

The lexer list isn't actually as complete as you posted on the live site, only

  ;; list got by posting an unknown lexer to dpaste, returns list of supported types
  ;; yes, typ_o_script (???)
  (let [known-filetypes ["applescript" "arduino" "bash" "bat" "c" "clojure"
                         "cmake" "coffee-script" "common-lisp" "console" "cpp"
                         "cpp-objdump" "csharp" "css" "cuda" "d" "dart,
                         delphi" "diff" "django" "docker" "elixir" "erlang"
                         "go" "handlebars" "haskell" "html" "html+django"
                         "ini" "ipythonconsole" "irc" "java" "js" "json" "jsx"
                         "kotlin" "less" "lua" "make" "matlab" "nginx" "numpy"
                         "objective-c" "perl" "php" "postgresql" "python" "rb"
                         "rst" "rust" "sass" "scss" "sol" "sql" "swift" "tex"
                         "typoscript" "vim" "xml" "xslt" "yaml"]]

require 'paperplanes'.PP(provider_opts)

This would be done (when 0.1.2 is merged or if you checkout that branch) via

-- assumes you've just made a visual selection before running
:lua require("paperplanes").post_selection("my_provider", {opt = "tion"})

Or any of the other post_string, post_buffer or post_range.