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

[DO NOT MERGE] config: allow for inline to end of line comments #3054

Closed
wants to merge 2 commits into from

Conversation

RedSoxFan
Copy link
Member

@RedSoxFan RedSoxFan commented Nov 3, 2018

THIS IS BRANCHED FROM #2979 SO THAT NEEDS TO BE MERGED FIRST

Closes #3044

Allows for the following syntax in the config: command <arguments...> # the rest of this line is a comment
Example: input * repeat_delay 200 # milliseconds

Note: The space before and after the # is mandatory otherwise the # will be seen as part of an argument (such as colors). If a # is needed as it's own argument, then it can be enclosed in quotes. For example, bar bar-0 separator_symbol "#".

Currently, variables cannot contain commands and cannot span more than
one argument. This is due to variable replacement happening after
determining the handler and after splitting the config line into
arguments.

This changes the process to:
0. Check for empty lines and block boundaries
1. Split the arguments as before
2. Verify that the first argument is not a variable. If needed the
following occurs
    a. Perform variable replacement on just the first argument
    b. Join the arguments back together then split the arguments again. This is needed when the variable
contains the command and arguments for the command.
3. Determine the handler
4. If the handler is cmd_set, escape the variable name so that it does
not get replaced
5. Join the arguments back together, do variable replacement on the full
command, and split the arguments again
6. Perform any needed quote stripping or unescaping on arguments
7. Run the command handler

This allows for config snippets such as:

```
set $super bindsym Mod4
$super+a exec some-command
```

and

```
set $bg bg #ffffff solid_color
output * $bg
```
Allows for the following syntax in the config:
    `command <arguments...> # the rest of this line is a comment`
Example:
    `input * repeat_delay 200 # milliseconds`

Note: The space before and after the `#` is mandatory otherwise the
`#` will be seen as part of an argument (such as colors). If a `#`
is needed as it's own argument, then it can be enclosed in quotes. For
example, `bar bar-0 separator_symbol "#"`.
@bl33pbl0p
Copy link

How about using something else for comments? (// or /* */)

@ascent12
Copy link
Member

ascent12 commented Nov 3, 2018

The computer scientist in me really hates this. It's such a subtle difference and leads to "# " becoming a token in the grammar (even if it's not implemented that way).
I would either argue for leaving it alone, or breaking i3 compatibility and using a different syntax for colours.

@ddevault
Copy link
Contributor

ddevault commented Nov 3, 2018

This is deliberately unsupported. Consider colors, for example.

@ddevault ddevault closed this Nov 3, 2018
@emersion
Copy link
Member

emersion commented Nov 3, 2018

Consider colors, for example.

This PR allowed comments at the end of line only if # is followed by a space. This ensures colors still work.

Still not sure it's a good idea.

@ddevault
Copy link
Contributor

ddevault commented Nov 3, 2018

Gotcha. Still not a fan of it.

@RedSoxFan RedSoxFan deleted the config-mixed-lines branch November 26, 2018 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Lines with mixed commands and comments
5 participants