/nx-ace

nx-ace is an editor for Nyxt.

Primary LanguageCommon LispBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Ace for Nyxt

This extension enables use the use of the Ace editor within Nyxt.

Getting started (on Nyxt 3.*)

First, clone the repository:

# ~/.local/share/nyxt/extensions/ is the default Nyxt extensions directory.
# Change if you set it to a different value.
git clone https://github.com/atlas-engineer/nx-ace.git ~/.local/share/nyxt/extensions/nx-ace

And then set up nx-ace:ace-mode as the editor mode, first loading nx-ace in your config.lisp

(define-nyxt-user-system-and-load "nyxt-user/ace"
   :depends-on (:nx-ace) :components ("ace.lisp"))

and then configuring it in ace.lisp:

(define-configuration nyxt/mode/editor:editor-buffer
  ((default-modes (cons 'nx-ace:ace-mode %slot-value%))))

Installing Ace extensions

You can install extensions using the nx-ace:extensions slot in ace-mode. Embeddable extension files can be found, for example, at https://cdnjs.com/libraries/ace. nx-ace:extensions will be automatically loaded and available to Ace. How to enable those depends on the type of the extension.

For example, if you want your Emacs keybindings and Monokai theme, you put this list of links in your ace.lisp (that you probably created above):

(define-configuration nx-ace:ace-mode
  ((nx-ace:extensions
    '("https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/keybinding-emacs.min.js"
      "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/theme-monokai.min.js"))))

Keybingings and themes

While the procedure to enable an extension varies wildly, it is more or less predictable for themes and keybindings, so nx-ace enables the ones you configured it to.

Now, if you want to enable your Monokai theme and Emacs keybindings, you only need to put this piece of configuration to ace.lisp (given that you added both Emacs and Monokai to your nx-ace:extensions):

(define-configuration nx-ace:ace-mode
  ((nx-ace::theme "ace/theme/monokai")
   (nx-ace::keybindings "ace/keyboard/emacs")))

And the next time you start your Nx-Ace, you’ll be greeted with the cozy Monokai-themed Emacsy code editor!

Other extensions

Other extensions are… complicated. It all depends on how they should be used. Let’s take Modelist extension, for example. Ace has this example snippet that we can roughly translate to Parenscript and put in the nx-ace:epilogue of Ace, running the code to enable the extensions after Ace is done loading and the file is open:

(define-configuration nx-ace:ace-mode
  ((nx-ace:epilogue
    (require
     "ace/ext/modelist"
     (lambda ()
       (let ((modelist (ps:chain ace (require "ace/ext/modelist"))))
         (ps:chain editor session
                   (set-mode (ps:chain modelist
                                       (get-mode-for-path (ps:@ window location href)) mode)))))))))

Once you start Ace, it will deduce the mode based on the editor: URL you have opened the file with :)