import sys with open('0008-ns-announce-child-frame-completion-candidates-for-Vo.patch', 'r') as f: lines = f.readlines() # Find and fix the problematic hunk new_lines = [] i = 0 while i < len(lines): line = lines[i] # Skip lines 555-562 (0-indexed: 554-561) - the "If Emacs moved" DELETE block if i == 554: # Skip 8 lines (555-562) i += 8 continue # Skip lines 568-575 (0-indexed: 567-574) after adjustment (now 559-566) # After removing 8 lines, line 568 is now 560 in 0-indexed terms: 567-8=559 if i == 559: # Skip 8 lines (568-575 became 560-567) i += 8 continue # Change context lines to ADD lines # Line 566 (0-indexed 565, after adjustments 565-8=557) if i == 557: # Change the context line to ADD if line.startswith(' '): line = '+' + line[1:] # Line 567 (0-indexed 566, after adjustments 558) if i == 558: if line.startswith(' '): line = '+' + line[1:] # Line 581 (0-indexed 580, after adjustments: 580-16=564) if i == 564: if line.startswith(' '): line = '+' + line[1:] # Line 582 (0-indexed 581, after adjustments: 565) if i == 565: if line.startswith(' '): line = '+' + line[1:] new_lines.append(line) i += 1 with open('0008-ns-announce-child-frame-completion-candidates-for-Vo.patch', 'w') as f: f.writelines(new_lines) print("Done")