blob: c0ab83a970e560b7cd70b8a271e7477a55752361 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
;;; sqf-mode.el --- Major mode for SQF scripts in Arma -*- lexical-binding: t; -*-
;; Author: hybrid <hybrid@hybridlabs.pro>
;; Version: 0.1.0
;; Keywords: languages, sqf, arma, arma3, arma2, syntax
;; URL: https://git.hybridlabs.pro/sqf-mode
;; Package-Requires: ((emacs "27.1") (lsp-mode "7.0"))
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Major mode for editing SQF scripts used in Arma 2/3 series.
;; Provides basic syntax highlighting and integrates with HEMTT LSP server
;;; Code:
(require 'prog-mode)
(defgroup sqf nil
"Major mode for SQF scripts."
:group 'languages)
;;;###autoload
(define-derived-mode sqf-mode prog-mode "SQF"
"Major mode for editing SQF files.
Provides basic font-lock keywords and relies on LSP (HEMTT) for
advanced features when available.
\\{sqf-mode-map}"
;; Comments setup
(setq-local comment-start "//")
(setq-local comment-end "")
(setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
;; Syntax table: double-quoted strings,
;; processing '/' and '*' symbols and '\n' for multi-line commentaries
(modify-syntax-entry ?/ ". 124b")
(modify-syntax-entry ?* ". 23")
(modify-syntax-entry ?\n "> b")
(modify-syntax-entry ?\" "\"")
;; check if backward slash is escape
(modify-syntax-entry ?\\ "\\")
;; Basic keywords for font-lock (instant highlighting)
(setq-local font-lock-defaults
`((,(regexp-opt '("if" "then" "else" "while" "for" "do" "switch"
"case" "default" "private" "public" "param"
"params" "nil" "true" "false" "exitWith"
"forEach" "select" "format" "hint" "call"
"spawn" "execVM" "and" "or" "not" "mod"
"isEqualTo" "in" "this" "player" "server"
"local" "global" "remoteExec" "remoteExecCall")
'words)
(0 font-lock-keyword-face))))
"Configure lsp-mode for SQF."
(require 'lsp-mode nil)
(lsp-deferred))
;; register hemtt-language-server
(with-eval-after-load 'lsp-mode
(with-eval-after-load 'lsp-mode
(defun my/hemtt-server-start-fn (port)
`("hemtt-language-server" ,(number-to-string port)))
(add-to-list 'lsp-language-id-configuration '(sqf-mode . "sqf"))
(lsp-register-client
(make-lsp-client
:language-id "sqf"
:environment-fn (lambda () '(("RUST_BACKTRACE" . "full")))
:new-connection (lsp-tcp-server-command 'my/hemtt-server-start-fn)
:major-modes '(sqf-mode)
:priority 1
:server-id 'hemtt-ls))))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.sqf\\'" . sqf-mode))
(provide 'sqf-mode)
;;; sqf-mode.el ends here
|