From: Jean Louis <bugs@gnu.support>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Yuri Khan <yuri.v.khan@gmail.com>,
Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: How to automatically escape regex characters for regex search?
Date: Mon, 7 Nov 2022 08:58:09 +0300 [thread overview]
Message-ID: <Y2iecaXR5o7pUXOU@protected.localdomain> (raw)
In-Reply-To: <874jvc6kwz.fsf@mbork.pl>
* Marcin Borkowski <mbork@mbork.pl> [2022-11-06 20:42]:
>
> On 2022-11-06, at 10:17, Yuri Khan <yuri.v.khan@gmail.com> wrote:
>
> > On Sun, 6 Nov 2022 at 16:13, Jean Louis <bugs@gnu.support> 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/
next prev parent reply other threads:[~2022-11-07 5:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-06 9:10 How to automatically escape regex characters for regex search? Jean Louis
2022-11-06 9:17 ` Yuri Khan
2022-11-06 17:40 ` Marcin Borkowski
2022-11-07 5:58 ` Jean Louis [this message]
2022-11-06 9:19 ` tomas
2022-11-06 9:24 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2iecaXR5o7pUXOU@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=mbork@mbork.pl \
--cc=yuri.v.khan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).