parent
6746aa4b5f
commit
a8757625c3
|
@ -1115,11 +1115,15 @@ show_marks yes
|
|||
Config files support line continuation, meaning when you end a line in a
|
||||
backslash character (`\`), the line-break will be ignored by the parser. This
|
||||
feature can be used to create more readable configuration files.
|
||||
Commented lines are not continued.
|
||||
|
||||
*Examples*:
|
||||
-------------------
|
||||
bindsym Mod1+f \
|
||||
fullscreen toggle
|
||||
|
||||
# this line is not continued \
|
||||
bindsym Mod1+F fullscreen toggle
|
||||
-------------------
|
||||
|
||||
== Configuring i3bar
|
||||
|
|
|
@ -846,17 +846,26 @@ bool parse_file(const char *f, bool use_nagbar) {
|
|||
if (buffer[strlen(buffer) - 1] != '\n' && !feof(fstr)) {
|
||||
ELOG("Your line continuation is too long, it exceeds %zd bytes\n", sizeof(buffer));
|
||||
}
|
||||
|
||||
/* sscanf implicitly strips whitespace. */
|
||||
const bool skip_line = (sscanf(buffer, "%511s %511[^\n]", key, value) < 1 || strlen(key) < 3);
|
||||
const bool comment = (key[0] == '#');
|
||||
|
||||
continuation = strstr(buffer, "\\\n");
|
||||
if (continuation) {
|
||||
continue;
|
||||
if (!comment) {
|
||||
continue;
|
||||
}
|
||||
DLOG("line continuation in comment is ignored: \"%.*s\"\n", (int)strlen(buffer) - 1, buffer);
|
||||
continuation = NULL;
|
||||
}
|
||||
|
||||
strncpy(buf + strlen(buf), buffer, strlen(buffer) + 1);
|
||||
|
||||
/* sscanf implicitly strips whitespace. Also, we skip comments and empty lines. */
|
||||
if (sscanf(buffer, "%511s %511[^\n]", key, value) < 1 ||
|
||||
key[0] == '#' || strlen(key) < 3)
|
||||
/* Skip comments and empty lines. */
|
||||
if (skip_line || comment) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcasecmp(key, "set") == 0) {
|
||||
if (value[0] != '$') {
|
||||
|
|
|
@ -198,4 +198,20 @@ EOT
|
|||
is(launch_get_border($config), 'none', 'no border');
|
||||
|
||||
|
||||
#####################################################################
|
||||
# test ignoring of line continuation within a comment
|
||||
#####################################################################
|
||||
|
||||
$config = <<'EOT';
|
||||
# i3 config file (v4)
|
||||
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
||||
|
||||
set $vartest \"special title\"
|
||||
for_window [title="$vartest"] border pixel 1
|
||||
# this line is not continued, so the following is not contained in this comment\
|
||||
for_window [title="$vartest"] border none
|
||||
EOT
|
||||
|
||||
is(launch_get_border($config), 'none', 'no border');
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue