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.
This commit is contained in:
Stefan Kangas 2020-08-28 19:23:01 +02:00
parent d2412492ca
commit 8d3160ec08
3 changed files with 35 additions and 0 deletions

View file

@ -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

View file

@ -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'.

View file

@ -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