Skip to content

Commit

Permalink
mode/prompt-buffer: Review handling of selection-actions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aadcg committed Nov 7, 2022
1 parent c211aa6 commit 88594d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
35 changes: 25 additions & 10 deletions source/mode/prompt-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions source/tutorial.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88594d1

Please sign in to comment.