add syntax highlighting for emacs

Signed-off-by: Ava Hahn <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2023-10-19 12:20:57 -07:00
parent 5dcf601384
commit 415b1181fa
3 changed files with 88 additions and 2 deletions

View file

@ -80,6 +80,13 @@ Variables and functions defined in an external script loaded by your interpreter
(call "my-extra-library-functions.rls")
#+END_SRC
* Syntax Highlighting
Syntax Highlighting is implemented for Emacs under [[file:snippets/relish-mode.el][the Relish Mode module (snippets/relish-mode.el)]].
For installation, consider adding the following to your ~\~/.emacs~:
#+BEGIN_SRC el
(load-file "/PATH/TO/relish/snippets/relish-mode.el")
#+END_SRC
* Compilation
Compiling Relish is as simple as kicking off a build with Cargo.
#+BEGIN_EXAMPLE sh
@ -162,6 +169,7 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
- Make an icon if you feel like it
- Post release to relevant channels
** TODO v1.1 tasks
- emacs lsp implementation
- finish stretch goals in the [[file:snippets/interactive-devel.rls][interactive development library]]
- History length configurable (env var?)
- Lex function
@ -174,7 +182,6 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
- a snippet with a bunch of color constants
- Search delim configurable
** TODO v1.2 release tasks
- Emacs syntax highlighting and/or LSP implementation
- Bindings for the simplest possible UI library?
- Scheme compatibility layer?
- Get on that bug tracker

View file

@ -297,7 +297,7 @@ The following table is up to date as of Relish 0.3.0. For latest information try
|----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------|
| exit | set? | fg | dq | div | concat | or | get-paths | | |
|----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------|
| | | | pop | gte? | string | | cond | | |
| | | bg | pop | gte? | string | | cond | | |
|----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------|
| | | | list? | int | | | | | |
|----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------|

79
snippets/relish-mode.el Normal file
View file

@ -0,0 +1,79 @@
;;; relish-mode.el --- sample major mode for editing Relish. -*- coding: utf-8; lexical-binding: t; -*-
;; Copyright © 2017, by Ava Hahn
;; Author: Ava Hahn (ava@sunnypup.io)
;; Version: 1
;; Keywords: languages
;; This file is not part of GNU Emacs.
;;; License:
;; You can redistribute this program and/or modify it under the terms of the GNU General Public License version 3.
;;; Code:
(setq relish-keywords
(let* (
(r-control-flow '("if" "let" "circuit" "while" "assert" "exit"))
(r-declaration '("lambda" "q" "quote" "def" "get-doc" "set-doc" "set?"))
(r-shell '("pipe" "load-to-string" "l" "load" "load-with" "cd" "fg" "bg"))
(r-list '("car" "len" "cons" "cdr" "reverse" "dq" "pop" "list?"))
(r-math '("float" "sub" "mul" "inc" "dec" "div" "gte?" "int" "mod" "exp" "lt?" "gt?" "add" "lte?"))
(r-strings '("strlen" "substr?" "echo" "split" "input" "concat" "string"))
(r-bool '("toggle" "bool" "and" "eq?" "not" "or"))
(r-file '("read-file" "append-file" "write-file" "exists?"))
(r-misc '("call" "help" "env" "eval"))
(r-userlib '("reduce" "prepend" "add-path" "set" "map" "get-paths" "cond"))
(r-control-flow-regexp (regexp-opt r-control-flow 'words))
(r-declaration-regexp (regexp-opt r-declaration 'words))
(r-shell-regexp (regexp-opt r-shell 'words))
(r-list-regexp (regexp-opt r-list 'words))
(r-math-regexp (regexp-opt r-math 'words))
(r-strings-regexp (regexp-opt r-strings 'words))
(r-bool-regexp (regexp-opt r-bool 'words))
(r-file-regexp (regexp-opt r-file 'words))
(r-misc-regexp (regexp-opt r-misc 'words))
(r-userlib-regexp (regexp-opt r-userlib 'words)))
`(
(,r-control-flow-regexp . 'font-lock-type-face)
(,r-declaration-regexp . 'font-lock-type-face)
(,r-misc-regexp . 'font-lock-type-face)
(,r-list-regexp . 'font-lock-builtin-face)
(,r-math-regexp . 'font-lock-keyword-face)
(,r-strings-regexp . 'font-lock-keyword-face)
(,r-bool-regexp . 'font-lock-keyword-face)
(,r-shell-regexp . 'font-lock-constant-face)
(,r-file-regexp . 'font-lock-constant-face)
(,r-userlib-regexp . 'font-lock-function-name-face)
)))
(setq relish-mode-syntax-table
(let ((table (make-syntax-table)))
;; string delims
(modify-syntax-entry ?' "\"" table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?` "\"" table)
;; comment delims
(modify-syntax-entry ?\; "<" table)
(modify-syntax-entry ?\n ">" table)
table))
(define-derived-mode relish-mode
text-mode
"Major mode for editing Relish"
:syntax-table relish-mode-syntax-table
(setq font-lock-defaults '((relish-keywords))))
(add-to-list 'auto-mode-alist '("\\.rls\\'" . relish-mode))
(add-to-list 'auto-mode-alist '(".relishrc" . relish-mode))
(provide 'relish-mode)
;;; relish-mode.el ends here