From 415b1181faa8b0cbc092305b9eaddb177da880dd Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 19 Oct 2023 12:20:57 -0700 Subject: [PATCH] add syntax highlighting for emacs Signed-off-by: Ava Hahn --- Readme.org | 9 ++++- Writing.org | 2 +- snippets/relish-mode.el | 79 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 snippets/relish-mode.el diff --git a/Readme.org b/Readme.org index 04781a0..04881b7 100644 --- a/Readme.org +++ b/Readme.org @@ -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 diff --git a/Writing.org b/Writing.org index fa58ad2..7c826b2 100644 --- a/Writing.org +++ b/Writing.org @@ -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 | | | | | | |----------------+---------------+----------------+---------+--------+-----------+-----------+-----------+--------+-------------| diff --git a/snippets/relish-mode.el b/snippets/relish-mode.el new file mode 100644 index 0000000..d61a574 --- /dev/null +++ b/snippets/relish-mode.el @@ -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