emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Feature Request] Add Zsh-style range and list iteration syntax to E


From: Jim Porter
Subject: Re: [Feature Request] Add Zsh-style range and list iteration syntax to Eshell
Date: Wed, 4 Dec 2024 10:44:01 -0800

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 via email to

[Prev in Thread] Current Thread [Next in Thread]