Skip to content

Uses `nimpretty` while allowing for tab indentation and diff viewing.

License

Notifications You must be signed in to change notification settings

ttytm/nimpretty_t

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nimpretty_t

Uses nimpretty to format Nim code while allowing for tab indentation and diff viewing.

Quick start

Overview

Usage

Usage: nimpretty_t [options] <path>...

Formatter and diff viewer utilizing nimpretty.
By default, formatted output is written to stdout.

Options:
  -w  --write           Modifies non-conforming files in-place.
  -l  --list            Prints paths of non-conforming files. Exits with an error if any are found.
  -d  --diff            Prints differences of non-conforming files. Exits with an error if any are found.
  -i  --indentation     Sets the indentation used [possible values: 'tabs', 'smart', '<num>'(spaces)].
                        - tabs: used by default.
                        - smart: based on the initial indentations in a file.
                        - <num>: number of spaces.
  -L  --line-length     Sets the max character line length. Default is 100.
  -h  --help            Prints this help information.
  -v  --version         Prints version information.

Environment Variables:
  NIM_DIFF_CMD          Sets a custom diff command that is used with the '-diff' option
                        E.g.: 'NIM_DIFFCMD="diff --color=always -U 2"'

Getting Started

Installation

Editor Setup

  • Neovim

    Register nimpretty_t in null-ls/none-ls

    local null_ls = require("null-ls")
    -- ...
    null_ls.register({
    	name = "nimpretty_t",
    	method = null_ls.methods.FORMATTING,
    	filetypes = { "nim" },
    	generator = null_ls.formatter({
    		command = "nimpretty_t",
    		args = { "-w", "$FILENAME" },
    		to_temp_file = true,
    	}),
    })

    A complementary tool regarding indentation for neovim is tabs-vs-spaces.nvim

  • VS Code / Codium

    Since nimpretty_t is a niche project in the Nim community, it is not yet clear whether it will have a user base that can benefit from its own VS Code extension. To save efforts the extension has not yet been completed. Until then, please use the Run on Save extension from emeraldwalk.

    // settings.json
    // ...
    "emeraldwalk.runonsave": {
    	"commands": [
    		{
    			"match": "\\.nim$",
    			"isAsync": true,
    			"cmd": "nimpretty_t -w ${file}"
    		}
    	]
    }