From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Cc: "Felix E. Klee" <felix.klee@inka.de>
Subject: Re: How to rename files to numbers in Eshell?
Date: Mon, 13 Sep 2021 13:52:12 +0200 [thread overview]
Message-ID: <20210913115212.GC25353@tuxteam.de> (raw)
In-Reply-To: <YT8ZuCvvYevO37V+@protected.localdomain>
[-- Attachment #1: Type: text/plain, Size: 1312 bytes --]
On Mon, Sep 13, 2021 at 12:28:24PM +0300, Jean Louis wrote:
> Dear Felix, maybe you forgot to insert mailing list in your answer.
>
> > Jean Louis <bugs@gnu.support> writes:
> > > Is there any regular expression counter replacement so that each new
> > > replacement get a new number?
>
> > Example replacement:
>
> > \,(1+ \#)
>
> > This starts counting at 1. If you want to start at 0, then simply use:
>
> \#
>
> That is definitely interesting, please correct me, as I don't get it how to apply it, as following is not working:
>
> (replace-regexp-in-string "ABC" "\#" "ABCM ABCI ABCJ ABCY ABC8")
I think this notation is only for interactive input. Besides, the
wrapping "\,(...)" is important, meaning "interpolate this Lisp
expression's value here".
For what you have in mind you could make use of the fact that
`replace-regexp-in-string' also takes a function:
(defun make-counter (startval) ; the "classical" counter closure
(lambda (match)
(prog1
(format "%d" startval) ; we have to evaluate to a string, I think
(setq startval (1+ startval)))))
(replace-regexp-in-string "ABC" (make-counter 23) "ABCM ABCI ABCJ ABCY ABC8")
=> "23M 24I 25J 26Y 278"
(don't forget lexical binding, it won't work otherwise ;-)
Cheers
- t
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2021-09-13 11:52 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-11 13:15 How to rename files to numbers in Eshell? Felix E. Klee
2021-09-11 13:40 ` Jean Louis
2021-09-12 8:44 ` Felix E. Klee
2021-09-12 19:03 ` Jean Louis
2021-09-13 9:28 ` Jean Louis
2021-09-13 11:52 ` tomas [this message]
2021-09-14 7:42 ` Felix E. Klee
2021-09-14 9:17 ` Jean Louis
2021-09-14 9:32 ` tomas
2021-09-14 11:11 ` Felix E. Klee
2021-09-14 13:37 ` Jean Louis
2021-09-14 15:48 ` Felix E. Klee
2021-09-16 22:37 ` Michael Heerdegen
2021-09-16 22:47 ` Michael Heerdegen
2021-09-17 7:27 ` Felix E. Klee
2021-09-24 7:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-25 13:43 ` Jean Louis
2021-09-26 2:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30 6:38 ` Felix E. Klee
2021-09-30 7:37 ` Jean Louis
2021-09-30 7:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30 13:17 ` Felix E. Klee
2021-09-30 15:34 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-30 21:42 ` Jean Louis
2021-10-01 0:09 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-01 20:51 ` Jean Louis
2021-10-01 21:34 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-02 7:53 ` Lack of integration in Emacs - it was " Jean Louis
2021-10-03 8:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-03 9:27 ` Jean Louis
2021-10-04 3:29 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-04 10:15 ` Jean Louis
2021-10-04 11:22 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-22 14:46 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-22 14:27 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-16 12:15 ` Felix E. Klee
2021-09-16 15:11 ` Nick Dokos
2021-09-16 16:07 ` Felix E. Klee
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=20210913115212.GC25353@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=felix.klee@inka.de \
--cc=help-gnu-emacs@gnu.org \
/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).