;;; glotawk.el --- Major mode for Glotawk Lisp -*- lexical-binding: t; -*-
;; Copyright 2025 Jared Jennings
;; Author: Jared Jennings <jjennings@fastmail.fm>
;; Version: 0.6
;; Package-Requires: ((emacs "25.1"))
;; Keywords: lisp
;; URL: https://j.agrue.info/glotawk-a-lisp-implemented-in-awk.html
;; This file is not part of GNU Emacs.
;; SPDX-License-Identifier: BSD-2-Clause
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials provided
;; with the distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;; “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
;; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
;; OF THE POSSIBILITY OF SUCH DAMAGE.
;;; Commentary:
;; Lets you edit source files written in Glotawk, a Lisp implemented
;; in AWK.
;;
;; Manual Installation: M-x package-install-file, then indicate your
;; downloaded copy of this file.
(require 'cl-lib)
;;; Code:
(defgroup glotawk nil "Glotawk Lisp options"
:group 'lisp
:prefix "glotawk-"
:tag "Glotawk")
(defcustom glotawk-lisp-program "glotawk"
"The full pathname of the glotawk interpreter executable."
:type 'string
:group 'glotawk)
(defcustom glotawk-mode-hook nil
"Hook run when entering Glotawk mode."
:type 'hook
:group 'glotawk)
(put 'with-ors 'lisp-indent-function 1)
(put 'with-rs 'lisp-indent-function 1)
(put 'with-fs 'lisp-indent-function 1)
(put 'with-output-to 'lisp-indent-function 2)
(put 'with-input-from 'lisp-indent-function 2)
(put 'macro 'lisp-indent-function 'defun)
;; OK, I'm really lazy, and I used a lot of the names from Common Lisp
;; (which it in turn inherited from earlier LISPs) for the usual
;; functions/special forms. So I don't want to copy/paste most of
;; lisp-mode, I want to derive from it. But the tradeoff is that
;; lisp-mode hooks are run, which means if you have Sly or SLIME
;; enabled, they will attempt to go into action when you open a
;; glotawk source file. Nothing useful will come from that. But -
;; https://stackoverflow.com/q/36268882 - it probably isn't worth
;; trying to prevent it. It just would surprise users and be awfully
;; difficult to maintain, for very little benefit. The best thing to
;; do is derive from lisp-data-mode, and copypaste here the parts of
;; lisp-mode that pertain exactly to glotawk. (And relicense to GPL.)
;;;###autoload
(define-derived-mode glotawk-mode lisp-mode "Glotawk"
"Major mode for editing programs in Glotawk, a Lisp implemented in AWK."
(setq-local inferior-lisp-program glotawk-lisp-program)
)
;;;###autoload
(add-to-list 'auto-mode-alist (cons "\\.glotawk\\'" 'glotawk-mode))
;;; glotawk.el ends here