Skip to content

Commit

Permalink
spinneret-tags: Refactor nselect.
Browse files Browse the repository at this point in the history
A partial refactor of commit 5d18d0a that
introduced a bug (see issue below).

The copy-p keyword argument is recovered since it adds flexibility without extra
complexity costs.

Closes #3376.
  • Loading branch information
aadcg committed Apr 4, 2024
1 parent bb19c9e commit 2814013
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions source/spinneret-tags.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,16 @@ forms in BUFFER."
(deftag :nselect (body attrs &rest keys &key default (id (alexandria:required-argument 'id)) buffer &allow-other-keys)
"Generate <select> tag from the BODY resembling cond clauses.
BODY can be:
- Multiple forms, each following/producing one of the formats:
- (VALUE . FORMS) -- creates <option value=\"value\">value</option> and runs
FORMS when it's selected.
- ((VALUE DISPLAY TITLE) . FORMS) -- creates an <option value=\"value\"
title=\"title\">display</option> and runs FORMS when it's selected. DISPLAY
and TITLE are optional literal strings.
- A single form, expected to produce a list of forms like above.
BODY is a list of forms, each given by ((VALUE DISPLAY TITLE) . FORMS).
It expands to <option value=\"value\" title=\"title\">display</option> and runs
FORMS when selected. DISPLAY and TITLE are optional literal strings.
In both cases, VALUEs should be literal (and printable) atoms. For instance,
symbol, number, string, or keyword.
BUFFER is a buffer to bind the actions of this tag to.
DEFAULT is a string or a string-producing form that is used as the default
option.
DEFAULT is a form evaluating to a string that is used as the default option.
In case some variable from the outer scope should be captured, injecting a
closure into the clause would work best.
Expand All @@ -105,7 +99,7 @@ Example:
(with-gensyms (body-var)
(let ((keys keys))
(declare (ignorable keys))
`(let ((,body-var ,`(list ,@body)))
`(let ((,body-var ,@body))
(:select.button
,@attrs
:id ,id
Expand Down Expand Up @@ -462,7 +456,7 @@ LISTING is the string to enrich, autogenerated from FORM on demand."
(deftag :ncode (body attrs &rest keys &key
(package :nyxt)
(inline-p nil inline-provided-p)
file (editor-p file) (external-editor-p file)
(copy-p t) file (editor-p file) (external-editor-p file)
&allow-other-keys)
"Generate the <pre>/<code> listing from the provided Lisp BODY.
Expand All @@ -473,8 +467,6 @@ syntax highlighting and actions. If not provided, is determined automatically
based on BODY length.
Most *-P arguments mandate whether to add the buttons for:
- Editing the BODY in the built-in REPL (REPL-P).
- Appending the BODY to the auto-config.lisp (CONFIG-P).
- Copying the source to clipboard (COPY-P).
- Editing the FILE it comes from (if present), in
- Nyxt built-in `nyxt/mode/editor:editor-mode' (EDITOR-P).
Expand All @@ -490,21 +482,23 @@ Most *-P arguments mandate whether to add the buttons for:
:class "code-select"
:default ""
:style (if ,inline-var "font-weight: bold" "font-weight: normal")
`((copy "Copy" "Copy the code to clipboard.")
(funcall (read-from-string "nyxt:ffi-buffer-copy")
(nyxt:current-buffer) ,,plaintext))
,@(when (and file editor-p)
`(`((editor
"Open in built-in editor"
"Open the file this code comes from in Nyxt built-in editor-mode.")
(funcall (read-from-string "nyxt/mode/editor:edit-file")
,,file-var))))
,@(when (and file external-editor-p)
`(`((external-editor
"Open in external editor"
"Open the file this code comes from in external editor.")
(funcall (read-from-string "nyxt/mode/file-manager:edit-file-with-external-editor")
(uiop:ensure-list ,,file-var))))))))
(list
,@(when copy-p
`(`((copy "Copy" "Copy the code to clipboard.")
(funcall (read-from-string "nyxt:ffi-buffer-copy")
(nyxt:current-buffer) ,,plaintext))))
,@(when (and file editor-p)
`(`((editor
"Open in built-in editor"
"Open the file this code comes from in Nyxt built-in editor-mode.")
(funcall (read-from-string "nyxt/mode/editor:edit-file")
,,file-var))))
,@(when (and file external-editor-p)
`(`((external-editor
"Open in external editor"
"Open the file this code comes from in external editor.")
(funcall (read-from-string "nyxt/mode/file-manager:edit-file-with-external-editor")
(uiop:ensure-list ,,file-var)))))))))
(declare (ignorable keys))
`(let* ((,body-var (list ,@body))
(,first (first ,body-var))
Expand Down

0 comments on commit 2814013

Please sign in to comment.