[PATCH] D138234: [clang-format] Support new file formatting with vim
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG86278114085b: [clang-format] Support new file formatting with vim (authored by jsji). Changed prior to commit: https://reviews.llvm.org/D138234?vs=476905=476984#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D138234/new/ https://reviews.llvm.org/D138234 Files: clang/tools/clang-format/clang-format.py Index: clang/tools/clang-format/clang-format.py === --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -41,6 +41,7 @@ import difflib import json +import os.path import platform import subprocess import sys @@ -76,7 +77,8 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1': + elif vim.eval('exists("l:formatdiff")') == '1' and \ + os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer) Index: clang/tools/clang-format/clang-format.py === --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -41,6 +41,7 @@ import difflib import json +import os.path import platform import subprocess import sys @@ -76,7 +77,8 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1': + elif vim.eval('exists("l:formatdiff")') == '1' and \ + os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D138234: [clang-format] Support new file formatting with vim
owenpan accepted this revision. owenpan added a comment. This revision is now accepted and ready to land. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D138234/new/ https://reviews.llvm.org/D138234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D138234: [clang-format] Support new file formatting with vim
jsji updated this revision to Diff 476905. jsji added a comment. Address comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D138234/new/ https://reviews.llvm.org/D138234 Files: clang/tools/clang-format/clang-format.py Index: clang/tools/clang-format/clang-format.py === --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -41,11 +41,11 @@ import difflib import json +import os.path import platform import subprocess import sys import vim -import os.path # set g:clang_format_path to the path to clang-format if it is not on the path # Change this to the full path if clang-format is not on the path. @@ -77,7 +77,8 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1' and os.path.exists(vim.current.buffer.name): + elif vim.eval('exists("l:formatdiff")') == '1' and \ + os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer) Index: clang/tools/clang-format/clang-format.py === --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -41,11 +41,11 @@ import difflib import json +import os.path import platform import subprocess import sys import vim -import os.path # set g:clang_format_path to the path to clang-format if it is not on the path # Change this to the full path if clang-format is not on the path. @@ -77,7 +77,8 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1' and os.path.exists(vim.current.buffer.name): + elif vim.eval('exists("l:formatdiff")') == '1' and \ + os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D138234: [clang-format] Support new file formatting with vim
owenpan added inline comments. Comment at: clang/tools/clang-format/clang-format.py:48 import vim +import os.path Can you move it up to keep the module names sorted? Comment at: clang/tools/clang-format/clang-format.py:80 lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1': + elif vim.eval('exists("l:formatdiff")') == '1' and os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D138234/new/ https://reviews.llvm.org/D138234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D138234: [clang-format] Support new file formatting with vim
jsji created this revision. jsji added reviewers: djasper, klimek. Herald added a project: All. jsji requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. The vim Formatonsave integration is not working if we create a new file directly using vim. eg: vi -V9t.log t.cpp It will not able to format the buffer. Traceback (most recent call last): File "", line 1, in File "...clang/tools/clang-format/clang-format.py", line 156, in main() File "...clang/tools/clang-format/clang-format.py", line 80, in main with open(vim.current.buffer.name, 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: '...t.cpp' This patch check the file before we try to open it. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D138234 Files: clang/tools/clang-format/clang-format.py Index: clang/tools/clang-format/clang-format.py === --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -45,6 +45,7 @@ import subprocess import sys import vim +import os.path # set g:clang_format_path to the path to clang-format if it is not on the path # Change this to the full path if clang-format is not on the path. @@ -76,7 +77,7 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1': + elif vim.eval('exists("l:formatdiff")') == '1' and os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer) Index: clang/tools/clang-format/clang-format.py === --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -45,6 +45,7 @@ import subprocess import sys import vim +import os.path # set g:clang_format_path to the path to clang-format if it is not on the path # Change this to the full path if clang-format is not on the path. @@ -76,7 +77,7 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1': + elif vim.eval('exists("l:formatdiff")') == '1' and os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits