Skip to content

Commit

Permalink
Simplify return-actions by ensuring it's a list.
Browse files Browse the repository at this point in the history
  • Loading branch information
aadcg committed Sep 13, 2022
1 parent ff463f6 commit f512241
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 66 deletions.
12 changes: 9 additions & 3 deletions libraries/prompter/prompter-source.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,17 @@ recompute the match-data for instance.")
The predicate works the same as the `sort' predicate.")

(return-actions
'(identity)
:type list
#'identity
:type (or null
(or function function-symbol)
(cons (or function function-symbol) *))
:accessor nil
:export nil
:documentation "List of funcallables that can be run on `suggestion's of
this source. This is the low-level implementation, see the `return-actions'
function for the public interface.")
function for the public interface.
For convenience, it may be initialized with a single function, in which case it
will be automatically turned into a list.")

(update-notifier
(make-channel)
Expand Down Expand Up @@ -627,6 +631,8 @@ If you are looking for a source that just returns its plain suggestions, use `so
(calispel:? wait-channel))
(setf (selection-actions source) (uiop:ensure-list (selection-actions source)))
(setf (marks-actions source) (uiop:ensure-list (marks-actions source)))
(setf (slot-value source 'return-actions)
(uiop:ensure-list (slot-value source 'return-actions)))
source)

(export-always 'attributes-keys-non-default)
Expand Down
2 changes: 1 addition & 1 deletion source/browser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ set of useful URLs or preparing a list to send to a someone else."
:sources (make-instance 'buffer-source
:constructor (remove-if #'internal-url-p (buffer-list)
:key #'url)
:return-actions '(identity)
:return-actions #'identity
:multi-selection-p t))))
(unwind-protect
(spinneret:with-html-string
Expand Down
28 changes: 14 additions & 14 deletions source/buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ second latest buffer first."
:prompt "Delete buffer(s)"
:sources (make-instance 'buffer-source
:multi-selection-p t
:return-actions (list 'identity)))))
:return-actions #'identity))))
"Query the buffer(s) to delete.
BUFFERS should be a list of `buffer's."
Expand Down Expand Up @@ -1314,7 +1314,7 @@ URL-DESIGNATOR is then transformed by BUFFER's `buffer-load-hook'."
(history-initial-suggestions)))
(prompter:multi-selection-p t)
(prompter:filter-preprocessor nil) ; Don't remove non-exact results.
(prompter:return-actions '(buffer-load)))
(prompter:return-actions #'buffer-load))
(:export-class-name-p t)
(:metaclass user-class))

Expand Down Expand Up @@ -1470,7 +1470,7 @@ Finally, if nothing else, set the `engine' to the `default-search-engine'."))
(input->queries input
:check-dns-p t
:engine-completion-p t)))
(prompter:return-actions '(buffer-load)))
(prompter:return-actions #'buffer-load))
(:export-class-name-p t)
(:documentation "This prompter source tries to \"do the right thing\" to
generate a new URL query from user input.
Expand Down Expand Up @@ -1537,11 +1537,11 @@ any.")
(define-command set-url-new-buffer (&key (prefill-current-url-p t))
"Prompt for a URL and set it in a new focused buffer."
(let ((history (set-url-history *browser*))
(return-actions (list (lambda-command new-buffer-load (suggestion-values)
"Load URL(s) in new buffer(s)"
(mapc (lambda (suggestion) (make-buffer :url (url suggestion)))
(rest suggestion-values))
(make-buffer-focus :url (url (first suggestion-values)))))))
(return-actions (lambda-command new-buffer-load (suggestion-values)
"Load URL(s) in new buffer(s)"
(mapc (lambda (suggestion) (make-buffer :url (url suggestion)))
(rest suggestion-values))
(make-buffer-focus :url (url (first suggestion-values))))))
(pushnew-url-history history (url (current-buffer)))
(prompt
:prompt "Open URL in new buffer"
Expand All @@ -1554,12 +1554,12 @@ any.")
(define-command set-url-new-nosave-buffer (&key (prefill-current-url-p t))
"Prompt for a URL and set it in a new focused nosave buffer."
(let ((return-actions
(list (lambda-command new-nosave-buffer-load (suggestion-values)
"Load URL(s) in new nosave buffer(s)"
(mapc (lambda (suggestion) (make-nosave-buffer :url (url suggestion)))
(rest suggestion-values))
(make-buffer-focus :url (url (first suggestion-values))
:nosave-buffer-p t)))))
(lambda-command new-nosave-buffer-load (suggestion-values)
"Load URL(s) in new nosave buffer(s)"
(mapc (lambda (suggestion) (make-nosave-buffer :url (url suggestion)))
(rest suggestion-values))
(make-buffer-focus :url (url (first suggestion-values))
:nosave-buffer-p t))))
(prompt
:prompt "Open URL in new nosave buffer"
:input (if prefill-current-url-p
Expand Down
23 changes: 10 additions & 13 deletions source/command-commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,18 @@ together with the arglists and documentations of the functions typed in."
:prompt "Execute command"
:sources (list (make-instance
'command-source
:return-actions
(list (lambda-command run-command* (commands)
"Run the chosen command."
(let ((command (first commands)))
(setf (last-access command) (local-time:now))
(run-async command)))))
:return-actions (lambda-command run-command* (commands)
"Run the chosen command."
(let ((command (first commands)))
(setf (last-access command) (local-time:now))
(run-async command))))
(make-instance
'extended-command-source
:return-actions
(list
(lambda-command evaluate-lisp-expression* (exprs)
"Evaluate the inputted Lisp expression."
(run-thread "evaluator"
(let ((*interactive-p* t))
(echo "~s" (eval (first exprs)))))))))
:return-actions (lambda-command evaluate-lisp-expression* (exprs)
"Evaluate the inputted Lisp expression."
(run-thread "evaluator"
(let ((*interactive-p* t))
(echo "~s" (eval (first exprs))))))))
:hide-suggestion-count-p t)))

(defun parse-function-lambda-list-types (fn)
Expand Down
27 changes: 16 additions & 11 deletions source/describe.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,37 @@ for matches."
(sources
(list (make-instance
'variable-source
:return-actions (list (lambda-command describe-variable* (variables)
(describe-variable :variable (first variables))))
:return-actions (lambda-command describe-variable* (variables)
"Inspect variable."
(describe-variable :variable (first variables)))
:filter-preprocessor preprocessor
:universal universal)
(make-instance
'function-source
:return-actions (list (lambda-command describe-function* (functions)
(describe-function :fn (first functions))))
:return-actions (lambda-command describe-function* (functions)
"Inspect function."
(describe-function :fn (first functions)))
:filter-preprocessor preprocessor
:universal universal)
(make-instance
'command-source
:return-actions (list (lambda-command describe-command* (commands)
(describe-command :command (name (first commands)))))
:return-actions (lambda-command describe-command* (commands)
"Inspect command."
(describe-command :command (name (first commands))))
:filter-preprocessor preprocessor)
(make-instance
'class-source
:return-actions (list (lambda-command describe-class* (classes)
(describe-class :class (first classes))))
:return-actions (lambda-command describe-class* (classes)
"Inspect class."
(describe-class :class (first classes)))
:filter-preprocessor preprocessor
:universal universal)
(make-instance
'slot-source
:return-actions (list (lambda-command describe-slot** (slots)
(describe-slot :class (class-sym (first slots))
:name (name (first slots)))))
:return-actions (lambda-command describe-slot* (slots)
"Inspect slot."
(describe-slot :class (class-sym (first slots))
:name (name (first slots))))
:filter-preprocessor preprocessor
:universal universal))))
(let ((suggestion+action-pairs
Expand Down
4 changes: 2 additions & 2 deletions source/lisp-system.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
(define-class quicklisp-source (prompter:source)
((prompter:name "Quicklisp systems")
(prompter:constructor (mapcar #'ql-dist:short-description (ql:system-list)))
(prompter:return-actions (list (lambda-command quickload* (systems)
(ql:quickload (first systems)))))))
(prompter:return-actions (lambda-command quickload* (systems)
(ql:quickload (first systems))))))

(define-command load-system ()
"Load a system from Quicklisp."
Expand Down
6 changes: 3 additions & 3 deletions source/mode/autofill.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ it will be in conflict with common-lisp:fill."))
(define-class autofill-source (prompter:source)
((prompter:name "Autofills")
(prompter:constructor (autofills (find-submode 'autofill-mode)))
(prompter:return-actions
(list (lambda-command autofill* (autofills)
(ffi-buffer-paste (current-buffer) (funcall (first autofills)))))))
(prompter:return-actions (lambda-command autofill* (autofills)
(ffi-buffer-paste (current-buffer)
(funcall (first autofills))))))
(:export-class-name-p t)
(:metaclass user-class))

Expand Down
2 changes: 1 addition & 1 deletion source/mode/bookmark.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ In particular, we ignore the protocol (e.g. HTTP or HTTPS does not matter)."
:prompt "Bookmark URL from buffer(s)"
:sources (make-instance 'buffer-source
:multi-selection-p t
:return-actions (list (lambda-mapped-command bookmark-current-url)))))
:return-actions (lambda-mapped-command bookmark-current-url))))

(define-command bookmark-url
(&key (url (ignore-errors (quri:uri (prompt1
Expand Down
12 changes: 5 additions & 7 deletions source/mode/document.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ It does not assume being online."))
(prompter:constructor
(lambda (source)
(containers:container->list (ring source))))
(prompter:return-actions
(list (lambda-command paste* (ring-items)
(ffi-buffer-paste (current-buffer) (first ring-items))))))
(prompter:return-actions (lambda-command paste* (ring-items)
(ffi-buffer-paste (current-buffer) (first ring-items)))))
(:export-class-name-p t)
(:metaclass user-class))

Expand Down Expand Up @@ -726,10 +725,9 @@ of buffers."
'frame-source
:buffer buffer
:multi-selection-p t
:return-actions (list (lambda-command open-new-buffers (urls)
(mapcar (lambda (i)
(make-buffer :url (quri:uri i)))
urls))))
:return-actions (lambda-command open-new-buffers (urls)
(mapcar (lambda (i) (make-buffer :url (quri:uri i)))
urls)))
:after-destructor (lambda () (with-current-buffer buffer
(frame-element-clear)))))

Expand Down
2 changes: 1 addition & 1 deletion source/mode/editor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contains an `nyxt/editor-mode:editor-mode' instance (or a subclass thereof)."))
:sources
(list (make-instance 'nyxt/file-manager-mode:file-source
:name "Existing file"
:return-actions '(identity))
:return-actions #'identity)
(make-instance 'prompter:raw-source
:name "Create new file"))))))

Expand Down
2 changes: 1 addition & 1 deletion source/mode/no-procrastinate.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ page(s) in the active buffer."
:prompt "Avoid procrastination on HOSTS from buffer(s)"
:sources (make-instance 'buffer-source
:multi-selection-p t
:return-actions (list (lambda-mapped-command no-procrastinate-current-host)))))
:return-actions (lambda-mapped-command no-procrastinate-current-host))))



Expand Down
2 changes: 1 addition & 1 deletion source/mode/prompt-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ If N is negative, go to next pages instead."
((prompter:name "List of prompter attributes")
(prompter:multi-selection-p t)
(prompter:suggestion-maker 'make-attribute-suggestion)
(prompter:return-actions '(return-marks-only))))
(prompter:return-actions #'return-marks-only)))

(defun return-marks-only (suggestion-values)
"Return marked suggestions only.
Expand Down
6 changes: 3 additions & 3 deletions source/mode/record-input-field.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ See also `set-input-data-from-saved-domain'."
:return-actions return-actions)))

(define-command set-input-data-from-saved-domain
(&key (return-actions (list (lambda-command buffer-load* (suggestion-values)
"Load selected input-entry in current buffer's input fields."
(ps-write-input-data (input-data (first suggestion-values)))))))
(&key (return-actions (lambda-command buffer-load* (suggestion-values)
"Load selected input-entry in current buffer's input fields."
(ps-write-input-data (input-data (first suggestion-values))))))
"Set the input data from a list of saved data filtered by current domain into
the current buffer.
Expand Down
8 changes: 4 additions & 4 deletions source/mode/search-buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ Example:
:sources (make-instance 'search-buffer-source
:case-sensitive-p case-sensitive-p
:return-actions
(list (lambda (search-match)
(unless (keep-search-hints-p (current-buffer))
(remove-search-hints))
search-match)))))
(lambda (search-match)
(unless (keep-search-hints-p (current-buffer))
(remove-search-hints))
search-match))))

(define-command search-buffers (&key case-sensitive-p)
"Search multiple buffers."
Expand Down
2 changes: 1 addition & 1 deletion source/window.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ not try to quit the browser."
((prompter:name "Windows")
(prompter:multi-selection-p t)
(prompter:constructor (window-list))
(prompter:return-actions (list (lambda-mapped-command window-delete)))))
(prompter:return-actions (lambda-mapped-command window-delete))))

(defmethod prompter:object-attributes ((window window) (source window-source))
(declare (ignore source))
Expand Down

0 comments on commit f512241

Please sign in to comment.