From: Stefan Kangas Date: Fri, 28 Aug 2020 17:23:01 +0000 (+0200) Subject: Add commands to run shell commands in project root X-Git-Tag: emacs-28.0.90~6340 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8d3160ec0856dba42ac39296e7191a51c1e8b7e8;p=emacs.git Add commands to run shell commands in project root * lisp/progmodes/project.el (project-async-shell-command) (project-shell-command): New commands to run 'async-shell-command' and 'shell-command' in project's root directory. (project-prefix-map): Bind commands to '!' and '&'. * doc/emacs/maintaining.texi (Project File Commands): Document the new commands. * etc/NEWS: Announce the new commands. --- diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 9f550b49874..a9b0da5aff6 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -1693,6 +1693,12 @@ Start Eshell in the current project's root directory @item C-x p c Run compilation in the current project's root directory (@code{project-compile}). +@item C-x p ! +Run shell command in the current project's root directory +(@code{project-shell-command}). +@item C-x p & +Run shell command asynchronously in the current project's root +directory (@code{project-async-shell-command}). @end table Emacs provides commands for handling project files conveniently. @@ -1770,6 +1776,14 @@ directory. @xref{Top,Eshell,Eshell, eshell, Eshell: The Emacs Shell}. The command @kbd{C-x p c} (@code{project-compile}) runs compilation (@pxref{Compilation}) in the current project's root directory. +@findex project-shell-command + The command @kbd{C-x p !} (@code{project-shell-command}) runs +@code{shell-command} in the current project's root directory. + +@findex project-async-shell-command + The command @kbd{C-x p &} (@code{project-async-shell-command}) runs +@code{async-shell-command} in the current project's root directory. + @node Project Buffer Commands @subsection Project Commands That Operate on Buffers diff --git a/etc/NEWS b/etc/NEWS index 964b626d7b8..658e2a35d76 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -778,6 +778,11 @@ directory. This command lets you "switch" to another project and run a project command chosen from a dispatch menu. ++++ +*** New commands 'project-shell-command' and 'project-async-shell-command'. +These commands run 'shell-command' and 'async-shell-command' in a +project's root directory, respectively. + +++ *** New user option 'project-list-file'. diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 8afd5ce7959..4fae3e9186c 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -581,6 +581,8 @@ DIRS must contain directory names." ;;;###autoload (defvar project-prefix-map (let ((map (make-sparse-keymap))) + (define-key map "!" 'project-shell-command) + (define-key map "&" 'project-async-shell-command) (define-key map "f" 'project-find-file) (define-key map "F" 'project-or-external-find-file) (define-key map "b" 'project-switch-to-buffer) @@ -882,6 +884,20 @@ if one already exists." (pop-to-buffer eshell-buffer) (eshell t)))) +;;;###autoload +(defun project-async-shell-command () + "Run `async-shell-command' in the current project's root directory." + (interactive) + (let ((default-directory (project-root (project-current t)))) + (call-interactively #'async-shell-command))) + +;;;###autoload +(defun project-shell-command () + "Run `shell-command' in the current project's root directory." + (interactive) + (let ((default-directory (project-root (project-current t)))) + (call-interactively #'shell-command))) + (declare-function fileloop-continue "fileloop" ()) ;;;###autoload