-
Notifications
You must be signed in to change notification settings - Fork 1
/
zephir-mode.el
182 lines (138 loc) · 5.72 KB
/
zephir-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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
;;; zephir-mode.el --- Major mode for editing Zephir code -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2020 Free Software Foundation, Inc
;; Author: Serghei Iakovlev <[email protected]>
;; Maintainer: Serghei Iakovlev <[email protected]>
;; Version: 0.7.0
;; URL: https://github.com/zephir-lang/zephir-mode
;; Keywords: languages
;; Package-Requires: ((cl-lib "0.5") (pkg-info "0.4") (emacs "25.1"))
;; Revision: $Format:%h (%cD %d)$
;; This file is NOT part of GNU Emacs.
;;;; License
;; This file 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 file 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 file. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; GNU Emacs major mode for editing Zephir code. Provides syntax
;; highlighting, indentation, movement, Imenu and navigation support.
;;
;;;; Support:
;;
;; Bug tracking is currently handled using the GitHub issue tracker at
;; `https://github.com/zephir-lang/zephir-mode/issues'. Feel free to ask
;; question or make suggestions in our issue tracker.
;;
;;;; History:
;;
;; History is tracked in the Git repository rather than in this file. See URL
;; `https://github.com/zephir-lang/zephir-mode/blob/master/NEWS'.
;;
;;;; Customize && Help:
;;
;; See “M-x apropos-command RET ^zephir- RET” for a list of all commands and
;; “M-x customize-group RET zephir RET” for a list of customizable variables.
;;; Code:
;;;; Requirements
(require 'zephir)
(require 'zephir-face)
(require 'zephir-indent)
;; Tell the byte compiler about autoloaded functions from packages
(declare-function pkg-info-version-info "pkg-info" (package))
(require 'pkg-info)
;;;; Customization
(defcustom zephir-mode-hook nil
"List of functions to call when entering Zephir Mode."
:tag "Hook"
:type 'hook
:group 'zephir)
;;;; Version information
(defun zephir-mode-version (&optional show-version)
"Display string describing the version of Zephir Mode.
If called interactively or if SHOW-VERSION is non-nil, show the
version in the echo area and the messages buffer.
The returned string includes both, the version from package.el
and the library version, if both a present and different.
If the version number could not be determined, signal an error,
if called interactively, or if SHOW-VERSION is non-nil, otherwise
just return nil."
(interactive (list t))
(let ((version (pkg-info-version-info 'zephir-mode)))
(when show-version
(message "Zephir Mode version: %s" version))
version))
;;;; Initialization
(defvar zephir-mode-syntax-table
(let ((table (make-syntax-table)))
;; Symbol constituents
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?$ "_" table)
;; Punctuaction constituents
(modify-syntax-entry ?+ "." table)
(modify-syntax-entry ?- "." table)
(modify-syntax-entry ?= "." table)
(modify-syntax-entry ?% "." table)
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?& "." table)
(modify-syntax-entry ?| "." table)
;; Characters used to delimit string constants
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?\' "\"" table)
;; Comment enders
(modify-syntax-entry ?\n "> b" table)
;; Set up block and line oriented comments
(modify-syntax-entry ?/ ". 124b" table)
(modify-syntax-entry ?* ". 23" table)
;; The parenthesis, braces and brackets
(modify-syntax-entry ?\( "()" table)
(modify-syntax-entry ?\) ")(" table)
(modify-syntax-entry ?\{ "(}" table)
(modify-syntax-entry ?\} "){" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
table)
"Syntax table in use in `zephir-mode' buffers.
This includes setting ' and \" as string delimiters, and setting up
the comment syntax tokens handle both line style \"//\" and block style
\"/*\" \"*/\" comments.")
;;;###autoload
(define-derived-mode zephir-mode prog-mode "Zephir" ()
"A major mode for editing Zephir code.
\\{zephir-mode-map}
Turning on Zephir Mode calls the value of `prog-mode-hook' and then of
`zephir-mode-hook', if they are non-nil."
:group 'zephir
;; Comments setup
(setq-local comment-use-syntax t)
(setq-local comment-auto-fill-only-comments t)
(setq-local comment-multi-line t)
(setq-local comment-start "// ")
(setq-local comment-start-skip "\\(/[*/]+\\)\\s-*")
(setq-local comment-end "")
;; Font locking
(setq-local font-lock-syntactic-face-function
#'zephir-font-lock-syntactic-face)
(setq-local font-lock-defaults
'((zephir-font-lock-keywords) ; keywords
nil ; keywords-only
nil)) ; case-fold
;; TODO(serghei): Paragraphs
;; Imenu
(setq-local imenu-generic-expression zephir-imenu-generic-expression)
;; Navigation
(setq-local beginning-of-defun-function #'zephir-beginning-of-defun)
(setq-local end-of-defun-function #'zephir-end-of-defun)
;; Indentation
(setq-local indent-line-function #'zephir-indent-line)
(setq-local indent-tabs-mode zephir-indent-tabs-mode))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.zep\\'" . zephir-mode))
(provide 'zephir-mode)
;;; zephir-mode.el ends here