From bffdab03e6379b85679ccec01b4bcbac4c659dd2 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Tue, 16 Nov 2021 17:33:15 +0100
Subject: [PATCH] Add the porth syntax highlighting

---
 config.el              |  3 ++
 packages/porth-mode.el | 66 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 packages/porth-mode.el

diff --git a/config.el b/config.el
index ce996bb..95ab120 100644
--- a/config.el
+++ b/config.el
@@ -67,6 +67,9 @@
  '(org-level-4 ((t (:inherit outline-4 :height 1.0))))
  '(org-level-5 ((t (:inherit outline-5 :height 1.0)))))
 
+;; Custom packages
+(load! "packages/porth-mode.el")
+
 ;; Here are some additional functions/macros that could help you configure Doom:
 ;;
 ;; - `load!' for loading external *.el files relative to this one
diff --git a/packages/porth-mode.el b/packages/porth-mode.el
new file mode 100644
index 0000000..ab16b2b
--- /dev/null
+++ b/packages/porth-mode.el
@@ -0,0 +1,66 @@
+;;; porth-mode.el --- Major Mode for editing Porth source code -*- lexical-binding: t -*-
+
+;; Copyright (C) 2021 Alexey Kutepov <reximkut@gmail.com>
+
+;; Author: Alexey Kutepov <reximkut@gmail.com>
+;; URL: https://github.com/tsoding/porth
+
+;; Permission is hereby granted, free of charge, to any person
+;; obtaining a copy of this software and associated documentation
+;; files (the "Software"), to deal in the Software without
+;; restriction, including without limitation the rights to use, copy,
+;; modify, merge, publish, distribute, sublicense, and/or sell copies
+;; of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+;; SOFTWARE.
+
+;;; Commentary:
+;;
+;; Major Mode for editing Porth source code. It's Forth but written in Python.
+
+;; TODO: jump to the opposite side of the blocks with C-M-f and C-M-b
+;; I think tuareg-mode can do that with similar end-like block, we try
+;; to steal their approach
+;; TODO: color the names of definitions in const, memory, proc, etc differently
+
+(defconst porth-mode-syntax-table
+  (with-syntax-table (copy-syntax-table)
+    ;; C/C++ style comments
+	(modify-syntax-entry ?/ ". 124b")
+	(modify-syntax-entry ?* ". 23")
+	(modify-syntax-entry ?\n "> b")
+    ;; Chars are the same as strings
+    (modify-syntax-entry ?' "\"")
+    (syntax-table))
+  "Syntax table for `porth-mode'.")
+
+(eval-and-compile
+  (defconst porth-keywords
+    '("if" "else" "while" "do" "include" "memory" "proc" "const" "end" "offset" "reset" "assert" "in")))
+
+(defconst porth-highlights
+  `((,(regexp-opt porth-keywords 'symbols) . font-lock-keyword-face)))
+
+;;;###autoload
+(define-derived-mode porth-mode prog-mode "porth"
+  "Major Mode for editing Porth source code."
+  (setq font-lock-defaults '(porth-highlights))
+  (set-syntax-table porth-mode-syntax-table))
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.porth\\'" . porth-mode))
+
+(provide 'porth-mode)
+
+;;; porth-mode.el ends here
-- 
GitLab