Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/diffpy/srfit/fitbase/recipeorganizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@ def _formatRestraints(self):
rlines.sort(key=numstr)
return rlines

def _is_single_or_matches_pattern(self, s):
return len(s.split(None, 1)) < 2 or self._regexp.search(s.split(None, 1)[0])

def show(self, pattern="", textwidth=78):
"""Show the configuration hierarchy on the screen.

Expand All @@ -947,14 +950,14 @@ def show(self, pattern="", textwidth=78):
Trim formatted lines at this text width to avoid folding at
the screen width. Do not trim when negative or 0.
"""
regexp = re.compile(pattern)
pmatch = lambda s: (len(s.split(None, 1)) < 2 or regexp.search(s.split(None, 1)[0]))
self._regexp = re.compile(pattern)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regexp is used twice in the function, storing as a private var.


# Show sub objects and their parameters
lines = []
tlines = self._formatManaged()
if tlines:
lines.extend(["Parameters", _DASHEDLINE])
linesok = filter(pmatch, tlines)
linesok = filter(self._is_single_or_matches_pattern, tlines)
lastnotblank = False
# squeeze repeated blank lines
for lastnotblank, g in groupby(linesok, bool):
Expand All @@ -965,7 +968,7 @@ def show(self, pattern="", textwidth=78):

# FIXME - parameter names in equations not particularly informative
# Show constraints
cmatch = regexp.search
cmatch = self._regexp.search
tlines = self._formatConstraints()
if tlines:
if lines:
Expand All @@ -980,7 +983,7 @@ def show(self, pattern="", textwidth=78):
if lines:
lines.append("")
lines.extend(["Restraints", _DASHEDLINE])
lines.extend(filter(pmatch, tlines))
lines.extend(filter(self._is_single_or_matches_pattern, tlines))

# Determine effective text width tw.
tw = textwidth if (textwidth is not None and textwidth > 0) else None
Expand Down