diff --git a/docs/changelog.rst b/docs/changelog.rst index a5d011570..49e702b65 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -74,6 +74,8 @@ Detailed list of changes - When multiple confirmable close requests are made focus the existing close confirmation window instead of opening a new one for each request (:iss:`6601`) +- Config file format: allow splitting lines by starting subsequent lines with a backslash (:pull:`6603`) + 0.29.2 [2023-07-27] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index 35123f85e..64e1761cf 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -264,44 +264,40 @@ def _parse( base_path_for_includes = config_dir it = iter(lines) - line: str - nextLine: str = "" - nextLineNum = 0 + line = '' + next_line: str = '' + next_line_num = 0 while True: try: - if nextLine != "": - line = nextLine + if next_line: + line = next_line else: line = next(it).lstrip() - nextLineNum += 1 - lineNum = nextLineNum + next_line_num += 1 + line_num = next_line_num try: - nextLine = next(it).lstrip() - nextLineNum += 1 + next_line = next(it).lstrip() + next_line_num += 1 - while nextLine.startswith('\\'): - if line.endswith("\n"): - line = line[:-1] - line += nextLine[1:] + while next_line.startswith('\\'): + line = line.rstrip('\n') + next_line[1:] try: - nextLine = next(it).lstrip() - nextLineNum += 1 + next_line = next(it).lstrip() + next_line_num += 1 except StopIteration: - nextLine = "" + next_line = '' break except StopIteration: - nextLine = "" - pass - + next_line = '' try: - with currently_parsing.set_line(line, lineNum): + with currently_parsing.set_line(line, line_num): parse_line(line, parse_conf_item, ans, base_path_for_includes, accumulate_bad_lines) except Exception as e: if accumulate_bad_lines is None: raise - accumulate_bad_lines.append(BadLine(lineNum, line.rstrip(), e, currently_parsing.file)) + accumulate_bad_lines.append(BadLine(line_num, line.rstrip(), e, currently_parsing.file)) except StopIteration: break diff --git a/tools/config/api.go b/tools/config/api.go index 50d7657ed..99be6a71e 100644 --- a/tools/config/api.go +++ b/tools/config/api.go @@ -74,41 +74,41 @@ func (self *ConfigParser) parse(scanner Scanner, name, base_path_for_includes st } lnum := 0 - nextLineNum := 0 - nextLine := "" - var line string + next_line_num := 0 + next_line := "" + var line string for { - if nextLine != "" { - line = nextLine - } else { + if next_line != "" { + line = next_line + } else { if scanner.Scan() { line = strings.TrimLeft(scanner.Text(), " \t") + next_line_num++ } else { break } - nextLineNum++ if line == "" { continue } - } - lnum = nextLineNum - if scanner.Scan() { - nextLine = strings.TrimLeft(scanner.Text(), " \t") - nextLineNum++ + } + lnum = next_line_num + if scanner.Scan() { + next_line = strings.TrimLeft(scanner.Text(), " \t") + next_line_num++ - for nextLine != "" && nextLine[0] == '\\' { - line += nextLine[1:] - if scanner.Scan() { - nextLine = strings.TrimLeft(scanner.Text(), " \t") - nextLineNum++ + for strings.HasPrefix(next_line, `\`) { + line += next_line[1:] + if scanner.Scan() { + next_line = strings.TrimLeft(scanner.Text(), " \t") + next_line_num++ } else { - nextLine = "" - } - } - } else { - nextLine = "" - } + next_line = "" + } + } + } else { + next_line = "" + } if line[0] == '#' { if self.CommentsHandler != nil {