-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new option 'all' to output all matches #32
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,13 +118,18 @@ static void action_emit(tty_interface_t *state) { | |
/* ttyout should be flushed before outputting on stdout */ | ||
tty_close(state->tty); | ||
|
||
const char *selection = choices_get(state->choices, state->choices->selection); | ||
if (selection) { | ||
/* output the selected result */ | ||
printf("%s\n", selection); | ||
} else { | ||
/* No match, output the query instead */ | ||
printf("%s\n", state->search); | ||
unsigned int all = state->options->output_all; | ||
size_t start = all ? 0 : state->choices->selection; | ||
size_t end = all ? choices_available(state->choices) : start + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rest of the code doesn't use whitespace to line up the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the easyalign-plugin for vim. The above alignment would be done in 3 keystrokes (after selecting the region of interest). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sure is prettier, but I think it's bad. Say you add a fourth statement with a longer type and variable name, now you have to update 4 lines of code. If you just always use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plus having to select code and run the macro is also too much hassle, for it to be worth it (ignoring the source control issues) it would have to automatically detect consecutive assignments and update them all without needing any user selection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. It's not important to me at all, I'd change that in a heart beat if it would stand in the way of the patch being accepted. |
||
for (size_t i = start; i < end; i++) { | ||
const char *selection = choices_get(state->choices, i); | ||
if (selection) { | ||
/* output the selected result */ | ||
printf("%s\n", selection); | ||
} else { | ||
/* No match, output the query instead */ | ||
printf("%s\n", state->search); | ||
} | ||
} | ||
|
||
state->exit = EXIT_SUCCESS; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, vim inserted a tab and I didn't notice the other lines were spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:set smarttab
in your vim config.