diff --git a/.gitignore b/.gitignore index 7918af7..c2e2de3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ bin .dub dub.selections.json .gdb_history -dfmt +bin/dfmt diff --git a/README.md b/README.md index 105eea2..2b234b1 100644 --- a/README.md +++ b/README.md @@ -89,13 +89,14 @@ Property Name | Allowed Values | Default Value | Description --------------|----------------|---------------|------------ dfmt_brace_style | `allman`, `otbs`, or `stroustrup` | `allman` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style) dfmt_soft_max_line_length | positive integers | `80` | The formatting process will usually keep lines below this length, but they may be up to max_line_length columns long. -dfmt_align_switch_statements (Not yet implemented) | `true`, `false` | `true` | Align labels, cases, and defaults with their enclosing switch -dfmt_outdent_attributes (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation level of attributes -dfmt_split_operator_at_line_end | `true`, `false` | `false` | Place operators on the end of the previous line when splitting lines -dfmt_space_after_cast | `true`, `false` | `true` | Insert space after the closing paren of a `cast` expression -dfmt_space_after_keywords (Not yet implemented) | `true`, `false` | `true` | Insert space after `if`, `while`, `foreach`, etc, and before the `(` -dfmt_selective_import_space | `true`, `false` | `true` | Insert space after the module name and before the `:` for selective imports -dfmt_compact_labeled_statements | `true`, `false` | `true` | Place labels on the same line as the labeled `switch`, `for`, `foreach`, or `while` statement +dfmt_align_switch_statements (Not yet implemented) | `true`, `false` | `true` | Align labels, cases, and defaults with their enclosing switch. +dfmt_outdent_attributes (Not yet implemented) | `true`, `false` | `true` | Decrease the indentation level of attributes. +dfmt_split_operator_at_line_end | `true`, `false` | `false` | Place operators on the end of the previous line when splitting lines. +dfmt_space_after_cast | `true`, `false` | `true` | Insert space after the closing paren of a `cast` expression. +dfmt_space_after_keywords (Not yet implemented) | `true`, `false` | `true` | Insert space after `if`, `while`, `foreach`, etc, and before the `(`. +dfmt_selective_import_space | `true`, `false` | `true` | Insert space after the module name and before the `:` for selective imports. +dfmt_compact_labeled_statements | `true`, `false` | `true` | Place labels on the same line as the labeled `switch`, `for`, `foreach`, or `while` statement. +dfmt_template_constraint_style | `conditional_newline_indent` `conditional_newline` `always_newline` `always_newline_indent` | `conditional_newline_indent` | Control the formatting of template constraints. ## Terminology * Braces - `{` and `}` diff --git a/bash-completion/completion/dfmt b/bash-completion/completion/dfmt new file mode 100644 index 0000000..d21e0eb --- /dev/null +++ b/bash-completion/completion/dfmt @@ -0,0 +1,45 @@ +# Completion for dfmt +_dfmt() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="--help -h --inplace -i --version --align_switch_statements --brace_style\ + --end_of_line --indent_size --indent_style -t --soft_max_line_length\ + --max_line_length --outdent_attributes --space_after_cast\ + --selective_import_space --split_operator_at_line_end\ + --compact_labeled_statements --template_constraint_style" + eolOpts="lf cr crlf" + braceOpts="allman otbs stroustrup" + indentOpts="tab space" + constraintOpts="conditional_newline_indent conditional_newline always_newline always_newline_indent" + if [[ ${cur} == -* ]]; then + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0; + fi + case "${prev}" in + "--brace_style") + COMPREPLY=($(compgen -W "${braceOpts}" -- ${cur})) + return 0 + ;; + "--end_of_line") + COMPREPLY=($(compgen -W "${eolOpts}" -- ${cur})) + return 0 + ;; + "-t") + ;& + "--indent_style") + COMPREPLY=($(compgen -W "${indentOpts}" -- ${cur})) + return 0 + ;; + "--template_constraint_style") + COMPREPLY=($(compgen -W "${constraintOpts}" -- ${cur})) + return 0 + ;; + *) + ;; + esac + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) +} +complete -F _dfmt dfmt diff --git a/src/dfmt/main.d b/src/dfmt/main.d index afa75e4..2fa1912 100644 --- a/src/dfmt/main.d +++ b/src/dfmt/main.d @@ -184,12 +184,14 @@ else private string optionsToString(E)() if (is(E == enum)) { import std.traits : EnumMembers; - import std.conv; + import std.conv : to; string result = "["; foreach (i, option; EnumMembers!E) { - result ~= to!string(option) ~ "|"; + immutable s = to!string(option); + if (s != "unspecified") + result ~= s ~ "|"; } result = result[0 .. $ - 1] ~ "]"; return result; @@ -209,7 +211,8 @@ Formatting Options: --align_switch_statements --brace_style `, optionsToString!(typeof(Config.dfmt_brace_style))(), ` - --end_of_line + --end_of_line `, + optionsToString!(typeof(Config.end_of_line))(), ` --help|h --indent_size --indent_style|t `,