aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorHugues Evrard <hevrard@users.noreply.github.com>2019-06-04 14:46:38 +0100
committerGitHub <noreply@github.com>2019-06-04 14:46:38 +0100
commit0d6a1f686dcccc85544b3278dedbf784cb08a4d2 (patch)
tree2f156fa95116e495eee723c8a07549c1662b9e8d /tools
parent446efbd8a593e2dd565cb5b975ac4287c28e6117 (diff)
downloadamber-0d6a1f686dcccc85544b3278dedbf784cb08a4d2.tar.gz
Add basic Emacs mode for Amber script (#537)
This mode covers only syntax highligting, not indentation. It treats embedded shader code the same way as regular code, because it seems surprisingly complex to tell Emacs to ignore highlighting for part of the buffer.
Diffstat (limited to 'tools')
-rw-r--r--tools/amber-mode.el93
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/amber-mode.el b/tools/amber-mode.el
new file mode 100644
index 0000000..90173ec
--- /dev/null
+++ b/tools/amber-mode.el
@@ -0,0 +1,93 @@
+;; Copyright 2019 The Amber Authors.
+;;
+;; Licensed under the Apache License, Version 2.0 (the "License");
+;; you may not use this file except in compliance with the License.
+;; You may obtain a copy of the License at
+;;
+;; https://www.apache.org/licenses/LICENSE-2.0
+;;
+;; Unless required by applicable law or agreed to in writing, software
+;; distributed under the License is distributed on an "AS IS" BASIS,
+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;; See the License for the specific language governing permissions and
+;; limitations under the License.
+
+;; Emacs mode for Amber script
+;; https://github.com/google/amber
+
+(defvar amber-mode-hook nil)
+
+(defvar amber-mode-map
+ (let ((map (make-keymap)))
+ ;; Add key bindings here
+ (define-key map "\C-j" 'newline-and-indent)
+ map)
+ "Keymap for Amber major mode")
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.amber\\'" . amber-mode))
+
+;; Evaluate the following to create optimized regex used for highlighting
+
+;; (regexp-opt '(
+;; "END" "SHADER" "BUFFER" "DATA_TYPE" "SIZE" "DATA" "FILL"
+;; "SERIES_FROM" "PASSTHROUGH" "PIPELINE" "ATTACH" "ENTRY_POINT"
+;; "DESCRIPTOR_SET" "INC_BY" "BINDING" "IDX" "TO" "RUN" "DRAW_RECT"
+;; "POS" "DRAW_ARRAY" "IN" "AS" "START_IDX" "COUNT" "CLEAR_COLOR"
+;; "CLEAR" "EXPECT" "TYPE" "FRAMEBUFFER" "SHADER_OPTIMIZATION"
+;; "FORMAT" "FRAMEBUFFER_SIZE" "BIND" "SAMPLER" "VERTEX_DATA"
+;; "INDEX_DATA" "INDEXED" "IMAGE_ATTACHMENT"
+;; "DEPTH_STENCIL_ATTACHMENT" "LOCATION" "DEVICE_FEATURE"
+;; "DERIVE_PIPELINE" "FROM" "COPY" "TOLERANCE" "REPEAT"
+;; ) t)
+
+;; (regexp-opt '(
+;; "vertex" "fragment" "compute" "geometry" "tessellation_evaluation"
+;; "tessellation_control" "multi" "framebuffer" "graphics" "uniform"
+;; "storage" "push_constant" "color" "depth_stencil" "EQ" "NE" "LT"
+;; "LE" "GT" "GE" "EQ_RGB" "EQ_RGBA" "EQ_BUFFER" "GLSL" "HLSL"
+;; "SPIRV-ASM" "SPIRV-HEX" "OPENCL-C"
+;; ) t)
+
+;; (regexp-opt '(
+;; "point_list" "line_list" "line_list_with_adjacency" "line_strip"
+;; "line_strip_with_adjacency" "triangle_list"
+;; "triangle_list_with_adjacency" "triangle_strip"
+;; "triangle_strip_with_adjacency" "triangle_fan" "patch_list"
+;; "float" "double"
+;; ) t)
+
+(defconst amber-font-lock-keywords-1
+ (list
+ '("\\<\\(A\\(?:S\\|TTACH\\)\\|B\\(?:IND\\(?:ING\\)?\\|UFFER\\)\\|C\\(?:LEAR\\(?:_COLOR\\)?\\|O\\(?:PY\\|UNT\\)\\)\\|D\\(?:ATA\\(?:_TYPE\\)?\\|E\\(?:PTH_STENCIL_ATTACHMENT\\|RIVE_PIPELINE\\|SCRIPTOR_SET\\|VICE_FEATURE\\)\\|RAW_\\(?:ARRAY\\|RECT\\)\\)\\|E\\(?:N\\(?:D\\|TRY_POINT\\)\\|XPECT\\)\\|F\\(?:ILL\\|ORMAT\\|R\\(?:AMEBUFFER\\(?:_SIZE\\)?\\|OM\\)\\)\\|I\\(?:DX\\|MAGE_ATTACHMENT\\|N\\(?:C_BY\\|DEX\\(?:ED\\|_DATA\\)\\)?\\)\\|LOCATION\\|P\\(?:ASSTHROUGH\\|IPELINE\\|OS\\)\\|R\\(?:EPEAT\\|UN\\)\\|S\\(?:AMPLER\\|ERIES_FROM\\|HADER\\(?:_OPTIMIZATION\\)?\\|IZE\\|TART_IDX\\)\\|T\\(?:O\\(?:LERANCE\\)?\\|YPE\\)\\|VERTEX_DATA\\)\\>" . font-lock-builtin-face)
+ '("\\<\\(EQ\\(?:_\\(?:BUFFER\\|RGBA?\\)\\)?\\|G\\(?:LSL\\|[ET]\\)\\|HLSL\\|L[ET]\\|NE\\|OPENCL-C\\|SPIRV-\\(?:ASM\\|HEX\\)\\|co\\(?:lor\\|mpute\\)\\|depth_stencil\\|fra\\(?:gment\\|mebuffer\\)\\|g\\(?:eometry\\|raphics\\)\\|multi\\|push_constant\\|storage\\|tessellation_\\(?:control\\|evaluation\\)\\|uniform\\|vertex\\)\\>" . font-lock-constant-face)
+ '("\\<\\(double\\|float\\|line_\\(?:list\\(?:_with_adjacency\\)?\\|strip\\(?:_with_adjacency\\)?\\)\\|p\\(?:\\(?:atch\\|oint\\)_list\\)\\|triangle_\\(?:fan\\|list\\(?:_with_adjacency\\)?\\|strip\\(?:_with_adjacency\\)?\\)\\)\\>" . font-lock-type-face)
+ ;; This one is hand-written, not generated by regexp-opt
+ '("\\<\\(u?int\\|vec\\|mat\\)[[:digit:]]*\\>" . font-lock-type-face)
+ )
+ "Minimal highlighting expressions for Amber mode")
+
+(defvar amber-font-lock-keywords amber-font-lock-keywords-1
+ "Default highlighting expressions for Amber mode")
+
+(defvar amber-mode-syntax-table
+ (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?_ "w" st)
+ (modify-syntax-entry ?# "<" st)
+ (modify-syntax-entry ?\n ">" st)
+ (modify-syntax-entry ?\" "\"" st)
+ st)
+ "Syntax table for amber-mode")
+
+(defun amber-mode ()
+ "Major mode for editing Amber Script files"
+ (interactive)
+ (kill-all-local-variables)
+ (set-syntax-table amber-mode-syntax-table)
+ (use-local-map amber-mode-map)
+ (set (make-local-variable 'font-lock-defaults) '(amber-font-lock-keywords))
+ (setq major-mode 'amber-mode)
+ (setq mode-name "amber")
+ (run-hooks 'amber-mode-hook))
+
+(provide 'amber-mode)