branch: externals/embark commit aa9f0d7c70ae5e939667b3d896aba0259cd0b2ed Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Introduce embark--read-from-history One could argue that the remove from history commands should rather live in Consult, since they are based on completion. However it seems that these commands are only useful as minibuffer actions. If I recall correctly we came to this conclusion before when we added `embark-recentf-remove`. --- embark.el | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/embark.el b/embark.el index e80b636..e148308 100644 --- a/embark.el +++ b/embark.el @@ -3119,16 +3119,30 @@ When called with a prefix argument OTHER-WINDOW, open dired in other window." (interactive "fJump to Dired file: \nP") (dired-jump other-window file)) +(defun embark--read-from-history (prompt candidates &optional category) + "Read with completion from list of history CANDIDATES of CATEGORY. +Sorting and history are disabled. PROMPT is the prompt message." + (completing-read prompt + (lambda (string predicate action) + (if (eq action 'metadata) + `(metadata (display-sort-function . identity) + (cycle-sort-function . identity) + (category . ,category)) + (complete-with-action action candidates string predicate))) + nil t nil t)) + (defun embark-kill-ring-remove (text) "Remove TEXT from `kill-ring'." - (interactive (list (completing-read "Remove from kill-ring: " kill-ring nil t))) + (interactive (list (embark--read-from-history + "Remove from kill-ring: " kill-ring 'kill-ring))) (embark-history-remove text) (setq kill-ring (delete text kill-ring))) (defvar recentf-list) (defun embark-recentf-remove (file) "Remove FILE from the list of recent files." - (interactive (list (completing-read "Remove recent file: " recentf-list nil t))) + (interactive (list (embark--read-from-history + "Remove recent file: " recentf-list 'file))) (embark-history-remove file) (setq recentf-list (delete (expand-file-name file) recentf-list))) @@ -3137,13 +3151,11 @@ When called with a prefix argument OTHER-WINDOW, open dired in other window." Many completion UIs sort by history position. This command can be used to remove entries from the history, such that they are not sorted closer to the top." - (interactive - (list - (completing-read "Remove history item: " - (if (eq minibuffer-history-variable t) - (user-error "No minibuffer history") - (symbol-value minibuffer-history-variable)) - nil t))) + (interactive (list (embark--read-from-history + "Remove history item: " + (if (eq minibuffer-history-variable t) + (user-error "No minibuffer history") + (symbol-value minibuffer-history-variable))))) (unless (eq minibuffer-history-variable t) (set minibuffer-history-variable (delete str (symbol-value minibuffer-history-variable)))))