-
Notifications
You must be signed in to change notification settings - Fork 0
/
glicol-mode.el
122 lines (94 loc) · 3.49 KB
/
glicol-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;;; glicol-mode.el --- Major mode for Glicol audio programming language -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2024 Jose Mazzarelli
;;
;; Author: Jose Mazzarelli <[email protected]>
;; Maintainer: Jose Mazzarelli <[email protected]>
;; Created: December 14, 2024
;; Modified: December 14, 2024
;;
;; Version: 0.1.1
;; Package-Requires: ((emacs "26.1"))
;; Keywords: languages, multimedia
;; URL: https://github.com/khtdr/glicol-mode
;;; Commentary:
;; Major mode for editing Glicol audio programming language files.
;; Provides syntax highlighting and basic editing features.
;;; Code:
(require 'subr-x)
(require 'glicol-docs)
(require 'glicol-docs-ui)
(require 'glicol-cli)
(when (featurep 'doom)
(require 'glicol-doom))
(when (featurep 'company)
(require 'company-glicol))
;;; Customization
(defgroup glicol nil
"Major mode for editing Glicol files."
:group 'languages)
;;; Syntax Table
(defconst glicol-mode-syntax-table
(let ((table (make-syntax-table)))
;; Comments start with //
(modify-syntax-entry ?/ ". 124" table)
(modify-syntax-entry ?* ". 23b" table)
(modify-syntax-entry ?\n ">" table)
;; Symbol constituents
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?~ "_" table)
table)
"Syntax table for `glicol-mode'.")
;;; Font Lock
(defconst glicol-font-lock-keywords
`(
;; Comments
(,"//.*$" . font-lock-comment-face)
;; Node references (starting with ~)
(,"~[[:alnum:]_]+" . font-lock-variable-name-face)
;; Oscillators and generators
(,(regexp-opt '("sin" "saw" "squ" "tri" "noiz" "imp") 'words)
. font-lock-function-name-face)
;; Signal processors
(,(regexp-opt '("mul" "add" "lpf" "hpf" "envperc" "delayms" "delayn"
"allpass" "apf" "apfgain" "apfmsgain" "onepole" "plate"
"balance" "pan" "comb") 'words)
. font-lock-builtin-face)
;; Sequencing and control
(,(regexp-opt '("seq" "speed" "choose" "arrange" "meta") 'words)
. font-lock-keyword-face)
;; Instruments and synths
(,(regexp-opt '("sp" "bd" "sn" "hh" "sawsynth" "squsynth" "trisynth") 'words)
. font-lock-type-face)
;; Mixing and routing
(,(regexp-opt '("mix" "mono_sum" "buf" "pha" "state") 'words)
. font-lock-preprocessor-face)
;; Numbers
(,"\\<-?[0-9]*\\.?[0-9]+\\>" . font-lock-constant-face)
;; Node connection operator
(">>" . font-lock-keyword-face))
"Syntax highlighting for Glicol mode.")
;;; Mode Definition
;;;###autoload
(define-derived-mode glicol-mode prog-mode "Glicol"
"Major mode for editing Glicol files."
:syntax-table glicol-mode-syntax-table
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local font-lock-defaults '(glicol-font-lock-keywords))
(when (featurep 'company)
(add-to-list 'company-backends 'company-glicol)))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.glicol\\'" . glicol-mode))
;;; Key Bindings
;; Documentation commands
(define-key glicol-mode-map (kbd "C-c C-d") #'glicol-describe-node)
(define-key glicol-mode-map (kbd "C-c C-n") #'glicol-describe-node-at-point)
;; CLI commands
(define-key glicol-mode-map (kbd "C-c C-c") #'glicol-start-cli)
(define-key glicol-mode-map (kbd "C-c C-k") #'glicol-stop-cli)
(define-key glicol-mode-map (kbd "C-c C-s") #'glicol-server-status)
(define-key glicol-mode-map (kbd "C-c C-t") #'glicol-restart-cli)
(define-key glicol-mode-map (kbd "C-c C-b") #'glicol-set-bpm)
(provide 'glicol-mode)
;;; glicol-mode.el ends here