From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: How to automatically escape regex characters for regex search? Date: Mon, 7 Nov 2022 08:58:09 +0300 Message-ID: References: <5699a03ca2b14915459c0912ac389ad9.support1@rcdrun.com> <874jvc6kwz.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38659"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02) Cc: Yuri Khan , Help GNU Emacs To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 07 06:59:05 2022 Return-path: Envelope-to: geh-help-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 1orvA1-0009tc-Dd for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 07 Nov 2022 06:59:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orv9Z-0004do-Lv; Mon, 07 Nov 2022 00:58:37 -0500 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 1orv9X-0004dN-Pm for help-gnu-emacs@gnu.org; Mon, 07 Nov 2022 00:58:35 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orv9V-0001WC-VB for help-gnu-emacs@gnu.org; Mon, 07 Nov 2022 00:58:35 -0500 Original-Received: from localhost ([::ffff:154.231.99.6]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000081FF8.0000000063689E86.00004257; Sun, 06 Nov 2022 22:58:29 -0700 Mail-Followup-To: Marcin Borkowski , Yuri Khan , Help GNU Emacs Content-Disposition: inline In-Reply-To: <874jvc6kwz.fsf@mbork.pl> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:140754 Archived-At: * Marcin Borkowski [2022-11-06 20:42]: > > On 2022-11-06, at 10:17, Yuri Khan wrote: > > > On Sun, 6 Nov 2022 at 16:13, Jean Louis wrote: > > > >> Is there any Emacs function to automatically escape regex characters > >> for regex searches? > > > > regexp-quote? > > While this is not what OP asked for, `regexp-opt' is also worth knowing > about. That one is even better as I have to check for multiple strings, thanks. (regexp-opt '("- [ ]" "- [x]")) ⇒ "\\(?:- \\[\\(?:[ x]]\\)\\)" I have made functions to universally check the item in or out, similarly to Org mode. Org mode has nice C-c C-c to mark the list item done. But what about adoc-mode for Asciidoc? (when (fboundp 'adoc-mode-map) (keymap-set adoc-mode-map "C-c C-c" 'rcd-adoc-check)) (defun rcd-adoc-check () "Toggle DONE and TODO states in `adoc-mode-map' from `[ ]' to `[x]'." (interactive) (let ((rcd-check-in "- [ ]") (rcd-check-out "- [x]")) (rcd-check rcd-check-in rcd-check-out))) If line is empty like this one... - [ ] If line is empty like this one... by pressing C-c C-c it gets its "- [ ]" at front of the list. - [x] And by pressing again C-c C-c on the line, the item get "DONE". (defun rcd-check (&optional check-in check-out) "Replace matches of CHECK-IN with CHECK-OUT in a line. It is useful to toggle [ ] to [✔]" (interactive) (let* ((start (line-beginning-position)) (end (line-end-position)) (line (buffer-substring start end)) (check-in (or check-in "❰    ❱")) (check-out (or check-out "❰DONE❱"))) (rcd-check-start check-in check-out) (save-excursion (cond ((string-match (regexp-quote check-in) line) (replace-regexp (regexp-quote check-in) check-out nil start end)) ((string-match (regexp-quote check-out) line) (replace-regexp (regexp-quote check-out) check-in nil start end)))))) (defun rcd-check-start (&optional check-in check-out) "Insert variable `check-in' at the beginning of line." (interactive) (let* ((start (line-beginning-position)) (end (line-end-position)) (line (buffer-substring start end)) (check-in (or check-in "❰    ❱")) (check-out (or check-out "❰DONE❱"))) (when (not (string-match (regexp-opt (list check-in check-out)) line)) (save-excursion (goto-char start) (insert check-in " ")) (when (= start end) (goto-char (line-end-position)))))) And I personally like ❰    ❱ and ❰DONE❱ which I use in any mode. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/