summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2023-06-03 14:46:19 +0100
committerBasil L. Contovounesios <contovob@tcd.ie>2023-07-08 16:35:09 +0100
commitac57358762b42a7f0d7f70ce55ed0e7c4b540d16 (patch)
treee21faf2ba6d9f2b344b9663969b4813fe7777ada /src/search.c
parent1a9d454ebf661eb15ef3597c9c17dc59b9c63ee2 (diff)
downloademacs-ac57358762b42a7f0d7f70ce55ed0e7c4b540d16.tar.gz
Minor search_buffer cleanup
* src/search.c: Move commentary that used to precede search_buffer to that location once more. Update it for the current arglist. (search_command, search_buffer_non_re, search_buffer): * src/lisp.h (search_buffer): Turn RE flag/argument from an int into a bool. All callers changed (bug#64049).
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/search.c b/src/search.c
index 0bb52c03eef..122d6166637 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1027,7 +1027,7 @@ find_before_next_newline (ptrdiff_t from, ptrdiff_t to,
static Lisp_Object
search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
- Lisp_Object count, int direction, int RE, bool posix)
+ Lisp_Object count, int direction, bool RE, bool posix)
{
EMACS_INT np;
EMACS_INT lim;
@@ -1130,21 +1130,6 @@ trivial_regexp_p (Lisp_Object regexp)
return 1;
}
-/* Search for the n'th occurrence of STRING in the current buffer,
- starting at position POS and stopping at position LIM,
- treating STRING as a literal string if RE is false or as
- a regular expression if RE is true.
-
- If N is positive, searching is forward and LIM must be greater than POS.
- If N is negative, searching is backward and LIM must be less than POS.
-
- Returns -x if x occurrences remain to be found (x > 0),
- or else the position at the beginning of the Nth occurrence
- (if searching backward) or the end (if searching forward).
-
- POSIX is nonzero if we want full backtracking (POSIX style)
- for this pattern. 0 means backtrack only enough to get a valid match. */
-
#define TRANSLATE(out, trt, d) \
do \
{ \
@@ -1308,7 +1293,7 @@ search_buffer_re (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
static EMACS_INT
search_buffer_non_re (Lisp_Object string, ptrdiff_t pos,
ptrdiff_t pos_byte, ptrdiff_t lim, ptrdiff_t lim_byte,
- EMACS_INT n, int RE, Lisp_Object trt, Lisp_Object inverse_trt,
+ EMACS_INT n, bool RE, Lisp_Object trt, Lisp_Object inverse_trt,
bool posix)
{
unsigned char *raw_pattern, *pat;
@@ -1507,10 +1492,28 @@ search_buffer_non_re (Lisp_Object string, ptrdiff_t pos,
return result;
}
+/* Search for the Nth occurrence of STRING in the current buffer,
+ from buffer position POS/POS_BYTE until LIM/LIM_BYTE.
+
+ If RE, look for matches against the regular expression STRING instead;
+ if POSIX, enable POSIX style backtracking within that regular
+ expression.
+
+ If N is positive, search forward; in this case, LIM must be greater
+ than POS.
+
+ If N is negative, search backward; LIM must be less than POS.
+
+ Return -X if there are X remaining occurrences or matches,
+ or else the position at the beginning (if N is negative) or the end
+ (if N is positive) of the Nth occurrence or match against STRING.
+
+ Use TRT and INVERSE_TRT as character translation tables. */
+
EMACS_INT
search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
ptrdiff_t lim, ptrdiff_t lim_byte, EMACS_INT n,
- int RE, Lisp_Object trt, Lisp_Object inverse_trt, bool posix)
+ bool RE, Lisp_Object trt, Lisp_Object inverse_trt, bool posix)
{
if (running_asynch_code)
save_search_regs ();
@@ -2219,7 +2222,7 @@ Search case-sensitivity is determined by the value of the variable
See also the functions `match-beginning', `match-end' and `replace-match'. */)
(Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (string, bound, noerror, count, -1, 0, 0);
+ return search_command (string, bound, noerror, count, -1, false, false);
}
DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "MSearch: ",
@@ -2244,7 +2247,7 @@ Search case-sensitivity is determined by the value of the variable
See also the functions `match-beginning', `match-end' and `replace-match'. */)
(Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (string, bound, noerror, count, 1, 0, 0);
+ return search_command (string, bound, noerror, count, 1, false, false);
}
DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4,
@@ -2260,7 +2263,7 @@ because REGEXP is still matched in the forward direction. See Info
anchor `(elisp) re-search-backward' for details. */)
(Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (regexp, bound, noerror, count, -1, 1, 0);
+ return search_command (regexp, bound, noerror, count, -1, true, false);
}
DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4,
@@ -2291,7 +2294,7 @@ See also the functions `match-beginning', `match-end', `match-string',
and `replace-match'. */)
(Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (regexp, bound, noerror, count, 1, 1, 0);
+ return search_command (regexp, bound, noerror, count, 1, true, false);
}
DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4,
@@ -2319,7 +2322,7 @@ See also the functions `match-beginning', `match-end', `match-string',
and `replace-match'. */)
(Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (regexp, bound, noerror, count, -1, 1, 1);
+ return search_command (regexp, bound, noerror, count, -1, true, true);
}
DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4,
@@ -2347,7 +2350,7 @@ See also the functions `match-beginning', `match-end', `match-string',
and `replace-match'. */)
(Lisp_Object regexp, Lisp_Object bound, Lisp_Object noerror, Lisp_Object count)
{
- return search_command (regexp, bound, noerror, count, 1, 1, 1);
+ return search_command (regexp, bound, noerror, count, 1, true, true);
}
DEFUN ("replace-match", Freplace_match, Sreplace_match, 1, 5, 0,