/formatter

Code formatters for Pragtical code editor

Primary LanguageLuaMIT LicenseMIT

Formatters for Pragtical

List of formatters (Keep alphabetical)

Installation instructions

  1. Clone this repository into the pragtical plugins/formatter folder

  2. Make sure you have the command that formatter uses installed, or it won't work.

  3. Extra configuration: If you want to customize a formatter, you can do this from your init.lua script. Example:

config.plugins.formatter.jsbeautify = {
    -- Optionally disable this formmater
    enabled = false,
    -- Optionally set path of executable
    path = "/path/to/js-beautify",
    -- Set jsBeautify arguments to indent with spaces.
    args = "-r -s 4 -p -b end-expand"
}

Using the formatter

the default keymap to format the current doc is alt+shift+f the command is formatter:format-doc

to format a document at each save add the following config to your user init.lua as shown:

config.plugins.formatter.format_on_save = true

Contributing a formatter

Example from jsbeautify.lua:

-- for JS Beautify fortmatter

return {
  label = "JS Beautifier",
  file_patterns = {"%.js$"},
  command = {"js-beautify", "$ARGS", "$FILENAME"},
  -- make sure to keep -r arg if you change this
  args = "-r -q -s 1 -t -p -b end-expand"
}

a few things to keep in mind

  • choose a unique file name
  • make sure to set a label
  • make sure to add it to the list in readme.md (and keep it alphabetical)

Then, submit a pull request