unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [Feature Request] Add Zsh-style range and list iteration syntax to Eshell
@ 2024-12-04 17:15 the_wurfkreuz via Emacs development discussions.
  2024-12-04 18:44 ` Jim Porter
  0 siblings, 1 reply; 2+ messages in thread
From: the_wurfkreuz via Emacs development discussions. @ 2024-12-04 17:15 UTC (permalink / raw)
  To: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 312 bytes --]

Zsh has an ability to quickly iterate over ranges and lists like this:

touch file{1,3}
creates: file1, file3

touch file{1..3}

creates: file1, file2, file3

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)
}

[-- Attachment #2: Type: text/html, Size: 639 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Feature Request] Add Zsh-style range and list iteration syntax to Eshell
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Porter @ 2024-12-04 18:44 UTC (permalink / raw)
  To: the_wurfkreuz, emacs-devel@gnu.org

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) }



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-04 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this public inbox

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

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).