From 88594d143a7f24bc31ae9c7c00e3ded2c2f64881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20A=2E=20Gomes?= Date: Thu, 8 Sep 2022 18:09:46 +0300 Subject: [PATCH] mode/prompt-buffer: Review handling of selection-actions. Add set-selection-action. Keybindings review. Rename return-selection-over-action to return-marks-action. According to the terminology of the prompter library, return-actions run over marks, not over the selection. Rename action-source to return-action-source to distinguish it from selection-action-source. --- source/mode/prompt-buffer.lisp | 35 ++++++++++++++++++++++++---------- source/tutorial.lisp | 4 ++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/source/mode/prompt-buffer.lisp b/source/mode/prompt-buffer.lisp index 6634a0ed954a..3951ff36ef70 100644 --- a/source/mode/prompt-buffer.lisp +++ b/source/mode/prompt-buffer.lisp @@ -44,8 +44,9 @@ default)." "f1 b" 'run-prompt-buffer-command "f1 m" 'describe-prompt-buffer "return" 'return-selection - "M-return" 'return-selection-over-action + "M-return" 'return-marks-action "C-return" 'run-selection-action + "C-c C-j" 'set-selection-action "tab" 'insert-selection ; TODO: This is the Emacs Helm binding. Better? "C-c C-f" 'toggle-selection-actions-enabled @@ -305,6 +306,10 @@ current unmarked selection." (sera:and-let* ((first-prompt-buffer (first (nyxt::active-prompt-buffers window)))) (prompter:return-actions first-prompt-buffer))) +(defun prompt-buffer-selection-actions (&optional (window (current-window))) + (sera:and-let* ((first-prompt-buffer (first (nyxt::active-prompt-buffers window)))) + (prompter:selection-actions (prompter:selected-source first-prompt-buffer)))) + ;; TODO: Should return-actions be commands? For now, they can be either ;; commands or symbols. (defun make-action-suggestion (action &optional source input) @@ -323,25 +328,35 @@ current unmarked selection." (t (documentation action 'function))))) ""))))) -(define-class action-source (prompter:source) +(define-class return-action-source (prompter:source) ((prompter:name "List of return-actions") (prompter:constructor (prompt-buffer-return-actions)) (prompter:suggestion-maker 'make-action-suggestion))) -(define-command-prompt return-selection-over-action (prompt-buffer) - "Prompt for an action to run over PROMPT-BUFFER selection." +(define-class selection-action-source (prompter:source) + ((prompter:name "List of selection-actions") + (prompter:constructor (prompt-buffer-selection-actions)) + (prompter:suggestion-maker 'make-action-suggestion))) + +(define-command-prompt return-marks-action (prompt-buffer) + "Prompt for an action to run over PROMPT-BUFFER `prompter:marks'." (if (equal (mapcar #'type-of (prompter:sources (current-prompt-buffer))) - '(action-source)) + '(return-action-source)) (echo "Already displaying return-actions of previous prompt buffer.") - (let ((action (prompt1 :prompt "Action to run on selection" - :sources 'action-source))) - (when action - (prompter:return-selection prompt-buffer action))))) + (alex:when-let ((action (prompt1 :prompt "Action to run on selection" + :sources 'return-action-source))) + (prompter:return-selection prompt-buffer action)))) (define-command-prompt run-selection-action (prompt-buffer) - "Run one of `prompter:selection-actions' without closing PROMPT-BUFFER." + "Run `prompter::default-selection-action' without closing PROMPT-BUFFER." (prompter:call-selection-action prompt-buffer)) +(define-command-prompt set-selection-action (prompt-buffer) + "Set `prompter:selection-actions' without closing PROMPT-BUFFER." + (alex:when-let ((action (prompt1 :prompt "Set selection action" + :sources 'selection-action-source))) + (prompter:set-selection-action action prompt-buffer))) + (define-command-prompt cancel-input (prompt-buffer) ; TODO: Rename. "Close the PROMPT-BUFFER without further action." (prompter:destroy prompt-buffer)) diff --git a/source/tutorial.lisp b/source/tutorial.lisp index 35ad1889dd80..0678deb66d1b 100644 --- a/source/tutorial.lisp +++ b/source/tutorial.lisp @@ -63,9 +63,9 @@ matching your input as you type.") :modes (list (make-instance 'nyxt/prompt-buffer-mode:prompt-buffer-mode))) ": Validate the selected suggestion(s) or the current input if there is no suggestion.") - (:li (command-markup 'nyxt/prompt-buffer-mode:return-selection-over-action + (:li (command-markup 'nyxt/prompt-buffer-mode:return-marks-action :modes (list (make-instance 'nyxt/prompt-buffer-mode:prompt-buffer-mode))) - ": Query the user for an action to run over the selected suggestion(s).")) + ": Query the user for an action to run over the marked suggestion(s).")) (:p " Some commands support multiple selections, for instance " (:code "delete-buffer") " can delete all selected buffers at once. When the input is changed and the suggestions are re-filtered, the selection is