mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-15 06:31:13 -03:00
Deroffing completion work
This commit is contained in:
@@ -71,7 +71,7 @@ def unquoteSingleQuotes(data):
|
||||
|
||||
# Make a string of characters that are deemed safe in fish without needing to be escaped
|
||||
# Note that space is not included
|
||||
g_fish_safe_chars = frozenset(string.ascii_letters + string.digits + '_+-|/:=<>@~')
|
||||
g_fish_safe_chars = frozenset(string.ascii_letters + string.digits + '_+-|/:=@~')
|
||||
|
||||
def fish_escape_single_quote(str):
|
||||
# Escape a string if necessary so that it can be put in single quotes
|
||||
@@ -96,6 +96,11 @@ def builtcommand(options, description):
|
||||
man_optionlist = re.split(" |,|\"|=|[|]", options)
|
||||
fish_options = []
|
||||
for option in man_optionlist:
|
||||
option = option.strip()
|
||||
|
||||
# Skip some problematic cases
|
||||
if option in ['-', '--']: continue
|
||||
|
||||
if option.startswith('--'):
|
||||
# New style long option (--recursive)
|
||||
fish_options.append('-l ' + fish_escape_single_quote(option[2:]))
|
||||
@@ -563,10 +568,18 @@ class TypeDeroffManParser(ManParser):
|
||||
while lines and not (lines[0].startswith('DESCRIPTION') or lines[0].startswith('OPTIONS') or lines[0].startswith('COMMAND OPTIONS')):
|
||||
lines.pop(0)
|
||||
|
||||
# Look for BUGS and stop there
|
||||
for idx in xrange(len(lines)):
|
||||
line = lines[idx]
|
||||
if line.startswith('BUGS'):
|
||||
# Drop remaining elements
|
||||
lines[idx:] = []
|
||||
break
|
||||
|
||||
while lines:
|
||||
# Pop until we get to the next option
|
||||
while lines and not self.is_option(lines[0]):
|
||||
lines.pop(0)
|
||||
line = lines.pop(0)
|
||||
|
||||
if not lines:
|
||||
continue
|
||||
@@ -690,7 +703,7 @@ if __name__ == "__main__":
|
||||
VERBOSE = True
|
||||
args.pop(0)
|
||||
|
||||
if False:
|
||||
if True:
|
||||
parse_and_output_man_pages(args)
|
||||
else:
|
||||
# Profiling code
|
||||
|
||||
@@ -8,7 +8,7 @@ class Deroffer:
|
||||
|
||||
def __init__(self):
|
||||
self.reg_table = {}
|
||||
self.tr = range(256)
|
||||
self.tr = {}
|
||||
self.nls = 2
|
||||
self.specletter = False
|
||||
self.pretty = False
|
||||
@@ -42,13 +42,12 @@ class Deroffer:
|
||||
return ''.join(self.output)
|
||||
|
||||
def putchar(self, c):
|
||||
self.output.append(c)
|
||||
if c != '\n' or self.output:
|
||||
self.output.append(c)
|
||||
return c
|
||||
|
||||
def condputchar(self, c):
|
||||
ci = ord(c)
|
||||
ci_trans = self.tr[ci & 0xFF]
|
||||
c_trans = chr(ci_trans)
|
||||
c_trans = self.tr.get(c, c)
|
||||
if not self.pic and not self.eqn and not self.refer and not self.macro and (not self.skiplists or not self.inlist) and (not self.skipheaders or not self.inheader):
|
||||
if self.pretty:
|
||||
if c == '\n':
|
||||
@@ -483,13 +482,10 @@ class Deroffer:
|
||||
return False
|
||||
|
||||
def text(self):
|
||||
while True:
|
||||
while self.s:
|
||||
if not self.esc_char():
|
||||
if self.str_at(0):
|
||||
self.condputchar(self.str_at(0))
|
||||
self.skip_char()
|
||||
else:
|
||||
break
|
||||
self.condputchar(self.str_at(0))
|
||||
self.skip_char()
|
||||
return True
|
||||
|
||||
|
||||
@@ -669,9 +665,9 @@ class Deroffer:
|
||||
ns = self.str_at(0)
|
||||
self.skip_char()
|
||||
if not ns or ns == '\n':
|
||||
self.tr[c] = ord(' ')
|
||||
self.tr[c] = ' '
|
||||
else:
|
||||
self.tr[c] = ord(ns)
|
||||
self.tr[c] = ns
|
||||
return True
|
||||
elif s0s1 in ['sp']:
|
||||
if self.pretty: self.condputchar('\n')
|
||||
@@ -747,11 +743,14 @@ class Deroffer:
|
||||
return True
|
||||
|
||||
def do_line(self):
|
||||
if not self.s: return True
|
||||
if self.str_at(0) == '.' or self.str_at(0) == '\'':
|
||||
ch = self.str_at(0)
|
||||
if ch == '.' or ch == '\'':
|
||||
if not self.request_or_macro(): return False
|
||||
elif self.tbl:
|
||||
self.do_tbl()
|
||||
elif '\\' not in self.s:
|
||||
# Fast check for common case of simple string
|
||||
self.condputs(self.s)
|
||||
else:
|
||||
self.text()
|
||||
return True
|
||||
@@ -782,7 +781,7 @@ def deroff_files(files):
|
||||
if __name__ == "__main__":
|
||||
import gzip
|
||||
paths = sys.argv[1:]
|
||||
if True:
|
||||
if False:
|
||||
deroff_files(paths)
|
||||
else:
|
||||
import cProfile, pstats
|
||||
|
||||
Reference in New Issue
Block a user