@@ -1151,13 +1151,14 @@ def __del__(self) -> None:
11511151# To match, e.g. ~5/8-~2/3, or ~4 (without trailing slash for full session)
11521152# Session numbers: ~N or N/
11531153# Line numbers: N (just digits, no ~ and no /)
1154+ # Range syntax: 4-6 (with end) or 4- (without end, means "onward")
11541155range_re = re .compile (
11551156 r"""
11561157((?P<startsess>(?:~\d+/?|\d+/)))?
11571158(?P<start>\d+)?
11581159((?P<sep>[\-:])
11591160 ((?P<endsess>(?:~\d+/?|\d+/)))?
1160- (?P<end>\d+ ))?
1161+ (?P<end>\d* ))?
11611162$""" ,
11621163 re .VERBOSE ,
11631164)
@@ -1175,6 +1176,10 @@ def extract_hist_ranges(ranges_str: str) -> Iterable[tuple[int, int, Optional[in
11751176 [(-8, 5, None), (-7, 1, 5), (0, 2, 3)]
11761177 >>> list(extract_hist_ranges("~4"))
11771178 [(-4, 1, None)] # Full session 4 (trailing / is optional)
1179+ >>> list(extract_hist_ranges("4-"))
1180+ [(0, 4, None)] # From line 4 onward (to end)
1181+ >>> list(extract_hist_ranges("~4/4-"))
1182+ [(-4, 4, None)] # From line 4 onward in session 4
11781183 """
11791184 if ranges_str == "" :
11801185 yield (0 , 1 , None ) # Everything from current session
@@ -1185,23 +1190,21 @@ def extract_hist_ranges(ranges_str: str) -> Iterable[tuple[int, int, Optional[in
11851190 if not rmatch :
11861191 continue
11871192 start = rmatch .group ("start" )
1193+ sep = rmatch .group ("sep" )
11881194 if start :
11891195 start = int (start )
11901196 end = rmatch .group ("end" )
1191- # If no end specified, get (a, a + 1)
1192- end = int (end ) if end else start + 1
1193- else : # start not specified
1194- if not rmatch .group ("startsess" ): # no startsess
1197+ if sep == "-" :
1198+ end = (int (end ) + 1 ) if end else None
1199+ else :
1200+ end = int (end ) if end else start + 1
1201+ else :
1202+ if not rmatch .group ("startsess" ):
11951203 continue
11961204 start = 1
1197- end = None # provide the entire session hist
1198-
1199- if rmatch .group ("sep" ) == "-" : # 1-3 == 1:4 --> [1, 2, 3]
1200- assert end is not None
1201- end += 1
1205+ end = None
12021206 startsess = rmatch .group ("startsess" ) or "0"
12031207 endsess = rmatch .group ("endsess" ) or startsess
1204- # Strip trailing / from session numbers (e.g., "~4/" -> "~4", "4/" -> "4")
12051208 startsess = startsess .rstrip ("/" )
12061209 endsess = endsess .rstrip ("/" )
12071210 startsess = int (startsess .replace ("~" , "-" ))
0 commit comments