Skip to content
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

Parameters for subcommands do not have spaces #63

Open
mpldr opened this issue Mar 5, 2025 · 3 comments
Open

Parameters for subcommands do not have spaces #63

mpldr opened this issue Mar 5, 2025 · 3 comments

Comments

@mpldr
Copy link

mpldr commented Mar 5, 2025

Given the following grammar:

aerc [<OPTION>]...;
aerc [<OPTION>]... mbox:<PATH>;
aerc [<OPTION>]... mailto:<MAILTOLINK>;
aerc [<OPTION>]... :<COMMAND>;

# shortened for brevity

<COMMAND> ::= (help <topic> | man <topic>) "show help page inside aerc"
	# shortened for brevity
	| (quit <QUIT_ARGS> | exit <QUIT_ARGS> | q <QUIT_ARGS>) "exit aerc"
	| (redraw) "force a full redraw of the screen"
	;

<QUIT_ARGS> ::= ( -f) "force close aerc"
	;

The completion looks like this:

https://asciinema.org/a/YXLgujQoQ1MkMyiS2HT8fzNGK

My (uneducated) guess would be that spaces in ()-groups are trimmed, but not just at the start and end, but also in-between.

@adaszko
Copy link
Owner

adaszko commented Mar 5, 2025

Hi and thanks for reporting.

So the problem is aerc :quit<TAB> completes to aerc :quit-f whereas you expect it to complete to aerc :quit<SPACE>? Is that right?

If that's the case, the grammar can be further simplified to:

aerc :<COMMAND>;
<COMMAND> ::= quit -f;

What's happening here is the in first line (aerc :<COMMAND>), because there's no space between : and <COMMAND>, you're telling complgen that the entirety of :<COMMAND> is going to be just a single shell word (!) This is what's called subword mode and it propagates recursively downward to all <NONTERMINAL>s. That propagation includes ignoring the space in quit -f, which is actually expected behavior.

For :quit to be completed as an entire word, you need to lift it up in the grammar, e.g.:

aerc (:help <topic> | :man <topic>) "show help page inside aerc";
aerc (:quit <QUIT_ARGS> | :exit <QUIT_ARGS> | :q <QUIT_ARGS>) "exit aerc";
<QUIT_ARGS> ::= ( -f) "force close aerc";

What I can do to make it more obvious, is I can issue a warning/error whenever there's a suspicious space used in a subword mode.

@adaszko
Copy link
Owner

adaszko commented Mar 5, 2025

Or even more concisely:

aerc ((:help | :man) <topic>) "show help page inside aerc";
aerc ((:quit | :exit | :q) <QUIT_ARGS>) "exit aerc";
<QUIT_ARGS> ::= -f "force close aerc";

@mpldr
Copy link
Author

mpldr commented Mar 5, 2025

Thanks, that makes sense… in this case I explicitly wanted to keep the : as its own completion as to not pollute the list too much. (essentially, everything starting with : is a command to be sent to the running instance. With there being 21 commands, this gets a bit overwhelming ._.

I assume right now that option is not a given?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants