From 7e140c1ab5bfc7440753ab3aff2c3ce7eb38414e Mon Sep 17 00:00:00 2001 From: Spyros Roum Date: Wed, 25 Dec 2024 17:32:31 +0200 Subject: [PATCH] Add option for making compilation-read-command use completing-read * etc/NEWS: Add to NEWS * lisp/progmodes/compile.el (compilation-read-command): Call function based on `compilation-read-command-function`. (compilation-prompt-read-shell-command): The existing functionality from compilation-read-command extracted to a function. (compilation-prompt-read-with-history-completion): A function that uses completing-read to read the command. (compilation-read-command-function): The new option that controlls which function is used. --- etc/NEWS | 8 ++++++++ lisp/progmodes/compile.el | 28 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index ca107bb4938..cfb137c2399 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -147,6 +147,14 @@ will still be on that candidate after "*Completions*" is updated with a new list of completions. The candidate is automatically deselected when the "*Completions*" buffer is hidden. +--- +*** New user option 'compilation-read-command-function'. +This option controls what function is used to read user input for +'compilation-read-command'. +It defaults to 'compilation-prompt-read-shell-command', which preserves +existing behavior. When set to 'compilation-prompt-read-with-history-completion', +'completing-read' is used allowing autocomplete based on past runs of 'compile'. + ** Windows +++ diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 6784a12fd63..d01e8c69017 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1797,12 +1797,38 @@ compilation-mode-font-lock-keywords '((compilation--ensure-parse)) compilation-mode-font-lock-keywords)) -(defun compilation-read-command (command) +(defun compilation-prompt-read-shell-command (command) (read-shell-command "Compile command: " command (if (equal (car compile-history) command) '(compile-history . 1) 'compile-history))) +(defun compilation-prompt-read-with-history-completion (command) + (completing-read "Compile command: " compile-history + nil nil command + (if (equal (car compile-history) command) + '(compile-history . 1) + 'compile-history))) + +(defcustom compilation-read-command-function + #'compilation-prompt-read-shell-command + "`compilation-read-command' uses this function to get user's input. +Defaults to `compilation-prompt-read-shell-command', +but 'compilation-prompt-read-with-history-completion' can be used instead for +a completing version based on past runs." + :version "31.0" + :type 'function + :options + (list + #'compilation-prompt-read-shell-command + #'compilation-prompt-read-with-history-completion)) + +(defun compilation-read-command (command) + "Prompt user for command to run. +`compilation-read-command-function' controls the way input is read +from the minibuffer." + (funcall compilation-read-command-function command)) + ;;;###autoload (defun compile (command &optional comint) -- 2.47.1