blob: c7bcc319f285927d24e7cda8e95ee175025f6418 (
plain)
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
|
;;; barb-mode.el --- major mode for barb files -*- lexical-binding: t; -*-
(eval-when-compile
(require 'rx))
(defconst barb--font-lock-defaults
(let ((keywords '("GET" "POST" "PUT" "PATCH" "DELETE" "HEAD")))
`(((,(rx-to-string `(: (or ,@keywords))) 0 font-lock-keyword-face)
("^#\\([[:word:]]+\\):" 1 font-lock-function-name-face)))))
(defvar barb-mode-syntax-table
(let ((st (make-syntax-table)))
st))
(defun barb-indent-line ()
"Indent the current line - I do nothing."
(save-excursion
(back-to-indentation)
(let ((start-point (point)))
(move-beginning-of-line nil)
(let* ((line-start (point))
(indent (floor (/ (- start-point line-start) tab-width))))
(indent-to (* (1+ indent) tab-width)))))
(back-to-indentation))
(defvar barb-mode-abbrev-table nil
"Abbreviation table used by `barb-mode' buffers.")
(define-abbrev-table 'barb-mode-abbrev-table
'())
(defun barb-run-file ()
"Run the current file with `barb'."
(interactive)
(save-excursion
(save-buffer)
(let ((active-buf (current-buffer)))
(with-output-to-temp-buffer "*barb*"
(let ((buffer (get-buffer "*barb*")))
(call-process "/home/etenil/.cargo/bin/barb" nil t nil (buffer-file-name active-buf)))))))
(defvar barb-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'barb-run-file)
map))
;;;###autoload
(define-derived-mode barb-mode prog-mode "barb"
"Major mode for barb files."
:abbrev-table barb-mode-abbrev-table
(setq font-lock-defaults barb--font-lock-defaults)
;(setq-local comment-start "##")
(setq-local indent-line-function #'barb-indent-line)
(setq-local indent-tabs-mode t))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.barb" . barb-mode))
(provide 'barb-mode)
|