GitHub

@@ -811,98 +811,6 @@ handle. Useful to parallelize computations.")

811811

(:li (:code "--profile nosave")

812812

" to not pollute your history and cache with the script-accessed pages.")))

813813814-

(:nsection :title "Built-in REPL"

815-

(:p "Nyxt has a built-in REPL, available with "

816-

(:nxref :command 'nyxt/mode/repl:repl) " command."

817-

"The REPL can be used to try out some code snippets for automation or quickly

818-

make some Lisp calculations. All the packages Nyxt depends on are available in

819-

REPL with convenient nicknames, and all the code is evaluated in "

820-

(:nxref :package :nyxt-user) " package.")

821-

(:p "Once the REPL is open, there's only one input cell visible. This cell, always

822-

present at the bottom of the screen, adds new cells to the multi-pane interface

823-

of Nyxt REPL. You can type in " (:code "(print \"Hello, Nyxt!\")")

824-

" and press C-return to evaluate the cell. A new cell will appear at the top of the buffer, with

825-

input area containing familiar code, with some " (:code "v332 = \"Hello, Nyxt!\"")

826-

" variable assignment, and with a verbatim text outputted by your code:")

827-

(:pre (:code "Hello, Nyxt!"))

828-

(:p "This cell-based code evaluation is the basis of the Nyxt REPL. For more features, see "

829-

(:nxref :package :nyxt/mode/repl "REPL mode documentation") ".")

830-

(:nsection :title "Extending the REPL"

831-

(:p "Nyxt REPL is made to be extensible and allow to make custom cell types with

832-

their own display and functionality. The two cell types provided by default are:")

833-

(:ul

834-

(:li (:nxref :class-name 'nyxt/mode/repl:lisp-cell))

835-

(:li "and " (:nxref :class-name 'nyxt/mode/repl:shell-cell)))

836-

(:p "Both of these serve as examples of cell extension, but it may be more

837-

illuminating to create one of a different type from the default ones. A

838-

commentary cell, for example—the type of cell one can use as an annotation to

839-

other cells.")

840-

(:p "First, define a new " (:nxref :class-name 'nyxt/mode/repl:cell) " type:")

841-

(:ncode

842-

'(define-class comment-cell (nyxt/mode/repl:cell)

843-

((name "Commentary"))

844-

(:export-class-name-p t)

845-

(:export-accessor-names-p t)))

846-

(:p "There are methods of " (:nxref :class-name 'nyxt/mode/repl:cell)

847-

" that can be redefined for a better display:")

848-

(:ul

849-

(:li (:nxref :function 'nyxt/mode/repl:evaluate)

850-

" as a function to get results from the cell.")

851-

(:li (:nxref :function 'nyxt/mode/repl:suggest)

852-

" for choosing the most intuitive content to paste into the cell.")

853-

(:li (:nxref :function 'nyxt/mode/repl:render-input)

854-

" as the one rendering the input area for the cell.")

855-

(:li (:nxref :function 'nyxt/mode/repl:render-actions)

856-

", allowing to render a custom set of actions.")

857-

(:li "And " (:nxref :function 'nyxt/mode/repl:render-results)

858-

" to show cell results (the immediate values "

859-

(:nxref :function 'nyxt/mode/repl:evaluate "evaluation")

860-

" returns) and output (the text printed out while "

861-

(:nxref :function 'nyxt/mode/repl:evaluate "evaluating")

862-

" the cell).")

863-

(:li "And, in case none of those fits well, "

864-

(:nxref :function 'nyxt/mode/repl:render-cell)

865-

" to override all the rendering code."))

866-

(:p "The easiest thing is " (:nxref :function 'nyxt/mode/repl:render-input)

867-

": it's already defined as an input field updating the cell "

868-

(:nxref :function 'nyxt/mode/repl:input)

869-

" at every keypress. The only change to it that is needed for the commentary

870-

cell is to render as a <pre> tag when marked " (:nxref :function 'nyxt/mode/repl:ready-p) ":")

871-

(:ncode

872-

'(defmethod nyxt/mode/repl:render-input ((cell comment-cell))

873-

"Render as a pre tag when ready, render as default input otherwise."

874-

(if (nyxt/mode/repl:ready-p cell)

875-

(spinneret:with-html-string

876-

(:pre (input cell)))

877-

(call-next-method))))

878-

(:p (:nxref :function 'nyxt/mode/repl:render-results)

879-

" is another method useless for comment cell. It can safely return the empty

880-

string:")

881-

(:ncode

882-

'(defmethod nyxt/mode/repl:render-results ((cell comment-cell))

883-

(declare (ignore cell))

884-

""))

885-

(:p (:nxref :function 'nyxt/mode/repl:render-actions)

886-

" should stay as it is, because it produces an aesthetic set of buttons near the

887-

input. No need to tweak it in this case.")

888-

(:p "Last but not least, " (:nxref :function 'nyxt/mode/repl:evaluate)

889-

". This method should produce the " (:nxref :function 'nyxt/mode/repl:results)

890-

" and " (:nxref :function 'nyxt/mode/repl:output)

891-

" of the cell. The REPL infrastructure sets "

892-

(:nxref :function 'nyxt/mode/repl:ready-p)

893-

" to T when the evaluation ends, which enables the <pre> rendering. Given that

894-

comment cells produce no result "

895-

(:nxref :function 'nyxt/mode/repl:evaluate) " can stay empty:")

896-

(:ncode

897-

'(defmethod nyxt/mode/repl:evaluate ((cell comment-cell))

898-

(declare (ignore cell))))

899-

(:p "After all of these methods are defined in the configuration file and Nyxt restarted,

900-

invoking "

901-

(:nxref :command 'nyxt/mode/repl:repl) " and pressing the " (:code "Add a cell")

902-

" button will allow to create a new comment cell.")

903-

(:p "Note that the display of the comment cell is not exactly concise. But making it

904-

better is left as an exercise to the reader.")))

905-906814

(:nsection :title "Advanced configuration"

907815

(:p "While " (:nxref :macro 'define-configuration) " is convenient, it is mostly

908816

restricted to class slot configuration. If you want to do anything else on

@@ -940,13 +848,7 @@ core to finalize the instance."))

940848

(:nsection :title "Troubleshooting"

941849942850

(:nsection :title "Debugging and reporting errors"

943-

(:p "If you experience hangs or errors you can reproduce, you can use the "

944-

(:nxref :command 'nyxt:toggle-debug-on-error)

945-

" command to enable Nyxt-native debugger and see the reasons of these. Based on

946-

this information, you can report a bug using " (:nxref :command 'nyxt:report-bug) ".")

947-

(:p "Note that often errors, hangs, and crashes happen on the side of renderer and

948-

thus are not visible to the Nyxt-native debugger and fixable on the side of

949-

Nyxt. See below."))

851+

(:p "Report bugs using " (:nxref :command 'nyxt:report-bug) "."))

950852951853

(:nsection :title "Bwrap error on initialization (Ubuntu)"

952854

(:p "If Nyxt crashes on start due to " (:code "bwrap")

Read the original on github.com ↗