From 387826ba37c0e41119c4f50e70a783446ea59067 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 19 Jan 2016 19:48:28 -0800 Subject: [PATCH 1/5] Fix option printing --- src/dfmt/main.d | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dfmt/main.d b/src/dfmt/main.d index afa75e4..b8b0aee 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; From 3d7f55495afc8a518d46789f96b3a6e5c13b977d Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 19 Jan 2016 19:49:15 -0800 Subject: [PATCH 2/5] Document template constraint formatting options --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 105eea2..e89b4b6 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` | Control the formatting of template constraints. ## Terminology * Braces - `{` and `}` From fbd28814e73be4b11fc6dd45a00893d0bde918f8 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 19 Jan 2016 20:03:41 -0800 Subject: [PATCH 3/5] Fix missing cell in table --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e89b4b6..2b234b1 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ dfmt_space_after_cast | `true`, `false` | `true` | Insert space after the closin 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` | Control the formatting of template constraints. +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 `}` From 4c5dfb588119b33d63c3a91f0cb563e052a9116d Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 19 Jan 2016 20:09:01 -0800 Subject: [PATCH 4/5] Fix option printing --- src/dfmt/main.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dfmt/main.d b/src/dfmt/main.d index b8b0aee..2fa1912 100644 --- a/src/dfmt/main.d +++ b/src/dfmt/main.d @@ -211,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 `, From abe51015c498ace3a008762dbd35f77718b0ff39 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Tue, 19 Jan 2016 20:10:15 -0800 Subject: [PATCH 5/5] Add bash completion support. Fix #218 --- .gitignore | 2 +- bash-completion/completion/dfmt | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 bash-completion/completion/dfmt 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/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