-
Notifications
You must be signed in to change notification settings - Fork 2
/
ten-mode.el
64 lines (51 loc) · 2.07 KB
/
ten-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
;;; ten-mode.el --- Minor mode for compiling TEN Lisp templates -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Mariano Montone
;; Author: Mariano Montone <[email protected]>
;; Keywords: lisp
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Minor mode for compiling TEN Lisp templates
;;
;; install like:
;; (add-hook 'web-mode-hook 'ten-mode)
;;; Code:
(require 'slime)
(defun ten-compile-template ()
"Compile the TEN template in `current-buffer'."
(interactive)
(slime-eval `(ten:compile-template (cl::pathname ,(buffer-file-name))))
(message "TEN template compiled."))
(defun ten-expand-template ()
"Expand the TEN template in `current-buffer'."
(interactive)
(let ((expanded (slime-eval
`(cl:with-output-to-string
(s)
(cl:pprint (ten:expand-template (cl::pathname ,(buffer-file-name))) s)))))
(slime-with-popup-buffer ("*TEN expansion*"
:package :ten-templates :connection t
:mode 'lisp-mode)
(slime-mode 1)
(slime-macroexpansion-minor-mode 1)
(setq font-lock-keywords-case-fold-search t)
(current-buffer)
(insert expanded))))
(define-minor-mode ten-mode
"Minor mode for compiling and expanding TEN templates."
:init-value nil
:lighter " TEN"
:keymap
`((,(kbd "C-c C-c") . ten-compile-template)
(,(kbd "C-c RET") . ten-expand-template))
:group 'ten)
(provide 'ten-mode)
;;; ten-mode.el ends here