From: Christoph Groth <christoph@grothesque.org>
To: emacs-devel@gnu.org
Subject: Proposed functionality: dired-do-execute
Date: Fri, 05 Apr 2019 14:16:30 +0200 [thread overview]
Message-ID: <87r2agsl41.fsf@neron> (raw)
[-- Attachment #1: Type: text/plain, Size: 2551 bytes --]
Hello,
Dired's 'M-x dired-do-find-regexp-and-replace' allows to edit multiple
files efficiently in some cases, but it is rather limited in what it can
do. In an effort to support more complex cases of multi-file editing, I
wrote the following command that allows executing arbitrary commands,
macros, and Lisp expressions in multiple files with little effort. Note
that the prefix argument is passed to the command to be executed in each
buffer, which allows to repeat executing a macro for each file until an
error occurs. I bind this command to 'E' in dired, and find it so
useful, that I would like to propose to include something similar in
Emacs.
If there's any interest, I could work on a proper patch. I'd grateful
for any comments or suggestions of what should be changed.
Please CC me in any replies, since I'm not subscribed to this list.
Christoph
(defun my-dired-do-execute (keys &optional arg)
"Execute a command in all marked files.
If an error occurs, execution in other files is not affected.
(Notably, this allows to run keyboard macros until there is an error.)
At the prompt, type any bound key sequence, or `\\[execute-extended-command]'
to choose a command by its name, or `\\[eval-expression]' to enter a Lisp expression.
The prefix ARG, if given, is passed on to the chosen command.
"
(interactive
(list (read-key-sequence (substitute-command-keys "Key sequence to execute, \
or \\[eval-expression], or \\[execute-extended-command]: "))
current-prefix-arg))
(when keys
(let ((cmd (if (arrayp keys) (key-binding keys) keys))
exp)
(cond ((eq cmd 'execute-extended-command)
(setq cmd (read-command "Name of command to execute: "))
(if (string-equal cmd "")
(error "No command name given")))
((eq cmd 'eval-expression)
(setq exp (read--expression "Eval in selected files: "))
(setq cmd nil))
((null cmd)
(error "Key sequence %s is not defined" (key-description keys))))
(mapc (lambda (filename)
(save-selected-window
(find-file-other-window filename)
(setq current-prefix-arg arg)
(condition-case-unless-debug err
(if cmd
(call-interactively cmd)
(message "Result in file %s:" filename)
(eval-expression exp))
(error (message "In file %s: %S" filename err)))))
(dired-get-marked-files)))))
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
reply other threads:[~2019-04-05 12:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87r2agsl41.fsf@neron \
--to=christoph@grothesque.org \
--cc=emacs-devel@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.
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).