Compare commits
3 Commits
main
...
bd9929d9c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd9929d9c5 | ||
|
|
37fcfd376c | ||
|
|
89c6faceb4 |
11
Readme.org
11
Readme.org
@@ -278,8 +278,15 @@ best option.
|
||||
*** sex-mode.el
|
||||
To harness the power of sex-mode, add the following lines to your
|
||||
~$HOME/.config/emacs/init.el~:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(use-package sex-mode
|
||||
:load-path "/path/to/sex"
|
||||
:mode ("\\.sex\\'"))
|
||||
:ensure nil
|
||||
:quelpa
|
||||
(sex-mode :fetcher git
|
||||
:url "https://git.kotobank.ch/alex-eg/sex.git"
|
||||
:files ("sex-mode.el")
|
||||
:upgrade t))
|
||||
#+end_src
|
||||
|
||||
~.sex~ files then open in ~sex-mode~.
|
||||
|
||||
106
sex-mode.el
106
sex-mode.el
@@ -1,8 +1,40 @@
|
||||
;;; sex-mode.el --- Major mode for Sex code -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2025-2026 alex-eg
|
||||
|
||||
;; Author: alex-eg <alexey.e.egorov@gmail.com>
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "28.1"))
|
||||
;; Keywords: languages
|
||||
;; URL: https://git.kotobank.ch/alex-eg/sex
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Major mode for Sex, a compiled language with S-expression syntax.
|
||||
;; The mode derives from `lisp-data-mode' and fontifies Sex
|
||||
;; declarations and keywords.
|
||||
;;
|
||||
;; `sex-mode' is one file in the Sex repository. Quelpa installs it
|
||||
;; from that git remote:
|
||||
;;
|
||||
;; (use-package sex-mode
|
||||
;; :ensure nil
|
||||
;; :quelpa
|
||||
;; (sex-mode :fetcher git
|
||||
;; :url "https://git.kotobank.ch/alex-eg/sex.git"
|
||||
;; :files ("sex-mode.el")
|
||||
;; :upgrade t))
|
||||
;;
|
||||
;; Visiting a .sex file turns the mode on.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'scheme)
|
||||
|
||||
(defgroup sex-mode nil
|
||||
"Major mode for Sex code."
|
||||
:prefix 'sex-
|
||||
:prefix "sex-"
|
||||
:group 'languages)
|
||||
|
||||
(define-abbrev-table 'sex-mode-abbrev-table ()
|
||||
@@ -11,8 +43,8 @@ It has `scheme-mode-abbrev-table' as its parent."
|
||||
:parents (list scheme-mode-abbrev-table))
|
||||
|
||||
(defvar sex-mode-syntax-table
|
||||
(let ((table (make-syntax-table lisp-data-mode-syntax-table)))
|
||||
table))
|
||||
(make-syntax-table lisp-data-mode-syntax-table)
|
||||
"Syntax table used in Sex mode.")
|
||||
|
||||
(defvar sex-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
@@ -21,52 +53,66 @@ It has `scheme-mode-abbrev-table' as its parent."
|
||||
"Keymap for Sex mode.
|
||||
All commands in `lisp-mode-shared-map' are inherited by this map.")
|
||||
|
||||
(defvar sex-mode-line-process "")
|
||||
(defvar sex-mode-line-process ""
|
||||
"Mode-line process string for Sex mode.")
|
||||
|
||||
(defconst sex-font-lock-keywords
|
||||
(eval-when-compile
|
||||
(list
|
||||
;; Declarations
|
||||
;; Declarations. `pub' and `extern' are optional prefixes, so
|
||||
;; `(pub fn main' highlights both keywords and the name.
|
||||
(list (concat "("
|
||||
(regexp-opt '("chicken-define"
|
||||
"chicken-define-syntax"
|
||||
"chicken-import"
|
||||
"chicken-load"
|
||||
"define"
|
||||
"\\(?:\\(pub\\|extern\\)[[:space:]]+\\)?"
|
||||
(regexp-opt '("define"
|
||||
"defmacro"
|
||||
"extern"
|
||||
"enum"
|
||||
"fn"
|
||||
"import"
|
||||
"include"
|
||||
"fn"
|
||||
"pub"
|
||||
"struct"
|
||||
"var"
|
||||
"union")
|
||||
'word)
|
||||
"\\>"
|
||||
"typedef"
|
||||
"union"
|
||||
"var")
|
||||
'words)
|
||||
"[[:space:]]*"
|
||||
"\\([[:word:]]*\\)")
|
||||
'(1 font-lock-keyword-face)
|
||||
'(2 font-lock-function-name-face))
|
||||
;; Keywords
|
||||
'(1 font-lock-keyword-face nil t)
|
||||
'(2 font-lock-keyword-face)
|
||||
'(3 font-lock-function-name-face nil t))
|
||||
;; Statement and expression heads, plus the macro-language forms
|
||||
;; that appear in `defmacro' bodies.
|
||||
(list (concat "("
|
||||
(regexp-opt '(
|
||||
"do"
|
||||
(regexp-opt '("break"
|
||||
"c-bit-or"
|
||||
"c-bit-or="
|
||||
"c-or"
|
||||
"case"
|
||||
"case/fallthrough"
|
||||
"cast"
|
||||
"closure"
|
||||
"continue"
|
||||
"default"
|
||||
"do"
|
||||
"if"
|
||||
"else"
|
||||
"for"
|
||||
"goto"
|
||||
"if"
|
||||
"lambda"
|
||||
"map-fields"
|
||||
"return"
|
||||
"sizeof"
|
||||
"static-assert"
|
||||
"switch"
|
||||
"var"
|
||||
"while")
|
||||
'word)
|
||||
"\\>")
|
||||
'(1 'font-lock-builtin-face)))))
|
||||
"type-match"
|
||||
"type-of"
|
||||
"while"
|
||||
":")
|
||||
'words))
|
||||
'(1 font-lock-builtin-face))))
|
||||
"Font-lock keywords for Sex mode.")
|
||||
|
||||
(defun sex-mode-set-variables ()
|
||||
"Set up buffer-local variables for Sex mode."
|
||||
(set-syntax-table sex-mode-syntax-table)
|
||||
(setq local-abbrev-table sex-mode-abbrev-table)
|
||||
(setq mode-line-process '("" sex-mode-line-process))
|
||||
@@ -101,6 +147,8 @@ Blank lines separate paragraphs. Semicolons start comments.
|
||||
(sex-mode-set-variables))
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.\\(sex\\|hsex\\)\\'" . sex-mode))
|
||||
(add-to-list 'auto-mode-alist '("\\.sex\\'" . sex-mode))
|
||||
|
||||
(provide 'sex-mode)
|
||||
|
||||
;;; sex-mode.el ends here
|
||||
|
||||
Reference in New Issue
Block a user