changeset 587: |
7efdeaebaf22 |
parent: |
1700f388192a
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Mon, 12 Aug 2024 16:18:47 -0400 |
permissions: |
-rw-r--r-- |
description: |
tweaks |
1 ;;; sxp.el --- S-Expression Mode -*- lexical-binding:t -*- 3 ;; Copyright (C) 2023 ellis 5 ;; Author: ellis <ellis@rwest.io> 8 ;; This program is free software; you can redistribute it and/or modify 9 ;; it under the terms of the GNU General Public License as published by 10 ;; the Free Software Foundation, either version 3 of the License, or 11 ;; (at your option) any later version. 13 ;; This program is distributed in the hope that it will be useful, 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ;; GNU General Public License for more details. 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 23 ;; Emacs Support for S-Expression files (.sxp). 25 ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-Expressions.html 28 (define-derived-mode sxp-mode lisp-data-mode "S-Expr" 29 "Major mode for editing '.sxp' files.") 31 (add-to-list 'auto-mode-alist '("\\.sxp" . sxp-mode)) 36 (cl-defgeneric wrap (sxp form)) 37 (cl-defgeneric unwrap (sxp)) 38 (cl-defgeneric from-sxp (sxp form) 39 "Update SXP using values from FORM.") 40 (cl-defgeneric to-sxp (sxp) 41 "Return SXP as a list.") 42 (cl-defgeneric read-sxp (sxp &optional stream) 43 "Read S-Expressions directly from STREAM (default = 44 `standard-input') and update SXP.") 45 (cl-defgeneric write-sxp (sxp &optional stream comment) 46 "Write S-Expressions directly to STREAM (default = 47 `standard-output') with optional COMMENT.") 50 ((form :initarg :form :accessor form))) 52 (cl-defmethod wrap ((sxp sxp) form) 53 (oset sxp :form form)) 54 (cl-defmethod unwrap ((sxp sxp)) 55 (slot-value sxp 'form)) 57 (cl-defmethod read-sxp ((sxp sxp) &optional stream) 58 (initialize-instance sxp (list :form (read stream))) 60 (cl-defmethod write-sxp ((sxp sxp) &optional stream) 61 (print (to-sxp sxp) stream)) 63 ;; (defvar sxp-load-tests nil) 64 ;; (when sxp-load-tests 66 ;; (defmacro deftest (name &rest body) 67 ;; "shorthand for `ert-deftest'." 68 ;; (declare (indent 1)) 69 ;; `(ert-deftest ,name () :tags '(sxp) ,@body)) 71 ;; (should (read-sxp (sxp) "(hey stranger)"))) 72 ;; (deftest 'sxp:write 73 ;; (should (write-sxp (sxp :form nil)))) 75 ;; (should (from-sxp (sxp) '(test 1 2 3)))) 77 ;; (should (to-sxp (sxp :form '("test" 'ing)))))