本文整理汇总了Python中pygments.util.format_lines方法的典型用法代码示例。如果您正苦于以下问题:Python util.format_lines方法的具体用法?Python util.format_lines怎么用?Python util.format_lines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.util
的用法示例。
在下文中一共展示了util.format_lines方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_consts
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def update_consts(filename, constname, content):
with open(filename) as f:
data = f.read()
# Line to start/end inserting
re_match = re.compile(r'^%s\s*=\s*\($.*?^\s*\)$' % constname, re.M | re.S)
m = re_match.search(data)
if not m:
raise ValueError('Could not find existing definition for %s' %
(constname,))
new_block = format_lines(constname, content)
data = data[:m.start()] + new_block + data[m.end():]
with open(filename, 'w') as f:
f.write(data)
示例2: regenerate
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def regenerate(filename, natives):
with open(filename) as fp:
content = fp.read()
header = content[:content.find('FUNCTIONS = (')]
footer = content[content.find("if __name__ == '__main__':")-1:]
with open(filename, 'w') as fp:
fp.write(header)
fp.write(format_lines('FUNCTIONS', natives))
fp.write(footer)
示例3: test_format_lines
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def test_format_lines():
lst = ['cat', 'dog']
output = util.format_lines('var', lst)
d = {}
exec(output, d)
assert isinstance(d['var'], tuple)
assert ('cat', 'dog') == d['var']
示例4: getkw
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import format_lines [as 别名]
def getkw(input, output):
out = file(output, 'w')
# Copy template from an existing file.
print(HEADER, file=out)
output_info = {'command': [], 'option': [], 'auto': []}
for line in file(input):
m = r_line.match(line)
if m:
# Decide which output gets mapped to d
if 'vimCommand' in m.group(1):
d = output_info['command']
elif 'AutoEvent' in m.group(1):
d = output_info['auto']
else:
d = output_info['option']
# Extract all the shortened versions
for i in r_item.finditer(m.group(2)):
d.append('(%r,%r)' %
(i.group(1), "%s%s" % (i.group(1), i.group(2) or '')))
output_info['option'].append("('nnoremap','nnoremap')")
output_info['option'].append("('inoremap','inoremap')")
output_info['option'].append("('vnoremap','vnoremap')")
for key, keywordlist in output_info.items():
keywordlist.sort()
body = format_lines('var', keywordlist, raw=True, indent_level=1)
print(METHOD % locals(), file=out)