From a92c3d691836eb762f54aeb93cdeb3e305b06185 Mon Sep 17 00:00:00 2001 From: Spyros Roum Date: Thu, 26 Dec 2024 17:57:54 +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 8adead78a32..a9862ccf3ff 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..7ef1e5997d4 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 command using read-shell-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) + "Read command using completing-read, completing on compile-history" + (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.1" + :type '(radio (function-item compilation-prompt-read-shell-command) + (function-item compilation-prompt-read-with-history-completion) + (function :tag "Other"))) + +(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