all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: the_wurfkreuz <the_wurfkreuz@proton.me>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: [Feature Request] Add Zsh-style range and list iteration syntax to Eshell
Date: Wed, 4 Dec 2024 10:44:01 -0800	[thread overview]
Message-ID: <2b5fa0f5-cc07-7a09-a66f-e478f8898e33@gmail.com> (raw)
In-Reply-To: <YMYRCbhe-joscqI5Yi7KwU6OmubPgGCXuBoLzoGpSf10hen72BVWaVRNEHvzGFAoIS01-v9jE4bmop1oj_5DYA6deogK0vzCpq7USSEMnWM=@proton.me>

On 12/4/2024 9:15 AM, the_wurfkreuz via Emacs development discussions. 
wrote:
> Zsh has an ability to quickly iterate over ranges and lists like this:
> 
> touch file{1,3}
> 
> creates: file1, file3

Thanks for the suggestion. However, I'd prefer not to add even more 
meanings for punctuation to Eshell; it's pretty complicated as it is, 
since it tries to combine both shell-like syntax with Lisp-like syntax. 
(I've been maintaining Eshell for the last couple years and still 
haven't fixed all the corner cases in the existing syntax.)

In this case though, I think you could make a helper function that gets 
you a fair amount of the way there:

   (defun eshell/expand (fmt list)
     (mapcar (lambda (i) (format fmt i)) list))

Then in Eshell:

   touch $@{expand file%s `(1 3)}

It's a bit more typing than Zsh, but less than writing a for loop.

You could also write an external Eshell module that parses syntax like 
this. em-pred.el could probably serve as some inspiration, as well as 
some examples of how it's tricky to get this right (for example, 
em-pred.el only supports predicates at the *end* of a word).

You might also be able to add a custom argument modifier that works 
somewhat like "expand" above. See 'eshell-modifier-alist'.

> It would be handy to have something similar in eshell instead of 
> explicitly writing a loop:
> 
> for i in (number-sequence 1 5) {
>      touch (format "file%d" i)
> }

As of Emacs 31, you could shorten this to:

   for i in 1..5 { touch (format "file%d" i) }



      reply	other threads:[~2024-12-04 18:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 17:15 [Feature Request] Add Zsh-style range and list iteration syntax to Eshell the_wurfkreuz via Emacs development discussions.
2024-12-04 18:44 ` Jim Porter [this message]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b5fa0f5-cc07-7a09-a66f-e478f8898e33@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=the_wurfkreuz@proton.me \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.