Improve sex-mode installation via use-package and quelpa #73

Merged
alex-eg merged 3 commits from pkulev/sex:improve-sex-mode-installation into main 2026-10-30 12:22:55 +01:00
2 changed files with 91 additions and 32 deletions

View File

@@ -317,8 +317,15 @@ best option.
*** sex-mode.el *** sex-mode.el
To harness the power of sex-mode, add the following lines to your To harness the power of sex-mode, add the following lines to your
~$HOME/.config/emacs/init.el~: ~$HOME/.config/emacs/init.el~:
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package sex-mode (use-package sex-mode
:load-path "/path/to/sex" :ensure nil
:mode ("\\.sex\\'")) :quelpa
(sex-mode :fetcher git
:url "https://git.kotobank.ch/alex-eg/sex.git"
:files ("sex-mode.el")
:upgrade t))
#+end_src #+end_src
~.sex~ files then open in ~sex-mode~.

View File

@@ -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.
alex-eg marked this conversation as resolved Outdated

Sex, C with S-expression syntax compiled by sexc

Not true, Sex is a compiled language, and while it does transpile to C for now, and heavily inspired by C, it's not its permanent quality.

>Sex, C with S-expression syntax compiled by sexc Not true, Sex is a compiled language, and while it does transpile to C for now, and heavily inspired by C, it's not its permanent quality.
;; 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) (require 'scheme)
(defgroup sex-mode nil (defgroup sex-mode nil
"Major mode for Sex code." "Major mode for Sex code."
:prefix 'sex- :prefix "sex-"
:group 'languages) :group 'languages)
(define-abbrev-table 'sex-mode-abbrev-table () (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)) :parents (list scheme-mode-abbrev-table))
(defvar sex-mode-syntax-table (defvar sex-mode-syntax-table
(let ((table (make-syntax-table lisp-data-mode-syntax-table))) (make-syntax-table lisp-data-mode-syntax-table)
table)) "Syntax table used in Sex mode.")
(defvar sex-mode-map (defvar sex-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
@@ -21,58 +53,76 @@ It has `scheme-mode-abbrev-table' as its parent."
"Keymap for Sex mode. "Keymap for Sex mode.
All commands in `lisp-mode-shared-map' are inherited by this map.") 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 (defconst sex-font-lock-keywords
(eval-when-compile (eval-when-compile
(list (list
;; Declarations ;; Declarations. `pub' and `extern' are optional prefixes, so
;; `(pub fn main' highlights both keywords and the name.
(list (concat "(" (list (concat "("
(regexp-opt '("chicken-define" "\\(?:\\(pub\\|extern\\)[[:space:]]+\\)?"
"chicken-define-syntax" (regexp-opt '("define"
"chicken-import"
"chicken-load"
"define"
"defmacro" "defmacro"
"extern" "enum"
"fn"
"import" "import"
"include" "include"
"fn"
"ops" "ops"
"pub"
"record"
"realize" "realize"
"record"
"spec" "spec"
"struct" "struct"
"sum" "sum"
"var" "typedef"
"union") "union"
'word) "var")
"\\>" 'words)
"[[:space:]]*" "[[:space:]]*"
"\\([[:word:]]*\\)") "\\([[:word:]]*\\)")
'(1 font-lock-keyword-face) '(1 font-lock-keyword-face nil t)
'(2 font-lock-function-name-face)) '(2 font-lock-keyword-face)
;; Keywords '(3 font-lock-function-name-face nil t))
alex-eg marked this conversation as resolved Outdated

Why. They were in alphabetical order.

Why. They were in alphabetical order.

Whoops, killed wrong one. There are two "do"s in that list. Showd I leawe a twodo? 🤣

Whoops, killed wrong one. There are two "do"s in that list. Showd I leawe a twodo? 🤣

Do one, leave a onedo

Do one, leave a onedo
;; Statement and expression heads, plus the macro-language forms
;; that appear in `defmacro' bodies.
(list (concat "(" (list (concat "("
(regexp-opt '( (regexp-opt '("break"
"do" "c-bit-or"
"c-bit-or="
"c-or"
"case" "case"
"case/fallthrough"
"cast"
alex-eg marked this conversation as resolved Outdated

A number of kws are missing, e.g. spec, ops and realize.

A number of kws are missing, e.g. spec, ops and realize.

Still missing them... Aren't we?

Still missing them... Aren't we?
"closure"
"continue"
"default" "default"
"do" "do"
"if" "else"
"for" "for"
"get-method"
"goto" "goto"
"if"
"lambda"
"map-fields"
"match" "match"
"realizes?"
"return" "return"
"sizeof"
"static-assert"
"switch" "switch"
"var" "type-match"
"while") "type-of"
'word) "while"
"\\>") "$"
'(1 'font-lock-builtin-face))))) "."
":")
'words))
'(1 font-lock-builtin-face))))
"Font-lock keywords for Sex mode.")
(defun sex-mode-set-variables () (defun sex-mode-set-variables ()
"Set up buffer-local variables for Sex mode."
(set-syntax-table sex-mode-syntax-table) (set-syntax-table sex-mode-syntax-table)
(setq local-abbrev-table sex-mode-abbrev-table) (setq local-abbrev-table sex-mode-abbrev-table)
(setq mode-line-process '("" sex-mode-line-process)) (setq mode-line-process '("" sex-mode-line-process))
@@ -113,6 +163,8 @@ Blank lines separate paragraphs. Semicolons start comments.
(sex-mode-set-variables)) (sex-mode-set-variables))
;;;###autoload ;;;###autoload
(add-to-list 'auto-mode-alist '("\\.\\(sex\\|hsex\\)\\'" . sex-mode)) (add-to-list 'auto-mode-alist '("\\.sex\\'" . sex-mode))
(provide 'sex-mode) (provide 'sex-mode)
;;; sex-mode.el ends here