How to connect Emacs with Nyxt

Requirements in Emacs

Install sly. Using use-package:

(use-package sly
  :commands (sly sly-connect))

Or with package install:

(package-install 'sly)

Requirements in the system

Install nyxt...

sudo pacman -S nyxt

Close all nyxt instances.

pkill nyxt

Install SBCL

sudo pacman -S sbcl

Install [quicklisp] and check the signature validity against the public key in GnuPG servers.

curl -O https://beta.quicklisp.org/quicklisp.lisp
curl -O https://beta.quicklisp.org/quicklisp.lisp.asc
gpg2 --receive-keys 307965AB028B5FF7
gpg2 --verify quicklisp.lisp.asc quicklisp.lisp

Load the lisp file with sbcl:

sbcl --load quicklisp.lisp

Inside the sbcl terminal run to start the installation procedure (copy paste the following code):

(quicklisp-quickstart:install)

It will create the directory with all the package. The `ql:quickload ` function will download, install, and load the desired package.

quicklisp

Configure Nyxt

Write this at the end of ~/.config/nyxt/init.lisp

(load "~/quicklisp/setup.lisp")
(ql:quickload :slynk)
(define-command-global start-slynk (&optional (slynk-port *swank-port*))
  "Start a Slynk server that can be connected to, for instance, in
Emacs via SLY.
Warning: This allows Nyxt to be controlled remotely, that is, to execute
arbitrary code with the privileges of the user running Nyxt.  Make sure
you understand the security risks associated with this before running
this command."
  (slynk:create-server :port slynk-port :dont-close t :interface "0.0.0.0")
  (echo "Slynk server started at port ~a" slynk-port))

Consider changing `:interface 0.0.0.0 ` to `:interface 127.0.0.1 ` to avoid opening ports on all interfaces.

Connect Emacs!

Run nyxt.

nyxt

Press `M-x start-slynk ` to start the server.

Run `M-x sly-connect `, provide the host and port at the Emacs side (or run the following with C-c C-c):

(sly-connect "0.0.0.0" "4006")

Controlling Nyxt

Functions can be redefined with `defun `.

Nyxt commands are under the package `nyxt:: `. For instance, the following command will open the manual.

(nyxt::manual)

Usually, nyxt::* is not required. The following command will open a new URL in the current buffer:

(buffer-load "about:blank")

Getting help

(describe #'buffer-load)

Nuevas funciones con HTML

(define-command my-html-data ()
  "Just open an example buffer"
    (with-current-html-buffer (buffer "*My help*" 'nyxt/help-mode:help-mode)
      (spinneret:with-html-string
        (:style (style buffer))
        (:style (cl-css:css '(("#documentation .button"
                               :min-width "100px"))))
        (:h1 "Welcome to Nyxt :-)")
        (:p (:a :href "https://nyxt.atlas.engineer" "https://nyxt.atlas.engineer"))
        (:p (:a :class "button" :href (lisp-url `(help)) "Help"))
        (:p "This is a common example text."))))

This function is accessible via de URL lisp://(my-html-data)

Setting a slot

A slot works as class variables shared among instances (classes and instances are OOP simile). It can be setted with `#'define-configuration ` functions. As the name suggests, they are used as configurations variables because all instances are affected as soon as their values are modified.

The following example set a slot `prompter::filter-postprocessor ` with a lambda function as value (the function is the value). The slot is defined in the `user-new-url-or-search-source ` class (the name is not case sensitive).

(define-configuration USER-NEW-URL-OR-SEARCH-SOURCE
  ((prompter::filter-postprocessor
    (lambda (nyxt::suggestions nyxt::source nyxt::input)
      (declare (ignore nyxt::suggestions nyxt::source))
      (nyxt::input->queries nyxt::input :check-dns-p t :engine-completion-p nil)))))

Classes

Classes are the same as OOP, but instances can change its behaviour by changing the method and slot definitions.

That is the reason why slots are used as configuration too.

The following create an instance of a class `user-new-url-or-search-source `.

(make-instance 'user-new-url-or-search-source :actions an-action-list-here)