From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Christoph Groth Newsgroups: gmane.emacs.devel Subject: Proposed functionality: dired-do-execute Date: Fri, 05 Apr 2019 14:16:30 +0200 Message-ID: <87r2agsl41.fsf@neron> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="95176"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 05 14:38:05 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCO6e-000Oak-R4 for ged-emacs-devel@m.gmane.org; Fri, 05 Apr 2019 14:38:04 +0200 Original-Received: from localhost ([127.0.0.1]:41463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hCO6d-0006VS-OV for ged-emacs-devel@m.gmane.org; Fri, 05 Apr 2019 08:38:03 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hCNm8-00020c-Dy for emacs-devel@gnu.org; Fri, 05 Apr 2019 08:16:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hCNm6-0002vu-IV for emacs-devel@gnu.org; Fri, 05 Apr 2019 08:16:52 -0400 Original-Received: from mail6.webfaction.com ([31.170.123.134]:59762 helo=smtp.webfaction.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hCNm2-0002iM-LN for emacs-devel@gnu.org; Fri, 05 Apr 2019 08:16:49 -0400 Original-Received: from localhost (s8s38-1-88-180-226-12.fbx.proxad.net [88.180.226.12]) by smtp.webfaction.com (Postfix) with ESMTPSA id 26EA5600FFE49 for ; Fri, 5 Apr 2019 12:16:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 31.170.123.134 X-Mailman-Approved-At: Fri, 05 Apr 2019 08:37:30 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:234976 Archived-At: --=-=-= Content-Type: text/plain 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))))) --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEUimQV/rXmWU8TwiKw/FH9ZgPNTUFAlynRx4ACgkQw/FH9ZgP NTWOHw/5AWg8xEkqN/C+VxzdTN0e5am9BIeE8E0FybB5nmvjM1nLAAO/APRxSgFd 5vdixEFMFzFwOv6GPGdFOZeFQZ8RMLYWdVgIqQt2ZD+e6XMquaKM1H0PsClxBbEW T7LID8gl9LUZZKPX2SDaq5MrvG0kQE8Dz77o4gqxdE/Ai4Bn2U+xR1xwJIXhjNle puc42DTqB0qLjhdLO34zBQ0ggvaI5SNZK+qQ+b9xTWpcCn6Ic0Seo+fNsaY4pXJp hCileTAE2cUrhGK2ZADZz1/dl8r+otyT+oJE2CVco2s+LbbVsqGBO+jj1xvuuGhL JIOIMkFzW2WDunqbYHnUGlzG75QrfVbeAYvXxmNeEvEnqV4ClF+L0QMlf48JalAj Bp7H5yR9W7OGkEO0suyuYNfMFENcNu+J7L3VMq3+ZbaPA2YkUCgGcSZS/qnKpqk4 iRAo3xQE+ydWG/0RIrmsXZeSMxuTTxTEHIcREpgi8CL59SoMFsfHqpkRPIrmdRO5 DYpeCIUVN1tAZbDCC4qMGbb4QIQY5BXIQxNAmwn3qXGCbXsL0MVG0A0dffiD4uGR dsZ74Zry8pIFbZeExLz/0/C2vmCrFXD55hLtrqIfnyZrHRZwPEI3rnJc79ogoj6J Hy/fZJlzh9uB53inUNEs6AaNoFkOaPcBLZcwGB7+rpsV4hhJFAg= =DFi/ -----END PGP SIGNATURE----- --=-=-=--