From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Basil Contovounesios via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#64049: 30.0.50; Minor search_buffer cleanup Date: Wed, 14 Jun 2023 14:26:22 +0100 Message-ID: <87a5x29nup.fsf@epfl.ch> References: <87wn07clrw.fsf@epfl.ch> <87cz1yhov5.fsf@yahoo.com> Reply-To: Basil Contovounesios Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14932"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 64049@debbugs.gnu.org To: Po Lu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 14 15:27:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q9QWt-0003g3-UL for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 14 Jun 2023 15:27:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q9QWe-0003c5-I5; Wed, 14 Jun 2023 09:27:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q9QWd-0003bw-0P for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2023 09:27:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q9QWc-0004t4-NB for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2023 09:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q9QWc-00045J-18 for bug-gnu-emacs@gnu.org; Wed, 14 Jun 2023 09:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Basil Contovounesios Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Jun 2023 13:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64049 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64049-submit@debbugs.gnu.org id=B64049.168674919615669 (code B ref 64049); Wed, 14 Jun 2023 13:27:01 +0000 Original-Received: (at 64049) by debbugs.gnu.org; 14 Jun 2023 13:26:36 +0000 Original-Received: from localhost ([127.0.0.1]:44112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9QWB-00044f-Uf for submit@debbugs.gnu.org; Wed, 14 Jun 2023 09:26:36 -0400 Original-Received: from mail-pf1-f176.google.com ([209.85.210.176]:46105) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9QW7-00044P-VH for 64049@debbugs.gnu.org; Wed, 14 Jun 2023 09:26:34 -0400 Original-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-666683eb028so317699b3a.0 for <64049@debbugs.gnu.org>; Wed, 14 Jun 2023 06:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd.ie; s=google21; t=1686749186; x=1689341186; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=EU9C96NHFGqsbwjlocIlm3+UxrOOrkn+IMNja3fLb4U=; b=DPf99ve8GA+KMnq2+++/FpFN8weUSKler+Oc5XVdcFDDefyok8QkVtZ1DoCTtJsmsl ufLBoGkGnR7iH1dT9NKlZvxCVSPkP4p+36BG8HKe06nlAjXkU7vATL5QWOT49hhGa05Z uK25wyYK5rLlFLp+cOgKRYcP6pr/SDMoM2pJmj/VxEUNqdzhIM56R3izRNyeZx7NDFwT l2IPF/1FQr6nOBj+886VlRbTa13jNhn18adpTY+h5meOgIXym2DJ6KiMFejnVgPrEzp/ wKvmDv6Slb+ufHMfAkzpHKz9SQG9g6IIG2I8NsuZb8haF3XoLqWyJjpAnIKZmrah8V/g RYQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686749186; x=1689341186; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EU9C96NHFGqsbwjlocIlm3+UxrOOrkn+IMNja3fLb4U=; b=kOA37PALEIYB4QaGjXX3MYjw/7UYV76xZPG67nANekYGGISCDPm332ANG54Aou/3eh 2hKB0b3YcxwYqA0pxUZ2b2HTu+S8LG11/UST/LYwYBLOnFB2laFV8qTLrEYj5p6x6zNX 1oDLQBCJK+l+6PjbWB8NZyecYxsr8M5oM0t+3WTL5ZrfhoRn/4d/tvoYLfglX8BTf+wB lMAdXIBUfof5VGwRI2AaCXWJJXyBR0D0YTHFiVFApcc/PAxLktQ2yyKMLVXcMtmHzszE cwndJ+boGHYuDWikW9qRBEhCy/NlOHC7u6vVbWihpjp+2OC5OkiWgw04KEWTXPFdYW5m 8cjw== X-Gm-Message-State: AC+VfDyh/zRlZiosVc0l7MYYUARQFBZ5/aSRIZqDpvFEcTHyn0z7Ckqa a81ggt8wR/mxoNsIARWco8TLvg== X-Google-Smtp-Source: ACHHUZ4RzshElp5BpsHfBPD8d3APTm5p0JDS+b5FejfyeRK5OfMwvFYHj9mVHpxFcn+v7vK8/mXFXA== X-Received: by 2002:a05:6a00:10d2:b0:643:96e:666b with SMTP id d18-20020a056a0010d200b00643096e666bmr1460290pfu.34.1686749185873; Wed, 14 Jun 2023 06:26:25 -0700 (PDT) Original-Received: from localhost ([64.43.152.143]) by smtp.gmail.com with ESMTPSA id n2-20020a62e502000000b006634d0fe2c6sm10333595pff.203.2023.06.14.06.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 06:26:25 -0700 (PDT) In-Reply-To: <87cz1yhov5.fsf@yahoo.com> (Po Lu's message of "Wed, 14 Jun 2023 08:25:02 +0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263372 Archived-At: --=-=-= Content-Type: text/plain Po Lu [2023-06-14 08:25 +0800] wrote: > We typically write ``All callers changed'' in ChangeLog, I think. [...] > How about: Thanks, done: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Minor-search_buffer-cleanup.patch >From 2cf5bbafef58aa7d8c5ea6d1b43a349d9dabe273 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 3 Jun 2023 14:46:19 +0100 Subject: [PATCH] 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). --- src/lisp.h | 2 +- src/search.c | 51 +++++++++++++++++++++++++++------------------------ src/treesit.c | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/lisp.h b/src/lisp.h index 2978de962d9..44af2ef8a2a 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4809,7 +4809,7 @@ fast_c_string_match_ignore_case (Lisp_Object regexp, ptrdiff_t, ptrdiff_t *); extern EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, - int, Lisp_Object, Lisp_Object, bool); + bool, Lisp_Object, Lisp_Object, bool); extern void syms_of_search (void); extern void clear_regexp_cache (void); 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 @@ DEFUN ("search-backward", Fsearch_backward, Ssearch_backward, 1, 4, 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 @@ DEFUN ("search-forward", Fsearch_forward, Ssearch_forward, 1, 4, "MSearch: ", 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 @@ DEFUN ("re-search-backward", Fre_search_backward, Sre_search_backward, 1, 4, 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 @@ DEFUN ("re-search-forward", Fre_search_forward, Sre_search_forward, 1, 4, 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 @@ DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 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 @@ DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 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, diff --git a/src/treesit.c b/src/treesit.c index 0af0e347694..e69cb872a9a 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2582,7 +2582,7 @@ treesit_predicate_match (Lisp_Object args, struct capture_range captures, ZV_BYTE = end_byte; ptrdiff_t val = search_buffer (regexp, start_pos, start_byte, - end_pos, end_byte, 1, 1, Qnil, Qnil, false); + end_pos, end_byte, 1, true, Qnil, Qnil, false); BEGV = old_begv; BEGV_BYTE = old_begv_byte; -- 2.34.1 --=-=-= Content-Type: text/plain -- Basil --=-=-=--