From f2145d9acf36d3c8ab0c38b8fa8eeb72c1806f85 Mon Sep 17 00:00:00 2001 From: Spyros Roum Date: Thu, 26 Dec 2024 16:42:56 +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 | 31 ++++++++++++++++++++++++++++++- 2 files changed, 38 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..7638e5b4df1 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1797,12 +1797,41 @@ 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.1" + :type + '(choice + (function :tag + "Read command using read-shell-command" + compilation-prompt-read-shell-command) + (function :tag + "Read command using completing-read, completing on compile-history" + 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