@@ -1099,43 +1099,77 @@ class TextBuffer
10991099 # {::backwardsScan} to avoid tripping over your own changes.
11001100 #
11011101 # * `regex` A {RegExp} to search for.
1102+ # * `options` (optional) {Object}
1103+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1104+ # matched line to include in the results object.
1105+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1106+ # matched line to include in the results object.
11021107 # * `iterator` A {Function} that's called on each match with an {Object}
11031108 # containing the following keys:
11041109 # * `match` The current regular expression match.
11051110 # * `matchText` A {String} with the text of the match.
11061111 # * `range` The {Range} of the match.
11071112 # * `stop` Call this {Function} to terminate the scan.
11081113 # * `replace` Call this {Function} with a {String} to replace the match.
1109- scan : (regex , iterator ) ->
1110- @ scanInRange (regex, @ getRange (), iterator)
1114+ # * `leadingContextLines` An {Array} with `leadingContextLineCount` lines before the match.
1115+ # * `trailingContextLines` An {Array} with `trailingContextLineCount` lines after the match.
1116+ scan : (regex , options = {}, iterator ) ->
1117+ if _ .isFunction (options)
1118+ iterator = options
1119+ options = {}
1120+
1121+ @ scanInRange (regex, @ getRange (), options, iterator)
11111122
11121123 # Public: Scan regular expression matches in the entire buffer in reverse
11131124 # order, calling the given iterator function on each match.
11141125 #
11151126 # * `regex` A {RegExp} to search for.
1127+ # * `options` (optional) {Object}
1128+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1129+ # matched line to include in the results object.
1130+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1131+ # matched line to include in the results object.
11161132 # * `iterator` A {Function} that's called on each match with an {Object}
11171133 # containing the following keys:
11181134 # * `match` The current regular expression match.
11191135 # * `matchText` A {String} with the text of the match.
11201136 # * `range` The {Range} of the match.
11211137 # * `stop` Call this {Function} to terminate the scan.
11221138 # * `replace` Call this {Function} with a {String} to replace the match.
1123- backwardsScan : (regex , iterator ) ->
1124- @ backwardsScanInRange (regex, @ getRange (), iterator)
1139+ # * `leadingContextLines` An {Array} with `leadingContextLineCount` lines before the match.
1140+ # * `trailingContextLines` An {Array} with `trailingContextLineCount` lines after the match.
1141+ backwardsScan : (regex , options = {}, iterator ) ->
1142+ if _ .isFunction (options)
1143+ iterator = options
1144+ options = {}
1145+
1146+ @ backwardsScanInRange (regex, @ getRange (), options, iterator)
11251147
11261148 # Public: Scan regular expression matches in a given range , calling the given
11271149 # iterator function on each match.
11281150 #
11291151 # * `regex` A {RegExp} to search for.
11301152 # * `range` A {Range} in which to search.
1153+ # * `options` (optional) {Object}
1154+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1155+ # matched line to include in the results object.
1156+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1157+ # matched line to include in the results object.
11311158 # * `callback` A {Function} that's called on each match with an {Object}
11321159 # containing the following keys:
11331160 # * `match` The current regular expression match.
11341161 # * `matchText` A {String} with the text of the match.
11351162 # * `range` The {Range} of the match.
11361163 # * `stop` Call this {Function} to terminate the scan.
11371164 # * `replace` Call this {Function} with a {String} to replace the match.
1138- scanInRange : (regex , range , callback , reverse = false ) ->
1165+ # * `leadingContextLines` An {Array} with `leadingContextLineCount` lines before the match.
1166+ # * `trailingContextLines` An {Array} with `trailingContextLineCount` lines after the match.
1167+ scanInRange : (regex , range , options = {}, callback , reverse = false ) ->
1168+ if _ .isFunction (options)
1169+ reverse = callback
1170+ callback = options
1171+ options = {}
1172+
11391173 range = @ clipRange (range)
11401174 global = regex .global
11411175 flags = " gm"
@@ -1144,14 +1178,14 @@ class TextBuffer
11441178
11451179 if regexIsSingleLine (regex)
11461180 if reverse
1147- iterator = new MatchIterator.BackwardsSingleLine (this , regex, range)
1181+ iterator = new MatchIterator.BackwardsSingleLine (this , regex, range, options )
11481182 else
1149- iterator = new MatchIterator.ForwardsSingleLine (this , regex, range)
1183+ iterator = new MatchIterator.ForwardsSingleLine (this , regex, range, options )
11501184 else
11511185 if reverse
1152- iterator = new MatchIterator.BackwardsMultiLine (this , regex, range, @backwardsScanChunkSize )
1186+ iterator = new MatchIterator.BackwardsMultiLine (this , regex, range, @backwardsScanChunkSize , options )
11531187 else
1154- iterator = new MatchIterator.ForwardsMultiLine (this , regex, range)
1188+ iterator = new MatchIterator.ForwardsMultiLine (this , regex, range, options )
11551189
11561190 iterator .iterate (callback, global )
11571191
@@ -1160,15 +1194,24 @@ class TextBuffer
11601194 #
11611195 # * `regex` A {RegExp} to search for.
11621196 # * `range` A {Range} in which to search.
1197+ # * `options` (optional) {Object}
1198+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1199+ # matched line to include in the results object.
1200+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1201+ # matched line to include in the results object.
11631202 # * `iterator` A {Function} that's called on each match with an {Object}
11641203 # containing the following keys:
11651204 # * `match` The current regular expression match.
11661205 # * `matchText` A {String} with the text of the match.
11671206 # * `range` The {Range} of the match.
11681207 # * `stop` Call this {Function} to terminate the scan.
11691208 # * `replace` Call this {Function} with a {String} to replace the match.
1170- backwardsScanInRange : (regex , range , iterator ) ->
1171- @ scanInRange regex, range, iterator, true
1209+ backwardsScanInRange : (regex , range , options = {}, iterator ) ->
1210+ if _ .isFunction (options)
1211+ iterator = options
1212+ options = {}
1213+
1214+ @ scanInRange regex, range, options, iterator, true
11721215
11731216 # Public: Replace all regular expression matches in the entire buffer.
11741217 #
0 commit comments